shivasurya / code-pathfinder

Code Pathfinder, the open-source alternative to CodeQL. Designed for precise flow analysis and advanced structural search, it identifies vulnerabilities in source code.
https://codepathfinder.dev/
GNU Affero General Public License v3.0
13 stars 5 forks source link

Enhanced Query Parser using ANTLR grammar definition #50

Open shivasurya opened 1 week ago

shivasurya commented 1 week ago

Using the ANTLR grammar, query parser can be enhanced and support more features including

grammar Query;

query           : 'FIND' select_list ('WHERE' expression)? ;
select_list     : select_item (',' select_item)* ;
select_item     : entity 'AS' alias ;
entity          : IDENTIFIER ;
alias           : IDENTIFIER ;
expression      : orExpression ;
orExpression    : andExpression ( 'OR' andExpression )* ;
andExpression   : notExpression ( 'AND' notExpression )* ;
notExpression   : 'NOT' notExpression
                | primary ;
primary         : condition
                | '(' expression ')' ;
condition       : alias '.' method_chain comparator value ;
method_chain    : method_or_variable ('.' method_or_variable)* ;
method_or_variable : method | variable ;
method          : IDENTIFIER '(' ')' ;
variable        : IDENTIFIER ;
comparator      : '=' | '!=' | '<' | '>' | '<=' | '>=' ;
value           : STRING | NUMBER ;
value_list      : value (',' value)* ;
STRING          : '"' ( ~('"' | '\\') | '\\' . )* '"' ;
NUMBER          : [0-9]+ ('.' [0-9]+)? ;
IDENTIFIER      : [a-zA-Z_][a-zA-Z0-9_]* ;
WS              : [ \t\r\n]+ -> skip ;
shivasurya commented 1 week ago

49 should be starting point for this change