diff options
author | Ting-Wei Lan <tingwei.lan@cobinhood.com> | 2019-03-04 18:10:25 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:04 +0800 |
commit | 698e83b3cc39737a45244ac2d47595964f6e468c (patch) | |
tree | 6af5b16f7e3914987aeb914fc78e261433cf47cc /core/vm/sqlvm/parser/parser.go | |
parent | 126145a7eca2c054367abc65291ab1c90c51b998 (diff) | |
download | dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar.gz dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar.bz2 dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar.lz dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar.xz dexon-698e83b3cc39737a45244ac2d47595964f6e468c.tar.zst dexon-698e83b3cc39737a45244ac2d47595964f6e468c.zip |
core: vm: sqlvm: errors: add length field
When an error corresponds to a source code token, it should be able to
report the length of the token in addition to the position.
Diffstat (limited to 'core/vm/sqlvm/parser/parser.go')
-rw-r--r-- | core/vm/sqlvm/parser/parser.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/vm/sqlvm/parser/parser.go b/core/vm/sqlvm/parser/parser.go index 8ed94e7aa..685b1dd0d 100644 --- a/core/vm/sqlvm/parser/parser.go +++ b/core/vm/sqlvm/parser/parser.go @@ -122,6 +122,7 @@ func Parse(b []byte) ([]ast.Node, error) { return nil, errors.ErrorList{ errors.Error{ Position: 0, + Length: 0, Category: errors.ErrorCategoryLimit, Code: errors.ErrorCodeDepthLimitReached, Token: "", @@ -148,12 +149,18 @@ func Parse(b []byte) ([]ast.Node, error) { } sqlvmErrList[i].Token = string(internal.DecodeString([]byte(sqlvmErrList[i].Token))) - if offset, ok := encMap[sqlvmErrList[i].Position]; ok { - sqlvmErrList[i].Position = offset - } else { - panic(fmt.Sprintf("cannot fix error position byte offset %d", - sqlvmErrList[i].Position)) + begin := sqlvmErrList[i].Position + end := begin + sqlvmErrList[i].Length + fixedBegin, ok := encMap[begin] + if !ok { + panic(fmt.Sprintf("cannot fix error position byte offset %d", begin)) + } + fixedEnd, ok := encMap[end] + if !ok { + panic(fmt.Sprintf("cannot fix error position byte offset %d", end)) } + sqlvmErrList[i].Position = fixedBegin + sqlvmErrList[i].Length = fixedEnd - fixedBegin } return stmts, sqlvmErrList } |