Git Product home page Git Product logo

tree-sitter-abl's People

Contributors

jchros avatar jkbz64 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tree-sitter-abl's Issues

Issues when parsing objects

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

Implement REPEAT statement

This snippet returns an error:

repeat while true:
end.

It should be easy as REPEAT has basically identical structure to DO statement.

More operator precedence issues

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..

Can't use logic operators in expressions

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))))

Unary minus can't be used with many expressions

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)))))

Wrong precedence of unary expression w/ logical expressions

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.

Error when parsing ELSE block

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

Incorrect precendence of the `NOT` operator

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.

Wrong precedence of logical operators

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)).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.