Loupi / node-cypher-parser

A Cypher parser/linter addon module for NodeJS.
MIT License
36 stars 9 forks source link

Comparison error in roots #6

Closed junknown closed 5 years ago

junknown commented 5 years ago

Roots elements in predicates of types 'comparison' ( like where a.prop>2) shows only the first argument ( a.prop).

To replicate try to parse

MATCH (n)--(friend)
    WHERE n.age > 3
    RETURN n

it reports as roots:

[ { type: 'statement', body: { type: 'query', clauses: [ { type: 'match', optional: false, pattern: { type: 'pattern', paths: [ { type: 'pattern-path', elements: [ { type: 'node-pattern', identifier: { type: 'identifier', name: 'n' }, labels: [] }, { type: 'rel-pattern', direction: 2, reltypes: [] }, { type: 'node-pattern', identifier: { type: 'identifier', name: 'friend' }, labels: [] } ] } ] }, hints: [], predicate: { type: 'comparison', length: 1, ops: [ 'greater-than' ], args: [ { type: 'property-operator', expression: { type: 'identifier', name: 'n' }, propName: { type: 'prop-name', value: 'age' } } ] } }, { type: 'return', distinct: false, includeExisting: false, projections: [ { type: 'projection', expression: { type: 'identifier', name: 'n' } } ] } ], options: [] }, options: [] } ]

Loupi commented 5 years ago

Thank you for the detailed info, it allowed me to spot the error quickly.

In parser.cpp, line 920 looks like: LoopNodes("args", cypher_ast_comparison_get_length(node), cypher_ast_comparison_get_argument); In fact, it should be: LoopNodes("args", cypher_ast_comparison_get_length(node) + 1, cypher_ast_comparison_get_argument);

A fix is coming.

Loupi commented 5 years ago

https://github.com/Loupi/node-cypher-parser/pull/7

Loupi commented 5 years ago

https://github.com/Loupi/node-cypher-parser/releases/tag/0.1.1

junknown commented 5 years ago

Thanks!