usagi-coffee / tree-sitter-abl Goto Github PK
View Code? Open in Web Editor NEWOpenEdge ABL grammar for tree-sitter
License: MIT License
OpenEdge ABL grammar for tree-sitter
License: MIT License
Example:
FUNCTION GET_STUFF RETURNS Progress.Json.ObjectModel.JsonObject (cParam1 AS CHARACTER):
DEFINE VARIABLE jsonTableRow AS Progress.Json.ObjectModel.JsonObject NO-UNDO.
RETURN jsonTableRow.
END FUNCTION.
Result on one of the nodes:
Type: ERROR
Text: Progress.Json.ObjectModel.JsonObject (cParam1 AS
This snippet returns an error:
repeat while true:
end.
It should be easy as REPEAT has basically identical structure to DO statement.
Example:
find Vacation no-lock where Vacation.id = 123.
Result:
Parser isn't able to recognize no-lock before where clause. It returns ERROR type node.
First of all, thank you for fixing the previous issue (#2) so fast!
While experimenting a bit more, I found more precedence errors; the grammar currently parses the following code incorrectly:
x = NOT 2 + 2 = 5.
Giving the following syntax tree:
(source_code
(statement
(variable_assignment
(assignment
(identifier)
(expression
(binary_expression
(additive_expression
(expression
(unary_expression
(expression
(number_literal))))
(additive_operator)
(expression
(comparison
(expression
(number_literal))
(comparator)
(expression
(number_literal))))))))
(terminator))))
As if it were equivalent to x = ((NOT 2) + (2 = 5)).
instead of x = (NOT ((2 + 2) = 5)).
.
Note that the issue doesn't occur for x = NOT 5 = 2 + 2.
.
Examples:
ROUTINE-LEVEL ON ERROR UNDO, THROW.
BLOCK-LEVEL ON ERROR UNDO, THROW.
Result:
Parser error on , THROW
node
The following code fails to parse:
x = YES AND NO.
y = YES OR NO.
Tree-sitter generates the following AST:
(source_code
(statement
(variable_assignment
(assignment
(identifier)
(ERROR
(expression
(boolean_expression)))
(expression
(boolean_expression)))
(terminator)))
(statement
(variable_assignment
(assignment
(identifier)
(ERROR
(expression
(boolean_expression)))
(expression
(boolean_expression)))
(terminator))))
Using this page https://meimporta.eu/tree-sitter/json2ebnf.html we can get a navigable railroad diagram for tree-sitter grammars like this project.
See also tree-sitter/tree-sitter#2268 .
Cheers !
Trying to use the unary minus operator with parenthesized expressions, function calls, object accesses, or field accesses result in the error trees being generated. Example:
w = -(0).
x = -f().
y = -table.field.
z = -obj:method().
For the example above, the grammar generates the following tree:
(source_code
(variable_assignment
(assignment
(identifier)
(ERROR)
(parenthesized_expression
(number_literal))))
(variable_assignment
(assignment
(identifier)
(ERROR
(unary_expression
(identifier)))
(comparison_expression
(identifier)
(unary_expression
(identifier)))))
(abl_statement
statement: (identifier))
(variable_assignment
(assignment
(identifier)
(ERROR
(unary_expression
(identifier)))
(function_call
function: (identifier)))))
Currently, temp-table parsing is not implemented.
NOT x < 10 AND x = 10
Parses to
(unary_expression
(logical_expression
(comparison_expression
(identifier)
(number_literal))
(comparison_expression
(identifier)
(number_literal)))))))
As if it was NOT (x < 10 AND x = 10)
, should be (NOT x < 10) AND x = 10
.
Example:
define variable a as integer no-undo.
define variable b as integer no-undo.
if a = b then message "A".
else do:
message "B".
end.
Result:
Does not work when ELSE has do-end block
In test/corpus/basic.txt
, the expected output of z = NOT y > 5.
is incorrectly defined as:
(variable_assignment
(assignment
(identifier)
(expression
(comparison
(expression
(unary_expression
(expression
(identifier))))
(comparator)
(expression
(number_literal)))))
(terminator))
As if it were equivalent to z = ((NOT y) > 5).
, but OpenEdge ABL interprets this as being equivalent to z = (NOT (y > 5)).
.
The issue stems from the fact that the NOT
operator is defined as having a higher precedence than the comparison operator in grammar.js, contrary to the precedence table given in the ABL reference.
The same issue occurs in the "FIND FIRST (no terminator) statement" and the "TERNARY EXPRESSION (parenthesised) statement" test cases.
While working on #6, I identified a case where the parser emits an incorrect syntax tree, for the following code:
y = x < 10 OR x = 10.
Here's the emitted syntax tree:
(source_code
(statement
(variable_assignment
(assignment
(identifier)
(expression
(comparison
(expression
(identifier))
(comparator)
(expression
(logical_expression
(expression
(number_literal))
(logical_operator)
(expression
(comparison
(expression
(identifier))
(comparator)
(expression
(number_literal)))))))))
(terminator))))
The code is parsed as if it were equivalent to:
y = (x < (10 OR (x = 10))).
But the OpenEdge ABL parses it as:
y = ((x < 10) OR (x = 10)).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.