aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/parser
Commit message (Collapse)AuthorAgeFilesLines
* core: vm: sqlvm: parser: check if a number literal is an integerTing-Wei Lan2019-03-262-976/+1045
| | | | | | ORDER BY and GROUP BY options have to decide whether an expression is a reference to the column specified in SELECT command by checking whether it consists of only one integer literal.
* core: vm: sqlvm: make a common interface for statementsTing-Wei Lan2019-03-264-1616/+2247
| | | | | | | So Parse now returns a []ast.StmtNode instead of a generic []ast.Node, which should be clearer on what the return value looks like. This also adds a field recording the verb use to identify the statement in order to provide better error messages.
* core: vm: sqlvm: errors: remove token fieldTing-Wei Lan2019-03-264-469/+440
| | | | | | | | Now both position and length are both recorded in the error struct, recording the token in the error struct no longer provides any benefit. It is easy to find the token when position and length are known, but requiring all error locations to fill the field is complicated because they have to access the source code to find the token.
* core: vm: sqlvm: add ESCAPE grammarwmin02019-03-263-653/+733
| | | | | Provide ESCAPE grammar for specifying escape character in like pattern matching.
* core: vm: sqlvm: errors: add length fieldTing-Wei Lan2019-03-264-440/+470
| | | | | 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.
* core: vm: sqlvm: limit the depth of AST to 1024Ting-Wei Lan2019-03-261-7/+41
| | | | | Since we traverse an AST by calling functions recursively, we have to protect the parser by limiting the depth of an AST.
* core: vm: sqlvm: parser: move generated code to internal packageTing-Wei Lan2019-03-265-1565/+1585
| | | | | | | | Code generated by pigeon includes many exported symbols which should not be used by any other code other than the parser itself. To prevent them from being misused, we used to hide them by editing the generated code with sed. This commit removes the unreliable sed trick by putting generated code to internal package.
* core: vm: sqlvm: parser: don't use @, #, $ in unquoted identifiersTing-Wei Lan2019-03-262-35/+34
| | | | | | These symbols are allowed in Microsoft SQL or PostgreSQL, but the SQL standard doesn't mention them. It is still possible to use these symbols as identifiers by putting them in double quotes.
* core: vm: sqlvm: fill source code position in AST nodesTing-Wei Lan2019-03-263-1100/+1385
| | | | | | | | | | | | | | | Now all AST nodes should have position information recorded during parsing. These fields are intended to be used to report errors and make debugging easier. However, precise location of each token is currently unavailable. It can be done in the future if it becomes necessary. To make it easier to traverse an AST, GetChildren is modified to skip nil nodes in the output. This means callers of GetChildren don't have to check for nil in returned slices. AST printer is modified to print the position and the corresponding source code token. A few special handling for interfaces are removed because reflection works better for structs.
* core: vm: sqlvm: check if a number is a valid addressTing-Wei Lan2019-03-263-311/+307
| | | | | | | | | | | | This commit implements isAddress function to allow a number literal to be considered as an address literal. Since Solidity only allows '0x' to be written in lower case, we remove the handling of upper case '0X' to keep the behavior in sync with Solidity. In addition to isAddress implementation, this commit also removes 'String' methods from AST nodes to prevent them from implementing the builtin 'Stringer' interface. Therefore, our AST printer is now able to print struct fields of value nodes instead of only one string.
* core: vm: sqlvm: introduce interfaces for AST nodesTing-Wei Lan2019-03-264-1538/+1937
| | | | | | | | | In order to make our AST easier and safer to use, all declarations with empty interface type are now removed. This changes also makes it possible to traverse the AST without using reflection or understanding what each type means because all AST nodes have at least one common interface.
* core: vm: sqlvm: parser: toDecimal handle .0wmin02019-03-262-0/+4
| | | | | To cover the pitfall of decimal.fromString, we need to add leading 0 at '^\.[0-9]+' case.
* core: vm: sqlvm: process non-UTF-8 input and escape sequencesTing-Wei Lan2019-03-265-324/+529
| | | | | | | | | | | | | | | Our parser is able to process queries with invalid UTF-8, provided that it is compatible with ASCII. Since doing so requires encoding the input before passing to pigeon, Parse* functions generated by pigeon are unexported because they should not be used directly. Escape sequences in string literals and identifiers are now recognized. In addition to escape sequences supported by solidity, we support \U similar to the one supported by Go to allow users to specify non-BMP Unicode code point without using multiple \x escapes. AST printer is modified to quote non-printable characters in strings to prevent control characters from messing up the terminal.
* core: vm: sqlvm: parser: properly handle errorsTing-Wei Lan2019-03-264-1241/+1538
| | | | | | Instead of ignoring errors, errors returned from external functions are normalized and reported to users. Errors which should be impossible to occur are converted to panic calls.
* core: vm: sqlvm: move AST and parser to their own packagesTing-Wei Lan2019-03-264-0/+8496
In order to avoid putting too many different things in single package and allow other projects to reuse the syntax tree and the parser, these two components are moved to different packages and all nodes used in AST are now exported. A lot of comments are added in this commit to pass golint checks.