From 05aee26f8091ce170629262780d703242c5cacf9 Mon Sep 17 00:00:00 2001 From: shivasurya Date: Sat, 8 Nov 2025 22:17:10 -0500 Subject: [PATCH] PR #1: Remove ANTLR/expr-lang query system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Removes legacy ANTLR query parser and expr-lang evaluation system to prepare for callgraph-native Python DSL. ## Breaking Changes - Removed ANTLR query syntax and parser (antlr/ directory) - Removed expr-lang evaluation engine (graph/query.go) - Stubbed out query, ci, and scan commands (will be reimplemented with Python DSL) - Removed dependencies: antlr4-go/antlr/v4, expr-lang/expr ## Files Changed **Deleted:** - antlr/* (13 files, ~200KB of generated code) - graph/query.go, graph/query_test.go - cmd/ci_test.go, cmd/scan_test.go **Modified:** - cmd/query.go, cmd/ci.go, cmd/scan.go (stubbed for Python DSL) - go.mod (removed ANTLR/expr-lang dependencies) - graph/parser_python_test.go (removed ANTLR query integration test) - main_test.go (updated expected command descriptions) **Added:** - cmd/query_test.go (simple stub test) ## Testing ✅ Build succeeds: gradle buildGo ✅ All tests pass: gradle testGo ✅ Lint clean: gradle lintGo ✅ No ANTLR/expr-lang imports remain ## Next Steps PR #2 will introduce Python DSL core matchers (calls(), variable(), flows()) 🤖 Generated with Claude Code --- sourcecode-parser/antlr/Query.g4 | 59 - sourcecode-parser/antlr/Query.interp | 127 - sourcecode-parser/antlr/Query.tokens | 69 - sourcecode-parser/antlr/QueryLexer.interp | 128 - sourcecode-parser/antlr/QueryLexer.tokens | 69 - sourcecode-parser/antlr/listener_impl.go | 389 - sourcecode-parser/antlr/listener_impl_test.go | 135 - .../antlr/query_base_listener.go | 274 - sourcecode-parser/antlr/query_lexer.go | 244 - sourcecode-parser/antlr/query_listener.go | 262 - sourcecode-parser/antlr/query_parser.go | 6538 ----------------- sourcecode-parser/cmd/ci.go | 291 +- sourcecode-parser/cmd/ci_test.go | 213 - sourcecode-parser/cmd/query.go | 267 +- sourcecode-parser/cmd/query_test.go | 465 +- sourcecode-parser/cmd/scan.go | 56 +- sourcecode-parser/cmd/scan_test.go | 95 - sourcecode-parser/go.mod | 8 - sourcecode-parser/go.sum | 15 - sourcecode-parser/graph/parser_python_test.go | 132 - sourcecode-parser/graph/query.go | 936 --- sourcecode-parser/graph/query_test.go | 577 -- sourcecode-parser/main_test.go | 2 +- 23 files changed, 18 insertions(+), 11333 deletions(-) delete mode 100644 sourcecode-parser/antlr/Query.g4 delete mode 100644 sourcecode-parser/antlr/Query.interp delete mode 100644 sourcecode-parser/antlr/Query.tokens delete mode 100644 sourcecode-parser/antlr/QueryLexer.interp delete mode 100644 sourcecode-parser/antlr/QueryLexer.tokens delete mode 100644 sourcecode-parser/antlr/listener_impl.go delete mode 100644 sourcecode-parser/antlr/listener_impl_test.go delete mode 100644 sourcecode-parser/antlr/query_base_listener.go delete mode 100644 sourcecode-parser/antlr/query_lexer.go delete mode 100644 sourcecode-parser/antlr/query_listener.go delete mode 100644 sourcecode-parser/antlr/query_parser.go delete mode 100644 sourcecode-parser/cmd/ci_test.go delete mode 100644 sourcecode-parser/cmd/scan_test.go delete mode 100644 sourcecode-parser/graph/query.go delete mode 100644 sourcecode-parser/graph/query_test.go diff --git a/sourcecode-parser/antlr/Query.g4 b/sourcecode-parser/antlr/Query.g4 deleted file mode 100644 index 8d80d42b..00000000 --- a/sourcecode-parser/antlr/Query.g4 +++ /dev/null @@ -1,59 +0,0 @@ -grammar Query; - -query: class_declarations? predicate_declarations? FROM select_list (WHERE expression)? SELECT select_clause; - -class_declarations: class_declaration+; -class_declaration: 'class' class_name '{' method_declarations '}'; -class_name: IDENTIFIER; -method_declarations: method_declaration+; -method_declaration: return_type method_name '(' parameter_list? ')' '{' method_body '}'; -method_name: IDENTIFIER; -method_body: return_statement; -return_statement: 'result' '=' value; -return_type: type; - -predicate_declarations: predicate_declaration+; -predicate_declaration: PREDICATE predicate_name '(' parameter_list? ')' '{' expression '}'; -predicate_name: IDENTIFIER; -parameter_list: parameter (',' parameter)*; -parameter: (type | class_name) IDENTIFIER; -type: IDENTIFIER; - -select_list: select_item (',' select_item)*; -select_item: (entity | class_name) AS alias; -entity: IDENTIFIER; -alias: IDENTIFIER; - -expression: orExpression; -orExpression: andExpression ( '||' andExpression )*; -andExpression: equalityExpression ( '&&' equalityExpression )*; -equalityExpression: relationalExpression ( ( '==' | '!=' ) relationalExpression )*; -relationalExpression: additiveExpression ( ( '<' | '>' | '<=' | '>=' | ' in ' ) additiveExpression )*; -additiveExpression: multiplicativeExpression ( ( '+' | '-' ) multiplicativeExpression )*; -multiplicativeExpression: unaryExpression ( ( '*' | '/' ) unaryExpression )*; -unaryExpression: ( '!' | '-' ) unaryExpression | primary; -primary: operand | predicate_invocation | '(' expression ')'; -operand: value | variable | alias '.' method_chain | class_name '.' method_chain | '[' value_list ']'; -method_chain: (class_name '.')? method_name '(' argument_list? ')'; -method_or_variable: method_invocation | variable | predicate_invocation; -method_invocation: IDENTIFIER '(' argument_list? ')'; -variable: IDENTIFIER; -predicate_invocation: predicate_name '(' argument_list? ')'; -argument_list: argument (',' argument)*; -argument: expression | STRING; -comparator: '==' | '!=' | '<' | '>' | '<=' | '>=' | 'LIKE' | 'in'; -value: STRING | NUMBER | STRING_WITH_WILDCARD; -value_list: value (',' value)*; -select_clause: select_expression (',' select_expression)*; -select_expression: variable | method_chain | STRING; - -STRING: '"' ( ~('"' | '\\') | '\\' . )* '"'; -STRING_WITH_WILDCARD: '"' ( ~('"' | '\\') | '\\' . | '%' )* '"'; -NUMBER: [0-9]+ ('.' [0-9]+)?; -PREDICATE: 'predicate'; -FROM: 'FROM'; -WHERE: 'WHERE'; -AS: 'AS'; -SELECT: 'SELECT'; -IDENTIFIER: [a-zA-Z_][a-zA-Z0-9_]*; -WS: [ \t\r\n]+ -> skip; \ No newline at end of file diff --git a/sourcecode-parser/antlr/Query.interp b/sourcecode-parser/antlr/Query.interp deleted file mode 100644 index baaf97e6..00000000 --- a/sourcecode-parser/antlr/Query.interp +++ /dev/null @@ -1,127 +0,0 @@ -token literal names: -null -'class' -'{' -'}' -'(' -')' -'result' -'=' -',' -'||' -'&&' -'==' -'!=' -'<' -'>' -'<=' -'>=' -' in ' -'+' -'-' -'*' -'/' -'!' -'.' -'[' -']' -'LIKE' -'in' -null -null -null -'predicate' -'FROM' -'WHERE' -'AS' -'SELECT' -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -STRING -STRING_WITH_WILDCARD -NUMBER -PREDICATE -FROM -WHERE -AS -SELECT -IDENTIFIER -WS - -rule names: -query -class_declarations -class_declaration -class_name -method_declarations -method_declaration -method_name -method_body -return_statement -return_type -predicate_declarations -predicate_declaration -predicate_name -parameter_list -parameter -type -select_list -select_item -entity -alias -expression -orExpression -andExpression -equalityExpression -relationalExpression -additiveExpression -multiplicativeExpression -unaryExpression -primary -operand -method_chain -method_or_variable -method_invocation -variable -predicate_invocation -argument_list -argument -comparator -value -value_list -select_clause -select_expression - - -atn: -[4, 1, 37, 341, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 1, 0, 3, 0, 86, 8, 0, 1, 0, 3, 0, 89, 8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 95, 8, 0, 1, 0, 1, 0, 1, 0, 1, 1, 4, 1, 101, 8, 1, 11, 1, 12, 1, 102, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 4, 4, 114, 8, 4, 11, 4, 12, 4, 115, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 122, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 4, 10, 140, 8, 10, 11, 10, 12, 10, 141, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 148, 8, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 5, 13, 160, 8, 13, 10, 13, 12, 13, 163, 9, 13, 1, 14, 1, 14, 3, 14, 167, 8, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 5, 16, 176, 8, 16, 10, 16, 12, 16, 179, 9, 16, 1, 17, 1, 17, 3, 17, 183, 8, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 5, 21, 197, 8, 21, 10, 21, 12, 21, 200, 9, 21, 1, 22, 1, 22, 1, 22, 5, 22, 205, 8, 22, 10, 22, 12, 22, 208, 9, 22, 1, 23, 1, 23, 1, 23, 5, 23, 213, 8, 23, 10, 23, 12, 23, 216, 9, 23, 1, 24, 1, 24, 1, 24, 5, 24, 221, 8, 24, 10, 24, 12, 24, 224, 9, 24, 1, 25, 1, 25, 1, 25, 5, 25, 229, 8, 25, 10, 25, 12, 25, 232, 9, 25, 1, 26, 1, 26, 1, 26, 5, 26, 237, 8, 26, 10, 26, 12, 26, 240, 9, 26, 1, 27, 1, 27, 1, 27, 3, 27, 245, 8, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 3, 28, 253, 8, 28, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 3, 29, 269, 8, 29, 1, 30, 1, 30, 1, 30, 3, 30, 274, 8, 30, 1, 30, 1, 30, 1, 30, 3, 30, 279, 8, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 3, 31, 286, 8, 31, 1, 32, 1, 32, 1, 32, 3, 32, 291, 8, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 3, 34, 300, 8, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 5, 35, 307, 8, 35, 10, 35, 12, 35, 310, 9, 35, 1, 36, 1, 36, 3, 36, 314, 8, 36, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 5, 39, 323, 8, 39, 10, 39, 12, 39, 326, 9, 39, 1, 40, 1, 40, 1, 40, 5, 40, 331, 8, 40, 10, 40, 12, 40, 334, 9, 40, 1, 41, 1, 41, 1, 41, 3, 41, 339, 8, 41, 1, 41, 0, 0, 42, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 0, 7, 1, 0, 11, 12, 1, 0, 13, 17, 1, 0, 18, 19, 1, 0, 20, 21, 2, 0, 19, 19, 22, 22, 2, 0, 11, 16, 26, 27, 1, 0, 28, 30, 335, 0, 85, 1, 0, 0, 0, 2, 100, 1, 0, 0, 0, 4, 104, 1, 0, 0, 0, 6, 110, 1, 0, 0, 0, 8, 113, 1, 0, 0, 0, 10, 117, 1, 0, 0, 0, 12, 128, 1, 0, 0, 0, 14, 130, 1, 0, 0, 0, 16, 132, 1, 0, 0, 0, 18, 136, 1, 0, 0, 0, 20, 139, 1, 0, 0, 0, 22, 143, 1, 0, 0, 0, 24, 154, 1, 0, 0, 0, 26, 156, 1, 0, 0, 0, 28, 166, 1, 0, 0, 0, 30, 170, 1, 0, 0, 0, 32, 172, 1, 0, 0, 0, 34, 182, 1, 0, 0, 0, 36, 187, 1, 0, 0, 0, 38, 189, 1, 0, 0, 0, 40, 191, 1, 0, 0, 0, 42, 193, 1, 0, 0, 0, 44, 201, 1, 0, 0, 0, 46, 209, 1, 0, 0, 0, 48, 217, 1, 0, 0, 0, 50, 225, 1, 0, 0, 0, 52, 233, 1, 0, 0, 0, 54, 244, 1, 0, 0, 0, 56, 252, 1, 0, 0, 0, 58, 268, 1, 0, 0, 0, 60, 273, 1, 0, 0, 0, 62, 285, 1, 0, 0, 0, 64, 287, 1, 0, 0, 0, 66, 294, 1, 0, 0, 0, 68, 296, 1, 0, 0, 0, 70, 303, 1, 0, 0, 0, 72, 313, 1, 0, 0, 0, 74, 315, 1, 0, 0, 0, 76, 317, 1, 0, 0, 0, 78, 319, 1, 0, 0, 0, 80, 327, 1, 0, 0, 0, 82, 338, 1, 0, 0, 0, 84, 86, 3, 2, 1, 0, 85, 84, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 89, 3, 20, 10, 0, 88, 87, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 91, 5, 32, 0, 0, 91, 94, 3, 32, 16, 0, 92, 93, 5, 33, 0, 0, 93, 95, 3, 40, 20, 0, 94, 92, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 97, 5, 35, 0, 0, 97, 98, 3, 80, 40, 0, 98, 1, 1, 0, 0, 0, 99, 101, 3, 4, 2, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 3, 1, 0, 0, 0, 104, 105, 5, 1, 0, 0, 105, 106, 3, 6, 3, 0, 106, 107, 5, 2, 0, 0, 107, 108, 3, 8, 4, 0, 108, 109, 5, 3, 0, 0, 109, 5, 1, 0, 0, 0, 110, 111, 5, 36, 0, 0, 111, 7, 1, 0, 0, 0, 112, 114, 3, 10, 5, 0, 113, 112, 1, 0, 0, 0, 114, 115, 1, 0, 0, 0, 115, 113, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 9, 1, 0, 0, 0, 117, 118, 3, 18, 9, 0, 118, 119, 3, 12, 6, 0, 119, 121, 5, 4, 0, 0, 120, 122, 3, 26, 13, 0, 121, 120, 1, 0, 0, 0, 121, 122, 1, 0, 0, 0, 122, 123, 1, 0, 0, 0, 123, 124, 5, 5, 0, 0, 124, 125, 5, 2, 0, 0, 125, 126, 3, 14, 7, 0, 126, 127, 5, 3, 0, 0, 127, 11, 1, 0, 0, 0, 128, 129, 5, 36, 0, 0, 129, 13, 1, 0, 0, 0, 130, 131, 3, 16, 8, 0, 131, 15, 1, 0, 0, 0, 132, 133, 5, 6, 0, 0, 133, 134, 5, 7, 0, 0, 134, 135, 3, 76, 38, 0, 135, 17, 1, 0, 0, 0, 136, 137, 3, 30, 15, 0, 137, 19, 1, 0, 0, 0, 138, 140, 3, 22, 11, 0, 139, 138, 1, 0, 0, 0, 140, 141, 1, 0, 0, 0, 141, 139, 1, 0, 0, 0, 141, 142, 1, 0, 0, 0, 142, 21, 1, 0, 0, 0, 143, 144, 5, 31, 0, 0, 144, 145, 3, 24, 12, 0, 145, 147, 5, 4, 0, 0, 146, 148, 3, 26, 13, 0, 147, 146, 1, 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 149, 1, 0, 0, 0, 149, 150, 5, 5, 0, 0, 150, 151, 5, 2, 0, 0, 151, 152, 3, 40, 20, 0, 152, 153, 5, 3, 0, 0, 153, 23, 1, 0, 0, 0, 154, 155, 5, 36, 0, 0, 155, 25, 1, 0, 0, 0, 156, 161, 3, 28, 14, 0, 157, 158, 5, 8, 0, 0, 158, 160, 3, 28, 14, 0, 159, 157, 1, 0, 0, 0, 160, 163, 1, 0, 0, 0, 161, 159, 1, 0, 0, 0, 161, 162, 1, 0, 0, 0, 162, 27, 1, 0, 0, 0, 163, 161, 1, 0, 0, 0, 164, 167, 3, 30, 15, 0, 165, 167, 3, 6, 3, 0, 166, 164, 1, 0, 0, 0, 166, 165, 1, 0, 0, 0, 167, 168, 1, 0, 0, 0, 168, 169, 5, 36, 0, 0, 169, 29, 1, 0, 0, 0, 170, 171, 5, 36, 0, 0, 171, 31, 1, 0, 0, 0, 172, 177, 3, 34, 17, 0, 173, 174, 5, 8, 0, 0, 174, 176, 3, 34, 17, 0, 175, 173, 1, 0, 0, 0, 176, 179, 1, 0, 0, 0, 177, 175, 1, 0, 0, 0, 177, 178, 1, 0, 0, 0, 178, 33, 1, 0, 0, 0, 179, 177, 1, 0, 0, 0, 180, 183, 3, 36, 18, 0, 181, 183, 3, 6, 3, 0, 182, 180, 1, 0, 0, 0, 182, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 185, 5, 34, 0, 0, 185, 186, 3, 38, 19, 0, 186, 35, 1, 0, 0, 0, 187, 188, 5, 36, 0, 0, 188, 37, 1, 0, 0, 0, 189, 190, 5, 36, 0, 0, 190, 39, 1, 0, 0, 0, 191, 192, 3, 42, 21, 0, 192, 41, 1, 0, 0, 0, 193, 198, 3, 44, 22, 0, 194, 195, 5, 9, 0, 0, 195, 197, 3, 44, 22, 0, 196, 194, 1, 0, 0, 0, 197, 200, 1, 0, 0, 0, 198, 196, 1, 0, 0, 0, 198, 199, 1, 0, 0, 0, 199, 43, 1, 0, 0, 0, 200, 198, 1, 0, 0, 0, 201, 206, 3, 46, 23, 0, 202, 203, 5, 10, 0, 0, 203, 205, 3, 46, 23, 0, 204, 202, 1, 0, 0, 0, 205, 208, 1, 0, 0, 0, 206, 204, 1, 0, 0, 0, 206, 207, 1, 0, 0, 0, 207, 45, 1, 0, 0, 0, 208, 206, 1, 0, 0, 0, 209, 214, 3, 48, 24, 0, 210, 211, 7, 0, 0, 0, 211, 213, 3, 48, 24, 0, 212, 210, 1, 0, 0, 0, 213, 216, 1, 0, 0, 0, 214, 212, 1, 0, 0, 0, 214, 215, 1, 0, 0, 0, 215, 47, 1, 0, 0, 0, 216, 214, 1, 0, 0, 0, 217, 222, 3, 50, 25, 0, 218, 219, 7, 1, 0, 0, 219, 221, 3, 50, 25, 0, 220, 218, 1, 0, 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, 0, 223, 49, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 225, 230, 3, 52, 26, 0, 226, 227, 7, 2, 0, 0, 227, 229, 3, 52, 26, 0, 228, 226, 1, 0, 0, 0, 229, 232, 1, 0, 0, 0, 230, 228, 1, 0, 0, 0, 230, 231, 1, 0, 0, 0, 231, 51, 1, 0, 0, 0, 232, 230, 1, 0, 0, 0, 233, 238, 3, 54, 27, 0, 234, 235, 7, 3, 0, 0, 235, 237, 3, 54, 27, 0, 236, 234, 1, 0, 0, 0, 237, 240, 1, 0, 0, 0, 238, 236, 1, 0, 0, 0, 238, 239, 1, 0, 0, 0, 239, 53, 1, 0, 0, 0, 240, 238, 1, 0, 0, 0, 241, 242, 7, 4, 0, 0, 242, 245, 3, 54, 27, 0, 243, 245, 3, 56, 28, 0, 244, 241, 1, 0, 0, 0, 244, 243, 1, 0, 0, 0, 245, 55, 1, 0, 0, 0, 246, 253, 3, 58, 29, 0, 247, 253, 3, 68, 34, 0, 248, 249, 5, 4, 0, 0, 249, 250, 3, 40, 20, 0, 250, 251, 5, 5, 0, 0, 251, 253, 1, 0, 0, 0, 252, 246, 1, 0, 0, 0, 252, 247, 1, 0, 0, 0, 252, 248, 1, 0, 0, 0, 253, 57, 1, 0, 0, 0, 254, 269, 3, 76, 38, 0, 255, 269, 3, 66, 33, 0, 256, 257, 3, 38, 19, 0, 257, 258, 5, 23, 0, 0, 258, 259, 3, 60, 30, 0, 259, 269, 1, 0, 0, 0, 260, 261, 3, 6, 3, 0, 261, 262, 5, 23, 0, 0, 262, 263, 3, 60, 30, 0, 263, 269, 1, 0, 0, 0, 264, 265, 5, 24, 0, 0, 265, 266, 3, 78, 39, 0, 266, 267, 5, 25, 0, 0, 267, 269, 1, 0, 0, 0, 268, 254, 1, 0, 0, 0, 268, 255, 1, 0, 0, 0, 268, 256, 1, 0, 0, 0, 268, 260, 1, 0, 0, 0, 268, 264, 1, 0, 0, 0, 269, 59, 1, 0, 0, 0, 270, 271, 3, 6, 3, 0, 271, 272, 5, 23, 0, 0, 272, 274, 1, 0, 0, 0, 273, 270, 1, 0, 0, 0, 273, 274, 1, 0, 0, 0, 274, 275, 1, 0, 0, 0, 275, 276, 3, 12, 6, 0, 276, 278, 5, 4, 0, 0, 277, 279, 3, 70, 35, 0, 278, 277, 1, 0, 0, 0, 278, 279, 1, 0, 0, 0, 279, 280, 1, 0, 0, 0, 280, 281, 5, 5, 0, 0, 281, 61, 1, 0, 0, 0, 282, 286, 3, 64, 32, 0, 283, 286, 3, 66, 33, 0, 284, 286, 3, 68, 34, 0, 285, 282, 1, 0, 0, 0, 285, 283, 1, 0, 0, 0, 285, 284, 1, 0, 0, 0, 286, 63, 1, 0, 0, 0, 287, 288, 5, 36, 0, 0, 288, 290, 5, 4, 0, 0, 289, 291, 3, 70, 35, 0, 290, 289, 1, 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 292, 1, 0, 0, 0, 292, 293, 5, 5, 0, 0, 293, 65, 1, 0, 0, 0, 294, 295, 5, 36, 0, 0, 295, 67, 1, 0, 0, 0, 296, 297, 3, 24, 12, 0, 297, 299, 5, 4, 0, 0, 298, 300, 3, 70, 35, 0, 299, 298, 1, 0, 0, 0, 299, 300, 1, 0, 0, 0, 300, 301, 1, 0, 0, 0, 301, 302, 5, 5, 0, 0, 302, 69, 1, 0, 0, 0, 303, 308, 3, 72, 36, 0, 304, 305, 5, 8, 0, 0, 305, 307, 3, 72, 36, 0, 306, 304, 1, 0, 0, 0, 307, 310, 1, 0, 0, 0, 308, 306, 1, 0, 0, 0, 308, 309, 1, 0, 0, 0, 309, 71, 1, 0, 0, 0, 310, 308, 1, 0, 0, 0, 311, 314, 3, 40, 20, 0, 312, 314, 5, 28, 0, 0, 313, 311, 1, 0, 0, 0, 313, 312, 1, 0, 0, 0, 314, 73, 1, 0, 0, 0, 315, 316, 7, 5, 0, 0, 316, 75, 1, 0, 0, 0, 317, 318, 7, 6, 0, 0, 318, 77, 1, 0, 0, 0, 319, 324, 3, 76, 38, 0, 320, 321, 5, 8, 0, 0, 321, 323, 3, 76, 38, 0, 322, 320, 1, 0, 0, 0, 323, 326, 1, 0, 0, 0, 324, 322, 1, 0, 0, 0, 324, 325, 1, 0, 0, 0, 325, 79, 1, 0, 0, 0, 326, 324, 1, 0, 0, 0, 327, 332, 3, 82, 41, 0, 328, 329, 5, 8, 0, 0, 329, 331, 3, 82, 41, 0, 330, 328, 1, 0, 0, 0, 331, 334, 1, 0, 0, 0, 332, 330, 1, 0, 0, 0, 332, 333, 1, 0, 0, 0, 333, 81, 1, 0, 0, 0, 334, 332, 1, 0, 0, 0, 335, 339, 3, 66, 33, 0, 336, 339, 3, 60, 30, 0, 337, 339, 5, 28, 0, 0, 338, 335, 1, 0, 0, 0, 338, 336, 1, 0, 0, 0, 338, 337, 1, 0, 0, 0, 339, 83, 1, 0, 0, 0, 31, 85, 88, 94, 102, 115, 121, 141, 147, 161, 166, 177, 182, 198, 206, 214, 222, 230, 238, 244, 252, 268, 273, 278, 285, 290, 299, 308, 313, 324, 332, 338] \ No newline at end of file diff --git a/sourcecode-parser/antlr/Query.tokens b/sourcecode-parser/antlr/Query.tokens deleted file mode 100644 index 3130e15b..00000000 --- a/sourcecode-parser/antlr/Query.tokens +++ /dev/null @@ -1,69 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -STRING=28 -STRING_WITH_WILDCARD=29 -NUMBER=30 -PREDICATE=31 -FROM=32 -WHERE=33 -AS=34 -SELECT=35 -IDENTIFIER=36 -WS=37 -'class'=1 -'{'=2 -'}'=3 -'('=4 -')'=5 -'result'=6 -'='=7 -','=8 -'||'=9 -'&&'=10 -'=='=11 -'!='=12 -'<'=13 -'>'=14 -'<='=15 -'>='=16 -' in '=17 -'+'=18 -'-'=19 -'*'=20 -'/'=21 -'!'=22 -'.'=23 -'['=24 -']'=25 -'LIKE'=26 -'in'=27 -'predicate'=31 -'FROM'=32 -'WHERE'=33 -'AS'=34 -'SELECT'=35 diff --git a/sourcecode-parser/antlr/QueryLexer.interp b/sourcecode-parser/antlr/QueryLexer.interp deleted file mode 100644 index 2890fc2e..00000000 --- a/sourcecode-parser/antlr/QueryLexer.interp +++ /dev/null @@ -1,128 +0,0 @@ -token literal names: -null -'class' -'{' -'}' -'(' -')' -'result' -'=' -',' -'||' -'&&' -'==' -'!=' -'<' -'>' -'<=' -'>=' -' in ' -'+' -'-' -'*' -'/' -'!' -'.' -'[' -']' -'LIKE' -'in' -null -null -null -'predicate' -'FROM' -'WHERE' -'AS' -'SELECT' -null -null - -token symbolic names: -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -null -STRING -STRING_WITH_WILDCARD -NUMBER -PREDICATE -FROM -WHERE -AS -SELECT -IDENTIFIER -WS - -rule names: -T__0 -T__1 -T__2 -T__3 -T__4 -T__5 -T__6 -T__7 -T__8 -T__9 -T__10 -T__11 -T__12 -T__13 -T__14 -T__15 -T__16 -T__17 -T__18 -T__19 -T__20 -T__21 -T__22 -T__23 -T__24 -T__25 -T__26 -STRING -STRING_WITH_WILDCARD -NUMBER -PREDICATE -FROM -WHERE -AS -SELECT -IDENTIFIER -WS - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 37, 232, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 156, 8, 27, 10, 27, 12, 27, 159, 9, 27, 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 5, 28, 168, 8, 28, 10, 28, 12, 28, 171, 9, 28, 1, 28, 1, 28, 1, 29, 4, 29, 176, 8, 29, 11, 29, 12, 29, 177, 1, 29, 1, 29, 4, 29, 182, 8, 29, 11, 29, 12, 29, 183, 3, 29, 186, 8, 29, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 34, 1, 34, 1, 34, 1, 34, 1, 35, 1, 35, 5, 35, 221, 8, 35, 10, 35, 12, 35, 224, 9, 35, 1, 36, 4, 36, 227, 8, 36, 11, 36, 12, 36, 228, 1, 36, 1, 36, 0, 0, 37, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 35, 71, 36, 73, 37, 1, 0, 5, 2, 0, 34, 34, 92, 92, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 241, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 1, 75, 1, 0, 0, 0, 3, 81, 1, 0, 0, 0, 5, 83, 1, 0, 0, 0, 7, 85, 1, 0, 0, 0, 9, 87, 1, 0, 0, 0, 11, 89, 1, 0, 0, 0, 13, 96, 1, 0, 0, 0, 15, 98, 1, 0, 0, 0, 17, 100, 1, 0, 0, 0, 19, 103, 1, 0, 0, 0, 21, 106, 1, 0, 0, 0, 23, 109, 1, 0, 0, 0, 25, 112, 1, 0, 0, 0, 27, 114, 1, 0, 0, 0, 29, 116, 1, 0, 0, 0, 31, 119, 1, 0, 0, 0, 33, 122, 1, 0, 0, 0, 35, 127, 1, 0, 0, 0, 37, 129, 1, 0, 0, 0, 39, 131, 1, 0, 0, 0, 41, 133, 1, 0, 0, 0, 43, 135, 1, 0, 0, 0, 45, 137, 1, 0, 0, 0, 47, 139, 1, 0, 0, 0, 49, 141, 1, 0, 0, 0, 51, 143, 1, 0, 0, 0, 53, 148, 1, 0, 0, 0, 55, 151, 1, 0, 0, 0, 57, 162, 1, 0, 0, 0, 59, 175, 1, 0, 0, 0, 61, 187, 1, 0, 0, 0, 63, 197, 1, 0, 0, 0, 65, 202, 1, 0, 0, 0, 67, 208, 1, 0, 0, 0, 69, 211, 1, 0, 0, 0, 71, 218, 1, 0, 0, 0, 73, 226, 1, 0, 0, 0, 75, 76, 5, 99, 0, 0, 76, 77, 5, 108, 0, 0, 77, 78, 5, 97, 0, 0, 78, 79, 5, 115, 0, 0, 79, 80, 5, 115, 0, 0, 80, 2, 1, 0, 0, 0, 81, 82, 5, 123, 0, 0, 82, 4, 1, 0, 0, 0, 83, 84, 5, 125, 0, 0, 84, 6, 1, 0, 0, 0, 85, 86, 5, 40, 0, 0, 86, 8, 1, 0, 0, 0, 87, 88, 5, 41, 0, 0, 88, 10, 1, 0, 0, 0, 89, 90, 5, 114, 0, 0, 90, 91, 5, 101, 0, 0, 91, 92, 5, 115, 0, 0, 92, 93, 5, 117, 0, 0, 93, 94, 5, 108, 0, 0, 94, 95, 5, 116, 0, 0, 95, 12, 1, 0, 0, 0, 96, 97, 5, 61, 0, 0, 97, 14, 1, 0, 0, 0, 98, 99, 5, 44, 0, 0, 99, 16, 1, 0, 0, 0, 100, 101, 5, 124, 0, 0, 101, 102, 5, 124, 0, 0, 102, 18, 1, 0, 0, 0, 103, 104, 5, 38, 0, 0, 104, 105, 5, 38, 0, 0, 105, 20, 1, 0, 0, 0, 106, 107, 5, 61, 0, 0, 107, 108, 5, 61, 0, 0, 108, 22, 1, 0, 0, 0, 109, 110, 5, 33, 0, 0, 110, 111, 5, 61, 0, 0, 111, 24, 1, 0, 0, 0, 112, 113, 5, 60, 0, 0, 113, 26, 1, 0, 0, 0, 114, 115, 5, 62, 0, 0, 115, 28, 1, 0, 0, 0, 116, 117, 5, 60, 0, 0, 117, 118, 5, 61, 0, 0, 118, 30, 1, 0, 0, 0, 119, 120, 5, 62, 0, 0, 120, 121, 5, 61, 0, 0, 121, 32, 1, 0, 0, 0, 122, 123, 5, 32, 0, 0, 123, 124, 5, 105, 0, 0, 124, 125, 5, 110, 0, 0, 125, 126, 5, 32, 0, 0, 126, 34, 1, 0, 0, 0, 127, 128, 5, 43, 0, 0, 128, 36, 1, 0, 0, 0, 129, 130, 5, 45, 0, 0, 130, 38, 1, 0, 0, 0, 131, 132, 5, 42, 0, 0, 132, 40, 1, 0, 0, 0, 133, 134, 5, 47, 0, 0, 134, 42, 1, 0, 0, 0, 135, 136, 5, 33, 0, 0, 136, 44, 1, 0, 0, 0, 137, 138, 5, 46, 0, 0, 138, 46, 1, 0, 0, 0, 139, 140, 5, 91, 0, 0, 140, 48, 1, 0, 0, 0, 141, 142, 5, 93, 0, 0, 142, 50, 1, 0, 0, 0, 143, 144, 5, 76, 0, 0, 144, 145, 5, 73, 0, 0, 145, 146, 5, 75, 0, 0, 146, 147, 5, 69, 0, 0, 147, 52, 1, 0, 0, 0, 148, 149, 5, 105, 0, 0, 149, 150, 5, 110, 0, 0, 150, 54, 1, 0, 0, 0, 151, 157, 5, 34, 0, 0, 152, 156, 8, 0, 0, 0, 153, 154, 5, 92, 0, 0, 154, 156, 9, 0, 0, 0, 155, 152, 1, 0, 0, 0, 155, 153, 1, 0, 0, 0, 156, 159, 1, 0, 0, 0, 157, 155, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 160, 1, 0, 0, 0, 159, 157, 1, 0, 0, 0, 160, 161, 5, 34, 0, 0, 161, 56, 1, 0, 0, 0, 162, 169, 5, 34, 0, 0, 163, 168, 8, 0, 0, 0, 164, 165, 5, 92, 0, 0, 165, 168, 9, 0, 0, 0, 166, 168, 5, 37, 0, 0, 167, 163, 1, 0, 0, 0, 167, 164, 1, 0, 0, 0, 167, 166, 1, 0, 0, 0, 168, 171, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 172, 1, 0, 0, 0, 171, 169, 1, 0, 0, 0, 172, 173, 5, 34, 0, 0, 173, 58, 1, 0, 0, 0, 174, 176, 7, 1, 0, 0, 175, 174, 1, 0, 0, 0, 176, 177, 1, 0, 0, 0, 177, 175, 1, 0, 0, 0, 177, 178, 1, 0, 0, 0, 178, 185, 1, 0, 0, 0, 179, 181, 5, 46, 0, 0, 180, 182, 7, 1, 0, 0, 181, 180, 1, 0, 0, 0, 182, 183, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 179, 1, 0, 0, 0, 185, 186, 1, 0, 0, 0, 186, 60, 1, 0, 0, 0, 187, 188, 5, 112, 0, 0, 188, 189, 5, 114, 0, 0, 189, 190, 5, 101, 0, 0, 190, 191, 5, 100, 0, 0, 191, 192, 5, 105, 0, 0, 192, 193, 5, 99, 0, 0, 193, 194, 5, 97, 0, 0, 194, 195, 5, 116, 0, 0, 195, 196, 5, 101, 0, 0, 196, 62, 1, 0, 0, 0, 197, 198, 5, 70, 0, 0, 198, 199, 5, 82, 0, 0, 199, 200, 5, 79, 0, 0, 200, 201, 5, 77, 0, 0, 201, 64, 1, 0, 0, 0, 202, 203, 5, 87, 0, 0, 203, 204, 5, 72, 0, 0, 204, 205, 5, 69, 0, 0, 205, 206, 5, 82, 0, 0, 206, 207, 5, 69, 0, 0, 207, 66, 1, 0, 0, 0, 208, 209, 5, 65, 0, 0, 209, 210, 5, 83, 0, 0, 210, 68, 1, 0, 0, 0, 211, 212, 5, 83, 0, 0, 212, 213, 5, 69, 0, 0, 213, 214, 5, 76, 0, 0, 214, 215, 5, 69, 0, 0, 215, 216, 5, 67, 0, 0, 216, 217, 5, 84, 0, 0, 217, 70, 1, 0, 0, 0, 218, 222, 7, 2, 0, 0, 219, 221, 7, 3, 0, 0, 220, 219, 1, 0, 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, 0, 223, 72, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 225, 227, 7, 4, 0, 0, 226, 225, 1, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 226, 1, 0, 0, 0, 228, 229, 1, 0, 0, 0, 229, 230, 1, 0, 0, 0, 230, 231, 6, 36, 0, 0, 231, 74, 1, 0, 0, 0, 10, 0, 155, 157, 167, 169, 177, 183, 185, 222, 228, 1, 6, 0, 0] \ No newline at end of file diff --git a/sourcecode-parser/antlr/QueryLexer.tokens b/sourcecode-parser/antlr/QueryLexer.tokens deleted file mode 100644 index 3130e15b..00000000 --- a/sourcecode-parser/antlr/QueryLexer.tokens +++ /dev/null @@ -1,69 +0,0 @@ -T__0=1 -T__1=2 -T__2=3 -T__3=4 -T__4=5 -T__5=6 -T__6=7 -T__7=8 -T__8=9 -T__9=10 -T__10=11 -T__11=12 -T__12=13 -T__13=14 -T__14=15 -T__15=16 -T__16=17 -T__17=18 -T__18=19 -T__19=20 -T__20=21 -T__21=22 -T__22=23 -T__23=24 -T__24=25 -T__25=26 -T__26=27 -STRING=28 -STRING_WITH_WILDCARD=29 -NUMBER=30 -PREDICATE=31 -FROM=32 -WHERE=33 -AS=34 -SELECT=35 -IDENTIFIER=36 -WS=37 -'class'=1 -'{'=2 -'}'=3 -'('=4 -')'=5 -'result'=6 -'='=7 -','=8 -'||'=9 -'&&'=10 -'=='=11 -'!='=12 -'<'=13 -'>'=14 -'<='=15 -'>='=16 -' in '=17 -'+'=18 -'-'=19 -'*'=20 -'/'=21 -'!'=22 -'.'=23 -'['=24 -']'=25 -'LIKE'=26 -'in'=27 -'predicate'=31 -'FROM'=32 -'WHERE'=33 -'AS'=34 -'SELECT'=35 diff --git a/sourcecode-parser/antlr/listener_impl.go b/sourcecode-parser/antlr/listener_impl.go deleted file mode 100644 index 48836a25..00000000 --- a/sourcecode-parser/antlr/listener_impl.go +++ /dev/null @@ -1,389 +0,0 @@ -package parser - -import ( - "fmt" - "strings" - - "github.com/antlr4-go/antlr/v4" -) - -type Parameter struct { - Name string - Type string - DefaultValue string -} - -type Predicate struct { - PredicateName string - Parameter []Parameter - Body string -} - -type PredicateInvocation struct { - PredicateName string - Parameter []Parameter - Predicate Predicate -} - -type Query struct { - Classes []ClassDeclaration - SelectList []SelectList - Expression string - Condition []string - Predicate []Predicate - PredicateInvocation []PredicateInvocation - SelectOutput []SelectOutput -} - -type CustomQueryListener struct { - BaseQueryListener - expression strings.Builder - selectList []SelectList - condition []string - Predicate []Predicate - PredicateInvocation []PredicateInvocation - Classes []ClassDeclaration - State State - SelectOutput []SelectOutput -} - -func (l *CustomQueryListener) EnterMethod_chain(ctx *Method_chainContext) { //nolint:all - // Handle class method calls - if ctx.Class_name() != nil { - className := ctx.Class_name().GetText() - methodName := ctx.Method_name().GetText() - - // Find the class and method - for _, class := range l.Classes { - if class.Name == className { - for _, method := range class.Methods { - if method.Name == methodName { - // Store method call information - l.SelectOutput = append(l.SelectOutput, SelectOutput{ - SelectEntity: ctx.GetText(), - Type: "class_method", - }) - return - } - } - } - } - } - - // Handle existing method chain logic - if ctx.Method_name() != nil { - l.SelectOutput = append(l.SelectOutput, SelectOutput{ - SelectEntity: ctx.GetText(), - Type: "method_chain", - }) - } -} - -type State struct { - isInPredicateDeclaration bool -} - -type ClassDeclaration struct { - Name string - Methods []MethodDeclaration -} - -type MethodDeclaration struct { - Name string - ReturnType string - Body string -} - -type SelectList struct { - Entity string - Alias string -} - -type SelectOutput struct { - SelectEntity string - Type string -} - -func (l *CustomQueryListener) EnterClass_declaration(ctx *Class_declarationContext) { //nolint:all - className := ctx.Class_name().GetText() - class := ClassDeclaration{ - Name: className, - } - l.Classes = append(l.Classes, class) -} - -func (l *CustomQueryListener) EnterMethod_declaration(ctx *Method_declarationContext) { //nolint:all - if len(l.Classes) > 0 { - currentClass := &l.Classes[len(l.Classes)-1] - method := MethodDeclaration{ - Name: ctx.Method_name().GetText(), - ReturnType: ctx.Return_type().GetText(), - Body: ctx.Method_body().GetText(), - } - currentClass.Methods = append(currentClass.Methods, method) - } -} - -type customErrorListener struct { - *antlr.DefaultErrorListener - errors []string -} - -func (l *customErrorListener) SyntaxError(_ antlr.Recognizer, _ interface{}, line, column int, msg string, _ antlr.RecognitionException) { - l.errors = append(l.errors, fmt.Sprintf("line %d:%d %s", line, column, msg)) -} - -func NewCustomQueryListener() *CustomQueryListener { - return &CustomQueryListener{ - BaseQueryListener: BaseQueryListener{}, - } -} - -//nolint:all -func (l *CustomQueryListener) EnterSelect_expression(ctx *Select_expressionContext) { - // get the select expression type and set it to the select output - var selectType string - switch { - case ctx.Variable() != nil: - selectType = "variable" - case ctx.Method_chain() != nil: - selectType = "method_chain" - case ctx.STRING() != nil: - selectType = "string" - } - - l.SelectOutput = append(l.SelectOutput, SelectOutput{ - SelectEntity: ctx.GetText(), - Type: selectType, - }) -} - -//nolint:all -func (l *CustomQueryListener) EnterSelect_list(ctx *Select_listContext) { - for i := 0; i < ctx.GetChildCount(); i++ { - child := ctx.GetChild(i).(antlr.ParseTree) - if child, ok := child.(ISelect_itemContext); ok { - l.selectList = append(l.selectList, SelectList{ - Entity: child.Entity().GetText(), - Alias: child.Alias().GetText(), - }) - } - } -} - -//nolint:all -func (l *CustomQueryListener) EnterPredicate_invocation(ctx *Predicate_invocationContext) { - predicateName := ctx.Predicate_name().GetText() - parameters := ctx.Argument_list().GetText() - // split the arguments by comma - invokedPredicateArgs := strings.Split(parameters, ",") - arguments := l.extractArguments(invokedPredicateArgs) - invokedPredicate := PredicateInvocation{ - PredicateName: predicateName, - Parameter: arguments, - } - matchedPredicate, err := l.matchPredicate(invokedPredicate) - if err == nil { - invokedPredicate.Predicate = matchedPredicate - } - l.PredicateInvocation = append(l.PredicateInvocation, invokedPredicate) -} - -//nolint:all -func (l *CustomQueryListener) EnterPredicate_declaration(ctx *Predicate_declarationContext) { - if l.State == (State{}) { - l.State = State{ - isInPredicateDeclaration: true, - } - } - name := ctx.Predicate_name().GetText() - var params []Parameter - if ctx.Parameter_list() != nil { - for _, paramCtx := range ctx.Parameter_list().AllParameter() { - paramType := paramCtx.Type_().GetText() - paramName := paramCtx.IDENTIFIER().GetText() - param := Parameter{ - Name: paramName, - Type: paramType, - DefaultValue: "", - } - params = append(params, param) - } - } - body := ctx.Expression() - - if l.Predicate == nil { - l.Predicate = []Predicate{} - } - - l.Predicate = append(l.Predicate, Predicate{ - PredicateName: name, - Parameter: params, - Body: body.GetText(), - }) -} - -//nolint:all -func (l *CustomQueryListener) ExitPredicate_declaration(_ *Predicate_declarationContext) { - if l.State.isInPredicateDeclaration { - l.State = State{ - isInPredicateDeclaration: false, - } - } -} - -func (l *CustomQueryListener) EnterEqualityExpression(ctx *EqualityExpressionContext) { - if ctx.GetChildCount() > 1 { - conditionText := ctx.GetText() - if !l.State.isInPredicateDeclaration { - l.condition = append(l.condition, conditionText) - } - } -} - -func (l *CustomQueryListener) EnterRelationalExpression(ctx *RelationalExpressionContext) { - if ctx.GetChildCount() > 1 { - conditionText := ctx.GetText() - if !l.State.isInPredicateDeclaration { - l.condition = append(l.condition, conditionText) - } - } -} - -func (l *CustomQueryListener) EnterExpression(ctx *ExpressionContext) { - if l.expression.Len() > 0 { - l.expression.WriteString(" ") - } - l.expression.WriteString(ctx.GetText()) -} - -func (l *CustomQueryListener) ExitOrExpression(ctx *OrExpressionContext) { - if ctx.GetChildCount() > 1 { - var result strings.Builder - for i := 0; i < ctx.GetChildCount(); i++ { - child := ctx.GetChild(i).(antlr.ParseTree) //nolint:all - if child.GetText() == "||" { - result.WriteString(" || ") - } else { - result.WriteString(child.GetText()) - } - } - l.expression.Reset() - l.expression.WriteString(result.String()) - } -} - -func (l *CustomQueryListener) ExitAndExpression(ctx *AndExpressionContext) { - if ctx.GetChildCount() > 1 { - var result strings.Builder - for i := 0; i < ctx.GetChildCount(); i++ { - child := ctx.GetChild(i).(antlr.ParseTree) //nolint:all - if child.GetText() == "&&" { - result.WriteString(" && ") - } else { - result.WriteString(child.GetText()) - } - } - l.expression.Reset() - l.expression.WriteString(result.String()) - } -} - -func (l *CustomQueryListener) extractArguments(arguments []string) []Parameter { - args := make([]Parameter, 0, len(arguments)) - for _, argument := range arguments { - exprType, err := l.inferExpressionType(argument) - if err != nil { - continue - } - args = append(args, exprType) - } - return args -} - -func (l *CustomQueryListener) inferExpressionType(argument string) (Parameter, error) { - argument = strings.TrimSpace(argument) - for _, entity := range l.selectList { - if strings.Contains(argument, entity.Alias) { - return Parameter{ - Name: entity.Alias, - Type: entity.Entity, - DefaultValue: "", - }, nil - } - } - return Parameter{}, fmt.Errorf("undefined entity: %s", argument) -} - -func (l *CustomQueryListener) matchPredicate(invokedPredicate PredicateInvocation) (Predicate, error) { - var candidates []Predicate - for _, pred := range l.Predicate { - if pred.PredicateName == invokedPredicate.PredicateName { - candidates = append(candidates, pred) - } - } - if len(candidates) == 0 { - return Predicate{}, fmt.Errorf("undefined predicate: %s", invokedPredicate.PredicateName) - } - - var matches []Predicate - for _, pred := range candidates { - if len(pred.Parameter) != len(invokedPredicate.Parameter) { - continue - } - - // Assume types are compatible unless type checking is required - compatible := true - for i := 0; i < len(pred.Parameter); i++ { - param := pred.Parameter[i] - argType := invokedPredicate.Parameter[i] - if param.Type != argType.Type { - compatible = false - break - } - } - - if compatible { - matches = append(matches, pred) - } - } - - if len(matches) == 0 { - return Predicate{}, fmt.Errorf("no matching predicate found for %s with given arguments", invokedPredicate.PredicateName) - } else if len(matches) > 1 { - // Handle ambiguity if overloading is supported - return Predicate{}, fmt.Errorf("ambiguous predicate invocation for %s", invokedPredicate.PredicateName) - } - - return matches[0], nil -} - -func ParseQuery(inputQuery string) (Query, error) { - inputStream := antlr.NewInputStream(inputQuery) - lexer := NewQueryLexer(inputStream) - stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) - p := NewQueryParser(stream) - - errorListener := &customErrorListener{} - p.RemoveErrorListeners() - p.AddErrorListener(errorListener) - - listener := NewCustomQueryListener() - tree := p.Query() - - if len(errorListener.errors) > 0 { - return Query{}, fmt.Errorf("\n%s", strings.Join(errorListener.errors, "\n")) - } - - antlr.ParseTreeWalkerDefault.Walk(listener, tree) - - return Query{ - Classes: listener.Classes, - SelectList: listener.selectList, - Expression: listener.expression.String(), - Condition: listener.condition, - Predicate: listener.Predicate, - PredicateInvocation: listener.PredicateInvocation, - SelectOutput: listener.SelectOutput, - }, nil -} diff --git a/sourcecode-parser/antlr/listener_impl_test.go b/sourcecode-parser/antlr/listener_impl_test.go deleted file mode 100644 index 4a3455cb..00000000 --- a/sourcecode-parser/antlr/listener_impl_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package parser - -import ( - "reflect" - "testing" -) - -func TestParseQuery(t *testing.T) { - tests := []struct { - name string - input string - expectedQuery Query - expectedSelect []SelectList - expectedExpr string - }{ - { - name: "Simple select with single entity", - input: "FROM class_declaration AS cd WHERE cd.GetName() == \"test\" SELECT cd", - expectedQuery: Query{ - SelectList: []SelectList{{Entity: "class_declaration", Alias: "cd"}}, - Expression: "cd.GetName()==\"test\"", - Condition: []string{"cd.GetName()==\"test\""}, - SelectOutput: []SelectOutput{ - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "cd", - Type: "variable", - }, - }, - }, - }, - { - name: "Select with multiple entities and aliases", - input: "FROM entity1 AS e1, entity2 AS e2 WHERE e1.GetName() == \"test\" SELECT e1.GetName()", - expectedQuery: Query{ - SelectList: []SelectList{ - {Entity: "entity1", Alias: "e1"}, - {Entity: "entity2", Alias: "e2"}, - }, - Expression: "e1.GetName()==\"test\"", - Condition: []string{"e1.GetName()==\"test\""}, - SelectOutput: []SelectOutput{ - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - }, - }, - }, - { - name: "Select with multiple entities and aliases", - input: "FROM entity1 AS e1, entity2 AS e2 WHERE e1.GetName() == \"test\" || e2.GetName() == \"test\" SELECT e1.GetName()", - expectedQuery: Query{ - SelectList: []SelectList{ - {Entity: "entity1", Alias: "e1"}, - {Entity: "entity2", Alias: "e2"}, - }, - Expression: "e1.GetName()==\"test\" || e2.GetName()==\"test\"", - Condition: []string{"e1.GetName()==\"test\"", "e2.GetName()==\"test\""}, - SelectOutput: []SelectOutput{ - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - }, - }, - }, - { - name: "Select with multiple entities and aliases", - input: "FROM entity1 AS e1, entity2 AS e2 WHERE e1.GetName() == \"test\" && e2.GetName() == \"test\" SELECT e1.GetName()", - expectedQuery: Query{ - SelectList: []SelectList{ - {Entity: "entity1", Alias: "e1"}, - {Entity: "entity2", Alias: "e2"}, - }, - Expression: "e1.GetName()==\"test\" && e2.GetName()==\"test\"", - Condition: []string{"e1.GetName()==\"test\"", "e2.GetName()==\"test\""}, - SelectOutput: []SelectOutput{ - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - { - SelectEntity: "e1.GetName()", - Type: "method_chain", - }, - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result, err := ParseQuery(tt.input) - if err != nil { - t.Errorf("ParseQuery() error = %v", err) - return - } - if !reflect.DeepEqual(result, tt.expectedQuery) { - t.Errorf("ParseQuery() = %v, want %v", result, tt.expectedQuery) - } - }) - } -} diff --git a/sourcecode-parser/antlr/query_base_listener.go b/sourcecode-parser/antlr/query_base_listener.go deleted file mode 100644 index e1e68b77..00000000 --- a/sourcecode-parser/antlr/query_base_listener.go +++ /dev/null @@ -1,274 +0,0 @@ -// Code generated from Query.g4 by ANTLR 4.13.2. DO NOT EDIT. - -package parser // Query - -import "github.com/antlr4-go/antlr/v4" - -// BaseQueryListener is a complete listener for a parse tree produced by QueryParser. -type BaseQueryListener struct{} - -var _ QueryListener = &BaseQueryListener{} - -// VisitTerminal is called when a terminal node is visited. -func (s *BaseQueryListener) VisitTerminal(node antlr.TerminalNode) {} - -// VisitErrorNode is called when an error node is visited. -func (s *BaseQueryListener) VisitErrorNode(node antlr.ErrorNode) {} - -// EnterEveryRule is called when any rule is entered. -func (s *BaseQueryListener) EnterEveryRule(ctx antlr.ParserRuleContext) {} - -// ExitEveryRule is called when any rule is exited. -func (s *BaseQueryListener) ExitEveryRule(ctx antlr.ParserRuleContext) {} - -// EnterQuery is called when production query is entered. -func (s *BaseQueryListener) EnterQuery(ctx *QueryContext) {} - -// ExitQuery is called when production query is exited. -func (s *BaseQueryListener) ExitQuery(ctx *QueryContext) {} - -// EnterClass_declarations is called when production class_declarations is entered. -func (s *BaseQueryListener) EnterClass_declarations(ctx *Class_declarationsContext) {} - -// ExitClass_declarations is called when production class_declarations is exited. -func (s *BaseQueryListener) ExitClass_declarations(ctx *Class_declarationsContext) {} - -// EnterClass_declaration is called when production class_declaration is entered. -func (s *BaseQueryListener) EnterClass_declaration(ctx *Class_declarationContext) {} - -// ExitClass_declaration is called when production class_declaration is exited. -func (s *BaseQueryListener) ExitClass_declaration(ctx *Class_declarationContext) {} - -// EnterClass_name is called when production class_name is entered. -func (s *BaseQueryListener) EnterClass_name(ctx *Class_nameContext) {} - -// ExitClass_name is called when production class_name is exited. -func (s *BaseQueryListener) ExitClass_name(ctx *Class_nameContext) {} - -// EnterMethod_declarations is called when production method_declarations is entered. -func (s *BaseQueryListener) EnterMethod_declarations(ctx *Method_declarationsContext) {} - -// ExitMethod_declarations is called when production method_declarations is exited. -func (s *BaseQueryListener) ExitMethod_declarations(ctx *Method_declarationsContext) {} - -// EnterMethod_declaration is called when production method_declaration is entered. -func (s *BaseQueryListener) EnterMethod_declaration(ctx *Method_declarationContext) {} - -// ExitMethod_declaration is called when production method_declaration is exited. -func (s *BaseQueryListener) ExitMethod_declaration(ctx *Method_declarationContext) {} - -// EnterMethod_name is called when production method_name is entered. -func (s *BaseQueryListener) EnterMethod_name(ctx *Method_nameContext) {} - -// ExitMethod_name is called when production method_name is exited. -func (s *BaseQueryListener) ExitMethod_name(ctx *Method_nameContext) {} - -// EnterMethod_body is called when production method_body is entered. -func (s *BaseQueryListener) EnterMethod_body(ctx *Method_bodyContext) {} - -// ExitMethod_body is called when production method_body is exited. -func (s *BaseQueryListener) ExitMethod_body(ctx *Method_bodyContext) {} - -// EnterReturn_statement is called when production return_statement is entered. -func (s *BaseQueryListener) EnterReturn_statement(ctx *Return_statementContext) {} - -// ExitReturn_statement is called when production return_statement is exited. -func (s *BaseQueryListener) ExitReturn_statement(ctx *Return_statementContext) {} - -// EnterReturn_type is called when production return_type is entered. -func (s *BaseQueryListener) EnterReturn_type(ctx *Return_typeContext) {} - -// ExitReturn_type is called when production return_type is exited. -func (s *BaseQueryListener) ExitReturn_type(ctx *Return_typeContext) {} - -// EnterPredicate_declarations is called when production predicate_declarations is entered. -func (s *BaseQueryListener) EnterPredicate_declarations(ctx *Predicate_declarationsContext) {} - -// ExitPredicate_declarations is called when production predicate_declarations is exited. -func (s *BaseQueryListener) ExitPredicate_declarations(ctx *Predicate_declarationsContext) {} - -// EnterPredicate_declaration is called when production predicate_declaration is entered. -func (s *BaseQueryListener) EnterPredicate_declaration(ctx *Predicate_declarationContext) {} - -// ExitPredicate_declaration is called when production predicate_declaration is exited. -func (s *BaseQueryListener) ExitPredicate_declaration(ctx *Predicate_declarationContext) {} - -// EnterPredicate_name is called when production predicate_name is entered. -func (s *BaseQueryListener) EnterPredicate_name(ctx *Predicate_nameContext) {} - -// ExitPredicate_name is called when production predicate_name is exited. -func (s *BaseQueryListener) ExitPredicate_name(ctx *Predicate_nameContext) {} - -// EnterParameter_list is called when production parameter_list is entered. -func (s *BaseQueryListener) EnterParameter_list(ctx *Parameter_listContext) {} - -// ExitParameter_list is called when production parameter_list is exited. -func (s *BaseQueryListener) ExitParameter_list(ctx *Parameter_listContext) {} - -// EnterParameter is called when production parameter is entered. -func (s *BaseQueryListener) EnterParameter(ctx *ParameterContext) {} - -// ExitParameter is called when production parameter is exited. -func (s *BaseQueryListener) ExitParameter(ctx *ParameterContext) {} - -// EnterType is called when production type is entered. -func (s *BaseQueryListener) EnterType(ctx *TypeContext) {} - -// ExitType is called when production type is exited. -func (s *BaseQueryListener) ExitType(ctx *TypeContext) {} - -// EnterSelect_list is called when production select_list is entered. -func (s *BaseQueryListener) EnterSelect_list(ctx *Select_listContext) {} - -// ExitSelect_list is called when production select_list is exited. -func (s *BaseQueryListener) ExitSelect_list(ctx *Select_listContext) {} - -// EnterSelect_item is called when production select_item is entered. -func (s *BaseQueryListener) EnterSelect_item(ctx *Select_itemContext) {} - -// ExitSelect_item is called when production select_item is exited. -func (s *BaseQueryListener) ExitSelect_item(ctx *Select_itemContext) {} - -// EnterEntity is called when production entity is entered. -func (s *BaseQueryListener) EnterEntity(ctx *EntityContext) {} - -// ExitEntity is called when production entity is exited. -func (s *BaseQueryListener) ExitEntity(ctx *EntityContext) {} - -// EnterAlias is called when production alias is entered. -func (s *BaseQueryListener) EnterAlias(ctx *AliasContext) {} - -// ExitAlias is called when production alias is exited. -func (s *BaseQueryListener) ExitAlias(ctx *AliasContext) {} - -// EnterExpression is called when production expression is entered. -func (s *BaseQueryListener) EnterExpression(ctx *ExpressionContext) {} - -// ExitExpression is called when production expression is exited. -func (s *BaseQueryListener) ExitExpression(ctx *ExpressionContext) {} - -// EnterOrExpression is called when production orExpression is entered. -func (s *BaseQueryListener) EnterOrExpression(ctx *OrExpressionContext) {} - -// ExitOrExpression is called when production orExpression is exited. -func (s *BaseQueryListener) ExitOrExpression(ctx *OrExpressionContext) {} - -// EnterAndExpression is called when production andExpression is entered. -func (s *BaseQueryListener) EnterAndExpression(ctx *AndExpressionContext) {} - -// ExitAndExpression is called when production andExpression is exited. -func (s *BaseQueryListener) ExitAndExpression(ctx *AndExpressionContext) {} - -// EnterEqualityExpression is called when production equalityExpression is entered. -func (s *BaseQueryListener) EnterEqualityExpression(ctx *EqualityExpressionContext) {} - -// ExitEqualityExpression is called when production equalityExpression is exited. -func (s *BaseQueryListener) ExitEqualityExpression(ctx *EqualityExpressionContext) {} - -// EnterRelationalExpression is called when production relationalExpression is entered. -func (s *BaseQueryListener) EnterRelationalExpression(ctx *RelationalExpressionContext) {} - -// ExitRelationalExpression is called when production relationalExpression is exited. -func (s *BaseQueryListener) ExitRelationalExpression(ctx *RelationalExpressionContext) {} - -// EnterAdditiveExpression is called when production additiveExpression is entered. -func (s *BaseQueryListener) EnterAdditiveExpression(ctx *AdditiveExpressionContext) {} - -// ExitAdditiveExpression is called when production additiveExpression is exited. -func (s *BaseQueryListener) ExitAdditiveExpression(ctx *AdditiveExpressionContext) {} - -// EnterMultiplicativeExpression is called when production multiplicativeExpression is entered. -func (s *BaseQueryListener) EnterMultiplicativeExpression(ctx *MultiplicativeExpressionContext) {} - -// ExitMultiplicativeExpression is called when production multiplicativeExpression is exited. -func (s *BaseQueryListener) ExitMultiplicativeExpression(ctx *MultiplicativeExpressionContext) {} - -// EnterUnaryExpression is called when production unaryExpression is entered. -func (s *BaseQueryListener) EnterUnaryExpression(ctx *UnaryExpressionContext) {} - -// ExitUnaryExpression is called when production unaryExpression is exited. -func (s *BaseQueryListener) ExitUnaryExpression(ctx *UnaryExpressionContext) {} - -// EnterPrimary is called when production primary is entered. -func (s *BaseQueryListener) EnterPrimary(ctx *PrimaryContext) {} - -// ExitPrimary is called when production primary is exited. -func (s *BaseQueryListener) ExitPrimary(ctx *PrimaryContext) {} - -// EnterOperand is called when production operand is entered. -func (s *BaseQueryListener) EnterOperand(ctx *OperandContext) {} - -// ExitOperand is called when production operand is exited. -func (s *BaseQueryListener) ExitOperand(ctx *OperandContext) {} - -// EnterMethod_chain is called when production method_chain is entered. -func (s *BaseQueryListener) EnterMethod_chain(ctx *Method_chainContext) {} - -// ExitMethod_chain is called when production method_chain is exited. -func (s *BaseQueryListener) ExitMethod_chain(ctx *Method_chainContext) {} - -// EnterMethod_or_variable is called when production method_or_variable is entered. -func (s *BaseQueryListener) EnterMethod_or_variable(ctx *Method_or_variableContext) {} - -// ExitMethod_or_variable is called when production method_or_variable is exited. -func (s *BaseQueryListener) ExitMethod_or_variable(ctx *Method_or_variableContext) {} - -// EnterMethod_invocation is called when production method_invocation is entered. -func (s *BaseQueryListener) EnterMethod_invocation(ctx *Method_invocationContext) {} - -// ExitMethod_invocation is called when production method_invocation is exited. -func (s *BaseQueryListener) ExitMethod_invocation(ctx *Method_invocationContext) {} - -// EnterVariable is called when production variable is entered. -func (s *BaseQueryListener) EnterVariable(ctx *VariableContext) {} - -// ExitVariable is called when production variable is exited. -func (s *BaseQueryListener) ExitVariable(ctx *VariableContext) {} - -// EnterPredicate_invocation is called when production predicate_invocation is entered. -func (s *BaseQueryListener) EnterPredicate_invocation(ctx *Predicate_invocationContext) {} - -// ExitPredicate_invocation is called when production predicate_invocation is exited. -func (s *BaseQueryListener) ExitPredicate_invocation(ctx *Predicate_invocationContext) {} - -// EnterArgument_list is called when production argument_list is entered. -func (s *BaseQueryListener) EnterArgument_list(ctx *Argument_listContext) {} - -// ExitArgument_list is called when production argument_list is exited. -func (s *BaseQueryListener) ExitArgument_list(ctx *Argument_listContext) {} - -// EnterArgument is called when production argument is entered. -func (s *BaseQueryListener) EnterArgument(ctx *ArgumentContext) {} - -// ExitArgument is called when production argument is exited. -func (s *BaseQueryListener) ExitArgument(ctx *ArgumentContext) {} - -// EnterComparator is called when production comparator is entered. -func (s *BaseQueryListener) EnterComparator(ctx *ComparatorContext) {} - -// ExitComparator is called when production comparator is exited. -func (s *BaseQueryListener) ExitComparator(ctx *ComparatorContext) {} - -// EnterValue is called when production value is entered. -func (s *BaseQueryListener) EnterValue(ctx *ValueContext) {} - -// ExitValue is called when production value is exited. -func (s *BaseQueryListener) ExitValue(ctx *ValueContext) {} - -// EnterValue_list is called when production value_list is entered. -func (s *BaseQueryListener) EnterValue_list(ctx *Value_listContext) {} - -// ExitValue_list is called when production value_list is exited. -func (s *BaseQueryListener) ExitValue_list(ctx *Value_listContext) {} - -// EnterSelect_clause is called when production select_clause is entered. -func (s *BaseQueryListener) EnterSelect_clause(ctx *Select_clauseContext) {} - -// ExitSelect_clause is called when production select_clause is exited. -func (s *BaseQueryListener) ExitSelect_clause(ctx *Select_clauseContext) {} - -// EnterSelect_expression is called when production select_expression is entered. -func (s *BaseQueryListener) EnterSelect_expression(ctx *Select_expressionContext) {} - -// ExitSelect_expression is called when production select_expression is exited. -func (s *BaseQueryListener) ExitSelect_expression(ctx *Select_expressionContext) {} diff --git a/sourcecode-parser/antlr/query_lexer.go b/sourcecode-parser/antlr/query_lexer.go deleted file mode 100644 index a94405bf..00000000 --- a/sourcecode-parser/antlr/query_lexer.go +++ /dev/null @@ -1,244 +0,0 @@ -// Code generated from Query.g4 by ANTLR 4.13.2. DO NOT EDIT. - -package parser - -import ( - "fmt" - "github.com/antlr4-go/antlr/v4" - "sync" - "unicode" -) - -// Suppress unused import error -var _ = fmt.Printf -var _ = sync.Once{} -var _ = unicode.IsLetter - -type QueryLexer struct { - *antlr.BaseLexer - channelNames []string - modeNames []string - // TODO: EOF string -} - -var QueryLexerLexerStaticData struct { - once sync.Once - serializedATN []int32 - ChannelNames []string - ModeNames []string - LiteralNames []string - SymbolicNames []string - RuleNames []string - PredictionContextCache *antlr.PredictionContextCache - atn *antlr.ATN - decisionToDFA []*antlr.DFA -} - -func querylexerLexerInit() { - staticData := &QueryLexerLexerStaticData - staticData.ChannelNames = []string{ - "DEFAULT_TOKEN_CHANNEL", "HIDDEN", - } - staticData.ModeNames = []string{ - "DEFAULT_MODE", - } - staticData.LiteralNames = []string{ - "", "'class'", "'{'", "'}'", "'('", "')'", "'result'", "'='", "','", - "'||'", "'&&'", "'=='", "'!='", "'<'", "'>'", "'<='", "'>='", "' in '", - "'+'", "'-'", "'*'", "'/'", "'!'", "'.'", "'['", "']'", "'LIKE'", "'in'", - "", "", "", "'predicate'", "'FROM'", "'WHERE'", "'AS'", "'SELECT'", - } - staticData.SymbolicNames = []string{ - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "STRING", "STRING_WITH_WILDCARD", - "NUMBER", "PREDICATE", "FROM", "WHERE", "AS", "SELECT", "IDENTIFIER", - "WS", - } - staticData.RuleNames = []string{ - "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", - "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", - "T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "T__23", "T__24", - "T__25", "T__26", "STRING", "STRING_WITH_WILDCARD", "NUMBER", "PREDICATE", - "FROM", "WHERE", "AS", "SELECT", "IDENTIFIER", "WS", - } - staticData.PredictionContextCache = antlr.NewPredictionContextCache() - staticData.serializedATN = []int32{ - 4, 0, 37, 232, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, - 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, - 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, - 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, - 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, - 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, - 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, - 7, 36, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, - 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, - 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, - 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 15, - 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, - 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 23, 1, 23, - 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, - 27, 1, 27, 1, 27, 1, 27, 5, 27, 156, 8, 27, 10, 27, 12, 27, 159, 9, 27, - 1, 27, 1, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 5, 28, 168, 8, 28, 10, - 28, 12, 28, 171, 9, 28, 1, 28, 1, 28, 1, 29, 4, 29, 176, 8, 29, 11, 29, - 12, 29, 177, 1, 29, 1, 29, 4, 29, 182, 8, 29, 11, 29, 12, 29, 183, 3, 29, - 186, 8, 29, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, 30, 1, - 30, 1, 30, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 32, 1, 32, 1, 32, 1, 32, - 1, 32, 1, 32, 1, 33, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, 1, 34, 1, 34, 1, - 34, 1, 34, 1, 35, 1, 35, 5, 35, 221, 8, 35, 10, 35, 12, 35, 224, 9, 35, - 1, 36, 4, 36, 227, 8, 36, 11, 36, 12, 36, 228, 1, 36, 1, 36, 0, 0, 37, - 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, - 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, - 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, - 59, 30, 61, 31, 63, 32, 65, 33, 67, 34, 69, 35, 71, 36, 73, 37, 1, 0, 5, - 2, 0, 34, 34, 92, 92, 1, 0, 48, 57, 3, 0, 65, 90, 95, 95, 97, 122, 4, 0, - 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 241, 0, 1, - 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, - 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, - 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, - 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, - 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, - 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, - 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, - 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, - 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 67, 1, 0, 0, 0, 0, 69, 1, 0, 0, 0, - 0, 71, 1, 0, 0, 0, 0, 73, 1, 0, 0, 0, 1, 75, 1, 0, 0, 0, 3, 81, 1, 0, 0, - 0, 5, 83, 1, 0, 0, 0, 7, 85, 1, 0, 0, 0, 9, 87, 1, 0, 0, 0, 11, 89, 1, - 0, 0, 0, 13, 96, 1, 0, 0, 0, 15, 98, 1, 0, 0, 0, 17, 100, 1, 0, 0, 0, 19, - 103, 1, 0, 0, 0, 21, 106, 1, 0, 0, 0, 23, 109, 1, 0, 0, 0, 25, 112, 1, - 0, 0, 0, 27, 114, 1, 0, 0, 0, 29, 116, 1, 0, 0, 0, 31, 119, 1, 0, 0, 0, - 33, 122, 1, 0, 0, 0, 35, 127, 1, 0, 0, 0, 37, 129, 1, 0, 0, 0, 39, 131, - 1, 0, 0, 0, 41, 133, 1, 0, 0, 0, 43, 135, 1, 0, 0, 0, 45, 137, 1, 0, 0, - 0, 47, 139, 1, 0, 0, 0, 49, 141, 1, 0, 0, 0, 51, 143, 1, 0, 0, 0, 53, 148, - 1, 0, 0, 0, 55, 151, 1, 0, 0, 0, 57, 162, 1, 0, 0, 0, 59, 175, 1, 0, 0, - 0, 61, 187, 1, 0, 0, 0, 63, 197, 1, 0, 0, 0, 65, 202, 1, 0, 0, 0, 67, 208, - 1, 0, 0, 0, 69, 211, 1, 0, 0, 0, 71, 218, 1, 0, 0, 0, 73, 226, 1, 0, 0, - 0, 75, 76, 5, 99, 0, 0, 76, 77, 5, 108, 0, 0, 77, 78, 5, 97, 0, 0, 78, - 79, 5, 115, 0, 0, 79, 80, 5, 115, 0, 0, 80, 2, 1, 0, 0, 0, 81, 82, 5, 123, - 0, 0, 82, 4, 1, 0, 0, 0, 83, 84, 5, 125, 0, 0, 84, 6, 1, 0, 0, 0, 85, 86, - 5, 40, 0, 0, 86, 8, 1, 0, 0, 0, 87, 88, 5, 41, 0, 0, 88, 10, 1, 0, 0, 0, - 89, 90, 5, 114, 0, 0, 90, 91, 5, 101, 0, 0, 91, 92, 5, 115, 0, 0, 92, 93, - 5, 117, 0, 0, 93, 94, 5, 108, 0, 0, 94, 95, 5, 116, 0, 0, 95, 12, 1, 0, - 0, 0, 96, 97, 5, 61, 0, 0, 97, 14, 1, 0, 0, 0, 98, 99, 5, 44, 0, 0, 99, - 16, 1, 0, 0, 0, 100, 101, 5, 124, 0, 0, 101, 102, 5, 124, 0, 0, 102, 18, - 1, 0, 0, 0, 103, 104, 5, 38, 0, 0, 104, 105, 5, 38, 0, 0, 105, 20, 1, 0, - 0, 0, 106, 107, 5, 61, 0, 0, 107, 108, 5, 61, 0, 0, 108, 22, 1, 0, 0, 0, - 109, 110, 5, 33, 0, 0, 110, 111, 5, 61, 0, 0, 111, 24, 1, 0, 0, 0, 112, - 113, 5, 60, 0, 0, 113, 26, 1, 0, 0, 0, 114, 115, 5, 62, 0, 0, 115, 28, - 1, 0, 0, 0, 116, 117, 5, 60, 0, 0, 117, 118, 5, 61, 0, 0, 118, 30, 1, 0, - 0, 0, 119, 120, 5, 62, 0, 0, 120, 121, 5, 61, 0, 0, 121, 32, 1, 0, 0, 0, - 122, 123, 5, 32, 0, 0, 123, 124, 5, 105, 0, 0, 124, 125, 5, 110, 0, 0, - 125, 126, 5, 32, 0, 0, 126, 34, 1, 0, 0, 0, 127, 128, 5, 43, 0, 0, 128, - 36, 1, 0, 0, 0, 129, 130, 5, 45, 0, 0, 130, 38, 1, 0, 0, 0, 131, 132, 5, - 42, 0, 0, 132, 40, 1, 0, 0, 0, 133, 134, 5, 47, 0, 0, 134, 42, 1, 0, 0, - 0, 135, 136, 5, 33, 0, 0, 136, 44, 1, 0, 0, 0, 137, 138, 5, 46, 0, 0, 138, - 46, 1, 0, 0, 0, 139, 140, 5, 91, 0, 0, 140, 48, 1, 0, 0, 0, 141, 142, 5, - 93, 0, 0, 142, 50, 1, 0, 0, 0, 143, 144, 5, 76, 0, 0, 144, 145, 5, 73, - 0, 0, 145, 146, 5, 75, 0, 0, 146, 147, 5, 69, 0, 0, 147, 52, 1, 0, 0, 0, - 148, 149, 5, 105, 0, 0, 149, 150, 5, 110, 0, 0, 150, 54, 1, 0, 0, 0, 151, - 157, 5, 34, 0, 0, 152, 156, 8, 0, 0, 0, 153, 154, 5, 92, 0, 0, 154, 156, - 9, 0, 0, 0, 155, 152, 1, 0, 0, 0, 155, 153, 1, 0, 0, 0, 156, 159, 1, 0, - 0, 0, 157, 155, 1, 0, 0, 0, 157, 158, 1, 0, 0, 0, 158, 160, 1, 0, 0, 0, - 159, 157, 1, 0, 0, 0, 160, 161, 5, 34, 0, 0, 161, 56, 1, 0, 0, 0, 162, - 169, 5, 34, 0, 0, 163, 168, 8, 0, 0, 0, 164, 165, 5, 92, 0, 0, 165, 168, - 9, 0, 0, 0, 166, 168, 5, 37, 0, 0, 167, 163, 1, 0, 0, 0, 167, 164, 1, 0, - 0, 0, 167, 166, 1, 0, 0, 0, 168, 171, 1, 0, 0, 0, 169, 167, 1, 0, 0, 0, - 169, 170, 1, 0, 0, 0, 170, 172, 1, 0, 0, 0, 171, 169, 1, 0, 0, 0, 172, - 173, 5, 34, 0, 0, 173, 58, 1, 0, 0, 0, 174, 176, 7, 1, 0, 0, 175, 174, - 1, 0, 0, 0, 176, 177, 1, 0, 0, 0, 177, 175, 1, 0, 0, 0, 177, 178, 1, 0, - 0, 0, 178, 185, 1, 0, 0, 0, 179, 181, 5, 46, 0, 0, 180, 182, 7, 1, 0, 0, - 181, 180, 1, 0, 0, 0, 182, 183, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 183, - 184, 1, 0, 0, 0, 184, 186, 1, 0, 0, 0, 185, 179, 1, 0, 0, 0, 185, 186, - 1, 0, 0, 0, 186, 60, 1, 0, 0, 0, 187, 188, 5, 112, 0, 0, 188, 189, 5, 114, - 0, 0, 189, 190, 5, 101, 0, 0, 190, 191, 5, 100, 0, 0, 191, 192, 5, 105, - 0, 0, 192, 193, 5, 99, 0, 0, 193, 194, 5, 97, 0, 0, 194, 195, 5, 116, 0, - 0, 195, 196, 5, 101, 0, 0, 196, 62, 1, 0, 0, 0, 197, 198, 5, 70, 0, 0, - 198, 199, 5, 82, 0, 0, 199, 200, 5, 79, 0, 0, 200, 201, 5, 77, 0, 0, 201, - 64, 1, 0, 0, 0, 202, 203, 5, 87, 0, 0, 203, 204, 5, 72, 0, 0, 204, 205, - 5, 69, 0, 0, 205, 206, 5, 82, 0, 0, 206, 207, 5, 69, 0, 0, 207, 66, 1, - 0, 0, 0, 208, 209, 5, 65, 0, 0, 209, 210, 5, 83, 0, 0, 210, 68, 1, 0, 0, - 0, 211, 212, 5, 83, 0, 0, 212, 213, 5, 69, 0, 0, 213, 214, 5, 76, 0, 0, - 214, 215, 5, 69, 0, 0, 215, 216, 5, 67, 0, 0, 216, 217, 5, 84, 0, 0, 217, - 70, 1, 0, 0, 0, 218, 222, 7, 2, 0, 0, 219, 221, 7, 3, 0, 0, 220, 219, 1, - 0, 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, - 0, 223, 72, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 225, 227, 7, 4, 0, 0, 226, - 225, 1, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 226, 1, 0, 0, 0, 228, 229, - 1, 0, 0, 0, 229, 230, 1, 0, 0, 0, 230, 231, 6, 36, 0, 0, 231, 74, 1, 0, - 0, 0, 10, 0, 155, 157, 167, 169, 177, 183, 185, 222, 228, 1, 6, 0, 0, - } - deserializer := antlr.NewATNDeserializer(nil) - staticData.atn = deserializer.Deserialize(staticData.serializedATN) - atn := staticData.atn - staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) - decisionToDFA := staticData.decisionToDFA - for index, state := range atn.DecisionToState { - decisionToDFA[index] = antlr.NewDFA(state, index) - } -} - -// QueryLexerInit initializes any static state used to implement QueryLexer. By default the -// static state used to implement the lexer is lazily initialized during the first call to -// NewQueryLexer(). You can call this function if you wish to initialize the static state ahead -// of time. -func QueryLexerInit() { - staticData := &QueryLexerLexerStaticData - staticData.once.Do(querylexerLexerInit) -} - -// NewQueryLexer produces a new lexer instance for the optional input antlr.CharStream. -func NewQueryLexer(input antlr.CharStream) *QueryLexer { - QueryLexerInit() - l := new(QueryLexer) - l.BaseLexer = antlr.NewBaseLexer(input) - staticData := &QueryLexerLexerStaticData - l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) - l.channelNames = staticData.ChannelNames - l.modeNames = staticData.ModeNames - l.RuleNames = staticData.RuleNames - l.LiteralNames = staticData.LiteralNames - l.SymbolicNames = staticData.SymbolicNames - l.GrammarFileName = "Query.g4" - // TODO: l.EOF = antlr.TokenEOF - - return l -} - -// QueryLexer tokens. -const ( - QueryLexerT__0 = 1 - QueryLexerT__1 = 2 - QueryLexerT__2 = 3 - QueryLexerT__3 = 4 - QueryLexerT__4 = 5 - QueryLexerT__5 = 6 - QueryLexerT__6 = 7 - QueryLexerT__7 = 8 - QueryLexerT__8 = 9 - QueryLexerT__9 = 10 - QueryLexerT__10 = 11 - QueryLexerT__11 = 12 - QueryLexerT__12 = 13 - QueryLexerT__13 = 14 - QueryLexerT__14 = 15 - QueryLexerT__15 = 16 - QueryLexerT__16 = 17 - QueryLexerT__17 = 18 - QueryLexerT__18 = 19 - QueryLexerT__19 = 20 - QueryLexerT__20 = 21 - QueryLexerT__21 = 22 - QueryLexerT__22 = 23 - QueryLexerT__23 = 24 - QueryLexerT__24 = 25 - QueryLexerT__25 = 26 - QueryLexerT__26 = 27 - QueryLexerSTRING = 28 - QueryLexerSTRING_WITH_WILDCARD = 29 - QueryLexerNUMBER = 30 - QueryLexerPREDICATE = 31 - QueryLexerFROM = 32 - QueryLexerWHERE = 33 - QueryLexerAS = 34 - QueryLexerSELECT = 35 - QueryLexerIDENTIFIER = 36 - QueryLexerWS = 37 -) diff --git a/sourcecode-parser/antlr/query_listener.go b/sourcecode-parser/antlr/query_listener.go deleted file mode 100644 index b5544471..00000000 --- a/sourcecode-parser/antlr/query_listener.go +++ /dev/null @@ -1,262 +0,0 @@ -// Code generated from Query.g4 by ANTLR 4.13.2. DO NOT EDIT. - -package parser // Query - -import "github.com/antlr4-go/antlr/v4" - -// QueryListener is a complete listener for a parse tree produced by QueryParser. -type QueryListener interface { - antlr.ParseTreeListener - - // EnterQuery is called when entering the query production. - EnterQuery(c *QueryContext) - - // EnterClass_declarations is called when entering the class_declarations production. - EnterClass_declarations(c *Class_declarationsContext) - - // EnterClass_declaration is called when entering the class_declaration production. - EnterClass_declaration(c *Class_declarationContext) - - // EnterClass_name is called when entering the class_name production. - EnterClass_name(c *Class_nameContext) - - // EnterMethod_declarations is called when entering the method_declarations production. - EnterMethod_declarations(c *Method_declarationsContext) - - // EnterMethod_declaration is called when entering the method_declaration production. - EnterMethod_declaration(c *Method_declarationContext) - - // EnterMethod_name is called when entering the method_name production. - EnterMethod_name(c *Method_nameContext) - - // EnterMethod_body is called when entering the method_body production. - EnterMethod_body(c *Method_bodyContext) - - // EnterReturn_statement is called when entering the return_statement production. - EnterReturn_statement(c *Return_statementContext) - - // EnterReturn_type is called when entering the return_type production. - EnterReturn_type(c *Return_typeContext) - - // EnterPredicate_declarations is called when entering the predicate_declarations production. - EnterPredicate_declarations(c *Predicate_declarationsContext) - - // EnterPredicate_declaration is called when entering the predicate_declaration production. - EnterPredicate_declaration(c *Predicate_declarationContext) - - // EnterPredicate_name is called when entering the predicate_name production. - EnterPredicate_name(c *Predicate_nameContext) - - // EnterParameter_list is called when entering the parameter_list production. - EnterParameter_list(c *Parameter_listContext) - - // EnterParameter is called when entering the parameter production. - EnterParameter(c *ParameterContext) - - // EnterType is called when entering the type production. - EnterType(c *TypeContext) - - // EnterSelect_list is called when entering the select_list production. - EnterSelect_list(c *Select_listContext) - - // EnterSelect_item is called when entering the select_item production. - EnterSelect_item(c *Select_itemContext) - - // EnterEntity is called when entering the entity production. - EnterEntity(c *EntityContext) - - // EnterAlias is called when entering the alias production. - EnterAlias(c *AliasContext) - - // EnterExpression is called when entering the expression production. - EnterExpression(c *ExpressionContext) - - // EnterOrExpression is called when entering the orExpression production. - EnterOrExpression(c *OrExpressionContext) - - // EnterAndExpression is called when entering the andExpression production. - EnterAndExpression(c *AndExpressionContext) - - // EnterEqualityExpression is called when entering the equalityExpression production. - EnterEqualityExpression(c *EqualityExpressionContext) - - // EnterRelationalExpression is called when entering the relationalExpression production. - EnterRelationalExpression(c *RelationalExpressionContext) - - // EnterAdditiveExpression is called when entering the additiveExpression production. - EnterAdditiveExpression(c *AdditiveExpressionContext) - - // EnterMultiplicativeExpression is called when entering the multiplicativeExpression production. - EnterMultiplicativeExpression(c *MultiplicativeExpressionContext) - - // EnterUnaryExpression is called when entering the unaryExpression production. - EnterUnaryExpression(c *UnaryExpressionContext) - - // EnterPrimary is called when entering the primary production. - EnterPrimary(c *PrimaryContext) - - // EnterOperand is called when entering the operand production. - EnterOperand(c *OperandContext) - - // EnterMethod_chain is called when entering the method_chain production. - EnterMethod_chain(c *Method_chainContext) - - // EnterMethod_or_variable is called when entering the method_or_variable production. - EnterMethod_or_variable(c *Method_or_variableContext) - - // EnterMethod_invocation is called when entering the method_invocation production. - EnterMethod_invocation(c *Method_invocationContext) - - // EnterVariable is called when entering the variable production. - EnterVariable(c *VariableContext) - - // EnterPredicate_invocation is called when entering the predicate_invocation production. - EnterPredicate_invocation(c *Predicate_invocationContext) - - // EnterArgument_list is called when entering the argument_list production. - EnterArgument_list(c *Argument_listContext) - - // EnterArgument is called when entering the argument production. - EnterArgument(c *ArgumentContext) - - // EnterComparator is called when entering the comparator production. - EnterComparator(c *ComparatorContext) - - // EnterValue is called when entering the value production. - EnterValue(c *ValueContext) - - // EnterValue_list is called when entering the value_list production. - EnterValue_list(c *Value_listContext) - - // EnterSelect_clause is called when entering the select_clause production. - EnterSelect_clause(c *Select_clauseContext) - - // EnterSelect_expression is called when entering the select_expression production. - EnterSelect_expression(c *Select_expressionContext) - - // ExitQuery is called when exiting the query production. - ExitQuery(c *QueryContext) - - // ExitClass_declarations is called when exiting the class_declarations production. - ExitClass_declarations(c *Class_declarationsContext) - - // ExitClass_declaration is called when exiting the class_declaration production. - ExitClass_declaration(c *Class_declarationContext) - - // ExitClass_name is called when exiting the class_name production. - ExitClass_name(c *Class_nameContext) - - // ExitMethod_declarations is called when exiting the method_declarations production. - ExitMethod_declarations(c *Method_declarationsContext) - - // ExitMethod_declaration is called when exiting the method_declaration production. - ExitMethod_declaration(c *Method_declarationContext) - - // ExitMethod_name is called when exiting the method_name production. - ExitMethod_name(c *Method_nameContext) - - // ExitMethod_body is called when exiting the method_body production. - ExitMethod_body(c *Method_bodyContext) - - // ExitReturn_statement is called when exiting the return_statement production. - ExitReturn_statement(c *Return_statementContext) - - // ExitReturn_type is called when exiting the return_type production. - ExitReturn_type(c *Return_typeContext) - - // ExitPredicate_declarations is called when exiting the predicate_declarations production. - ExitPredicate_declarations(c *Predicate_declarationsContext) - - // ExitPredicate_declaration is called when exiting the predicate_declaration production. - ExitPredicate_declaration(c *Predicate_declarationContext) - - // ExitPredicate_name is called when exiting the predicate_name production. - ExitPredicate_name(c *Predicate_nameContext) - - // ExitParameter_list is called when exiting the parameter_list production. - ExitParameter_list(c *Parameter_listContext) - - // ExitParameter is called when exiting the parameter production. - ExitParameter(c *ParameterContext) - - // ExitType is called when exiting the type production. - ExitType(c *TypeContext) - - // ExitSelect_list is called when exiting the select_list production. - ExitSelect_list(c *Select_listContext) - - // ExitSelect_item is called when exiting the select_item production. - ExitSelect_item(c *Select_itemContext) - - // ExitEntity is called when exiting the entity production. - ExitEntity(c *EntityContext) - - // ExitAlias is called when exiting the alias production. - ExitAlias(c *AliasContext) - - // ExitExpression is called when exiting the expression production. - ExitExpression(c *ExpressionContext) - - // ExitOrExpression is called when exiting the orExpression production. - ExitOrExpression(c *OrExpressionContext) - - // ExitAndExpression is called when exiting the andExpression production. - ExitAndExpression(c *AndExpressionContext) - - // ExitEqualityExpression is called when exiting the equalityExpression production. - ExitEqualityExpression(c *EqualityExpressionContext) - - // ExitRelationalExpression is called when exiting the relationalExpression production. - ExitRelationalExpression(c *RelationalExpressionContext) - - // ExitAdditiveExpression is called when exiting the additiveExpression production. - ExitAdditiveExpression(c *AdditiveExpressionContext) - - // ExitMultiplicativeExpression is called when exiting the multiplicativeExpression production. - ExitMultiplicativeExpression(c *MultiplicativeExpressionContext) - - // ExitUnaryExpression is called when exiting the unaryExpression production. - ExitUnaryExpression(c *UnaryExpressionContext) - - // ExitPrimary is called when exiting the primary production. - ExitPrimary(c *PrimaryContext) - - // ExitOperand is called when exiting the operand production. - ExitOperand(c *OperandContext) - - // ExitMethod_chain is called when exiting the method_chain production. - ExitMethod_chain(c *Method_chainContext) - - // ExitMethod_or_variable is called when exiting the method_or_variable production. - ExitMethod_or_variable(c *Method_or_variableContext) - - // ExitMethod_invocation is called when exiting the method_invocation production. - ExitMethod_invocation(c *Method_invocationContext) - - // ExitVariable is called when exiting the variable production. - ExitVariable(c *VariableContext) - - // ExitPredicate_invocation is called when exiting the predicate_invocation production. - ExitPredicate_invocation(c *Predicate_invocationContext) - - // ExitArgument_list is called when exiting the argument_list production. - ExitArgument_list(c *Argument_listContext) - - // ExitArgument is called when exiting the argument production. - ExitArgument(c *ArgumentContext) - - // ExitComparator is called when exiting the comparator production. - ExitComparator(c *ComparatorContext) - - // ExitValue is called when exiting the value production. - ExitValue(c *ValueContext) - - // ExitValue_list is called when exiting the value_list production. - ExitValue_list(c *Value_listContext) - - // ExitSelect_clause is called when exiting the select_clause production. - ExitSelect_clause(c *Select_clauseContext) - - // ExitSelect_expression is called when exiting the select_expression production. - ExitSelect_expression(c *Select_expressionContext) -} diff --git a/sourcecode-parser/antlr/query_parser.go b/sourcecode-parser/antlr/query_parser.go deleted file mode 100644 index 1c40cf0b..00000000 --- a/sourcecode-parser/antlr/query_parser.go +++ /dev/null @@ -1,6538 +0,0 @@ -// Code generated from Query.g4 by ANTLR 4.13.2. DO NOT EDIT. - -package parser // Query - -import ( - "fmt" - "strconv" - "sync" - - "github.com/antlr4-go/antlr/v4" -) - -// Suppress unused import errors -var _ = fmt.Printf -var _ = strconv.Itoa -var _ = sync.Once{} - -type QueryParser struct { - *antlr.BaseParser -} - -var QueryParserStaticData struct { - once sync.Once - serializedATN []int32 - LiteralNames []string - SymbolicNames []string - RuleNames []string - PredictionContextCache *antlr.PredictionContextCache - atn *antlr.ATN - decisionToDFA []*antlr.DFA -} - -func queryParserInit() { - staticData := &QueryParserStaticData - staticData.LiteralNames = []string{ - "", "'class'", "'{'", "'}'", "'('", "')'", "'result'", "'='", "','", - "'||'", "'&&'", "'=='", "'!='", "'<'", "'>'", "'<='", "'>='", "' in '", - "'+'", "'-'", "'*'", "'/'", "'!'", "'.'", "'['", "']'", "'LIKE'", "'in'", - "", "", "", "'predicate'", "'FROM'", "'WHERE'", "'AS'", "'SELECT'", - } - staticData.SymbolicNames = []string{ - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "STRING", "STRING_WITH_WILDCARD", - "NUMBER", "PREDICATE", "FROM", "WHERE", "AS", "SELECT", "IDENTIFIER", - "WS", - } - staticData.RuleNames = []string{ - "query", "class_declarations", "class_declaration", "class_name", "method_declarations", - "method_declaration", "method_name", "method_body", "return_statement", - "return_type", "predicate_declarations", "predicate_declaration", "predicate_name", - "parameter_list", "parameter", "type", "select_list", "select_item", - "entity", "alias", "expression", "orExpression", "andExpression", "equalityExpression", - "relationalExpression", "additiveExpression", "multiplicativeExpression", - "unaryExpression", "primary", "operand", "method_chain", "method_or_variable", - "method_invocation", "variable", "predicate_invocation", "argument_list", - "argument", "comparator", "value", "value_list", "select_clause", "select_expression", - } - staticData.PredictionContextCache = antlr.NewPredictionContextCache() - staticData.serializedATN = []int32{ - 4, 1, 37, 341, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, - 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, - 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, - 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, - 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, - 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, - 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, - 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 1, - 0, 3, 0, 86, 8, 0, 1, 0, 3, 0, 89, 8, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, - 95, 8, 0, 1, 0, 1, 0, 1, 0, 1, 1, 4, 1, 101, 8, 1, 11, 1, 12, 1, 102, 1, - 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 4, 4, 114, 8, 4, 11, - 4, 12, 4, 115, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 122, 8, 5, 1, 5, 1, 5, 1, - 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, - 9, 1, 10, 4, 10, 140, 8, 10, 11, 10, 12, 10, 141, 1, 11, 1, 11, 1, 11, - 1, 11, 3, 11, 148, 8, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, - 12, 1, 13, 1, 13, 1, 13, 5, 13, 160, 8, 13, 10, 13, 12, 13, 163, 9, 13, - 1, 14, 1, 14, 3, 14, 167, 8, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, - 16, 1, 16, 5, 16, 176, 8, 16, 10, 16, 12, 16, 179, 9, 16, 1, 17, 1, 17, - 3, 17, 183, 8, 17, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, - 20, 1, 20, 1, 21, 1, 21, 1, 21, 5, 21, 197, 8, 21, 10, 21, 12, 21, 200, - 9, 21, 1, 22, 1, 22, 1, 22, 5, 22, 205, 8, 22, 10, 22, 12, 22, 208, 9, - 22, 1, 23, 1, 23, 1, 23, 5, 23, 213, 8, 23, 10, 23, 12, 23, 216, 9, 23, - 1, 24, 1, 24, 1, 24, 5, 24, 221, 8, 24, 10, 24, 12, 24, 224, 9, 24, 1, - 25, 1, 25, 1, 25, 5, 25, 229, 8, 25, 10, 25, 12, 25, 232, 9, 25, 1, 26, - 1, 26, 1, 26, 5, 26, 237, 8, 26, 10, 26, 12, 26, 240, 9, 26, 1, 27, 1, - 27, 1, 27, 3, 27, 245, 8, 27, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, 1, 28, - 3, 28, 253, 8, 28, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, - 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 1, 29, 3, 29, 269, 8, 29, 1, 30, - 1, 30, 1, 30, 3, 30, 274, 8, 30, 1, 30, 1, 30, 1, 30, 3, 30, 279, 8, 30, - 1, 30, 1, 30, 1, 31, 1, 31, 1, 31, 3, 31, 286, 8, 31, 1, 32, 1, 32, 1, - 32, 3, 32, 291, 8, 32, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 1, 34, 1, 34, - 3, 34, 300, 8, 34, 1, 34, 1, 34, 1, 35, 1, 35, 1, 35, 5, 35, 307, 8, 35, - 10, 35, 12, 35, 310, 9, 35, 1, 36, 1, 36, 3, 36, 314, 8, 36, 1, 37, 1, - 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 39, 5, 39, 323, 8, 39, 10, 39, 12, 39, - 326, 9, 39, 1, 40, 1, 40, 1, 40, 5, 40, 331, 8, 40, 10, 40, 12, 40, 334, - 9, 40, 1, 41, 1, 41, 1, 41, 3, 41, 339, 8, 41, 1, 41, 0, 0, 42, 0, 2, 4, - 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, - 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, - 80, 82, 0, 7, 1, 0, 11, 12, 1, 0, 13, 17, 1, 0, 18, 19, 1, 0, 20, 21, 2, - 0, 19, 19, 22, 22, 2, 0, 11, 16, 26, 27, 1, 0, 28, 30, 335, 0, 85, 1, 0, - 0, 0, 2, 100, 1, 0, 0, 0, 4, 104, 1, 0, 0, 0, 6, 110, 1, 0, 0, 0, 8, 113, - 1, 0, 0, 0, 10, 117, 1, 0, 0, 0, 12, 128, 1, 0, 0, 0, 14, 130, 1, 0, 0, - 0, 16, 132, 1, 0, 0, 0, 18, 136, 1, 0, 0, 0, 20, 139, 1, 0, 0, 0, 22, 143, - 1, 0, 0, 0, 24, 154, 1, 0, 0, 0, 26, 156, 1, 0, 0, 0, 28, 166, 1, 0, 0, - 0, 30, 170, 1, 0, 0, 0, 32, 172, 1, 0, 0, 0, 34, 182, 1, 0, 0, 0, 36, 187, - 1, 0, 0, 0, 38, 189, 1, 0, 0, 0, 40, 191, 1, 0, 0, 0, 42, 193, 1, 0, 0, - 0, 44, 201, 1, 0, 0, 0, 46, 209, 1, 0, 0, 0, 48, 217, 1, 0, 0, 0, 50, 225, - 1, 0, 0, 0, 52, 233, 1, 0, 0, 0, 54, 244, 1, 0, 0, 0, 56, 252, 1, 0, 0, - 0, 58, 268, 1, 0, 0, 0, 60, 273, 1, 0, 0, 0, 62, 285, 1, 0, 0, 0, 64, 287, - 1, 0, 0, 0, 66, 294, 1, 0, 0, 0, 68, 296, 1, 0, 0, 0, 70, 303, 1, 0, 0, - 0, 72, 313, 1, 0, 0, 0, 74, 315, 1, 0, 0, 0, 76, 317, 1, 0, 0, 0, 78, 319, - 1, 0, 0, 0, 80, 327, 1, 0, 0, 0, 82, 338, 1, 0, 0, 0, 84, 86, 3, 2, 1, - 0, 85, 84, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 88, 1, 0, 0, 0, 87, 89, - 3, 20, 10, 0, 88, 87, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 90, 1, 0, 0, - 0, 90, 91, 5, 32, 0, 0, 91, 94, 3, 32, 16, 0, 92, 93, 5, 33, 0, 0, 93, - 95, 3, 40, 20, 0, 94, 92, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 96, 1, 0, - 0, 0, 96, 97, 5, 35, 0, 0, 97, 98, 3, 80, 40, 0, 98, 1, 1, 0, 0, 0, 99, - 101, 3, 4, 2, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1, - 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 3, 1, 0, 0, 0, 104, 105, 5, 1, 0, 0, - 105, 106, 3, 6, 3, 0, 106, 107, 5, 2, 0, 0, 107, 108, 3, 8, 4, 0, 108, - 109, 5, 3, 0, 0, 109, 5, 1, 0, 0, 0, 110, 111, 5, 36, 0, 0, 111, 7, 1, - 0, 0, 0, 112, 114, 3, 10, 5, 0, 113, 112, 1, 0, 0, 0, 114, 115, 1, 0, 0, - 0, 115, 113, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 9, 1, 0, 0, 0, 117, - 118, 3, 18, 9, 0, 118, 119, 3, 12, 6, 0, 119, 121, 5, 4, 0, 0, 120, 122, - 3, 26, 13, 0, 121, 120, 1, 0, 0, 0, 121, 122, 1, 0, 0, 0, 122, 123, 1, - 0, 0, 0, 123, 124, 5, 5, 0, 0, 124, 125, 5, 2, 0, 0, 125, 126, 3, 14, 7, - 0, 126, 127, 5, 3, 0, 0, 127, 11, 1, 0, 0, 0, 128, 129, 5, 36, 0, 0, 129, - 13, 1, 0, 0, 0, 130, 131, 3, 16, 8, 0, 131, 15, 1, 0, 0, 0, 132, 133, 5, - 6, 0, 0, 133, 134, 5, 7, 0, 0, 134, 135, 3, 76, 38, 0, 135, 17, 1, 0, 0, - 0, 136, 137, 3, 30, 15, 0, 137, 19, 1, 0, 0, 0, 138, 140, 3, 22, 11, 0, - 139, 138, 1, 0, 0, 0, 140, 141, 1, 0, 0, 0, 141, 139, 1, 0, 0, 0, 141, - 142, 1, 0, 0, 0, 142, 21, 1, 0, 0, 0, 143, 144, 5, 31, 0, 0, 144, 145, - 3, 24, 12, 0, 145, 147, 5, 4, 0, 0, 146, 148, 3, 26, 13, 0, 147, 146, 1, - 0, 0, 0, 147, 148, 1, 0, 0, 0, 148, 149, 1, 0, 0, 0, 149, 150, 5, 5, 0, - 0, 150, 151, 5, 2, 0, 0, 151, 152, 3, 40, 20, 0, 152, 153, 5, 3, 0, 0, - 153, 23, 1, 0, 0, 0, 154, 155, 5, 36, 0, 0, 155, 25, 1, 0, 0, 0, 156, 161, - 3, 28, 14, 0, 157, 158, 5, 8, 0, 0, 158, 160, 3, 28, 14, 0, 159, 157, 1, - 0, 0, 0, 160, 163, 1, 0, 0, 0, 161, 159, 1, 0, 0, 0, 161, 162, 1, 0, 0, - 0, 162, 27, 1, 0, 0, 0, 163, 161, 1, 0, 0, 0, 164, 167, 3, 30, 15, 0, 165, - 167, 3, 6, 3, 0, 166, 164, 1, 0, 0, 0, 166, 165, 1, 0, 0, 0, 167, 168, - 1, 0, 0, 0, 168, 169, 5, 36, 0, 0, 169, 29, 1, 0, 0, 0, 170, 171, 5, 36, - 0, 0, 171, 31, 1, 0, 0, 0, 172, 177, 3, 34, 17, 0, 173, 174, 5, 8, 0, 0, - 174, 176, 3, 34, 17, 0, 175, 173, 1, 0, 0, 0, 176, 179, 1, 0, 0, 0, 177, - 175, 1, 0, 0, 0, 177, 178, 1, 0, 0, 0, 178, 33, 1, 0, 0, 0, 179, 177, 1, - 0, 0, 0, 180, 183, 3, 36, 18, 0, 181, 183, 3, 6, 3, 0, 182, 180, 1, 0, - 0, 0, 182, 181, 1, 0, 0, 0, 183, 184, 1, 0, 0, 0, 184, 185, 5, 34, 0, 0, - 185, 186, 3, 38, 19, 0, 186, 35, 1, 0, 0, 0, 187, 188, 5, 36, 0, 0, 188, - 37, 1, 0, 0, 0, 189, 190, 5, 36, 0, 0, 190, 39, 1, 0, 0, 0, 191, 192, 3, - 42, 21, 0, 192, 41, 1, 0, 0, 0, 193, 198, 3, 44, 22, 0, 194, 195, 5, 9, - 0, 0, 195, 197, 3, 44, 22, 0, 196, 194, 1, 0, 0, 0, 197, 200, 1, 0, 0, - 0, 198, 196, 1, 0, 0, 0, 198, 199, 1, 0, 0, 0, 199, 43, 1, 0, 0, 0, 200, - 198, 1, 0, 0, 0, 201, 206, 3, 46, 23, 0, 202, 203, 5, 10, 0, 0, 203, 205, - 3, 46, 23, 0, 204, 202, 1, 0, 0, 0, 205, 208, 1, 0, 0, 0, 206, 204, 1, - 0, 0, 0, 206, 207, 1, 0, 0, 0, 207, 45, 1, 0, 0, 0, 208, 206, 1, 0, 0, - 0, 209, 214, 3, 48, 24, 0, 210, 211, 7, 0, 0, 0, 211, 213, 3, 48, 24, 0, - 212, 210, 1, 0, 0, 0, 213, 216, 1, 0, 0, 0, 214, 212, 1, 0, 0, 0, 214, - 215, 1, 0, 0, 0, 215, 47, 1, 0, 0, 0, 216, 214, 1, 0, 0, 0, 217, 222, 3, - 50, 25, 0, 218, 219, 7, 1, 0, 0, 219, 221, 3, 50, 25, 0, 220, 218, 1, 0, - 0, 0, 221, 224, 1, 0, 0, 0, 222, 220, 1, 0, 0, 0, 222, 223, 1, 0, 0, 0, - 223, 49, 1, 0, 0, 0, 224, 222, 1, 0, 0, 0, 225, 230, 3, 52, 26, 0, 226, - 227, 7, 2, 0, 0, 227, 229, 3, 52, 26, 0, 228, 226, 1, 0, 0, 0, 229, 232, - 1, 0, 0, 0, 230, 228, 1, 0, 0, 0, 230, 231, 1, 0, 0, 0, 231, 51, 1, 0, - 0, 0, 232, 230, 1, 0, 0, 0, 233, 238, 3, 54, 27, 0, 234, 235, 7, 3, 0, - 0, 235, 237, 3, 54, 27, 0, 236, 234, 1, 0, 0, 0, 237, 240, 1, 0, 0, 0, - 238, 236, 1, 0, 0, 0, 238, 239, 1, 0, 0, 0, 239, 53, 1, 0, 0, 0, 240, 238, - 1, 0, 0, 0, 241, 242, 7, 4, 0, 0, 242, 245, 3, 54, 27, 0, 243, 245, 3, - 56, 28, 0, 244, 241, 1, 0, 0, 0, 244, 243, 1, 0, 0, 0, 245, 55, 1, 0, 0, - 0, 246, 253, 3, 58, 29, 0, 247, 253, 3, 68, 34, 0, 248, 249, 5, 4, 0, 0, - 249, 250, 3, 40, 20, 0, 250, 251, 5, 5, 0, 0, 251, 253, 1, 0, 0, 0, 252, - 246, 1, 0, 0, 0, 252, 247, 1, 0, 0, 0, 252, 248, 1, 0, 0, 0, 253, 57, 1, - 0, 0, 0, 254, 269, 3, 76, 38, 0, 255, 269, 3, 66, 33, 0, 256, 257, 3, 38, - 19, 0, 257, 258, 5, 23, 0, 0, 258, 259, 3, 60, 30, 0, 259, 269, 1, 0, 0, - 0, 260, 261, 3, 6, 3, 0, 261, 262, 5, 23, 0, 0, 262, 263, 3, 60, 30, 0, - 263, 269, 1, 0, 0, 0, 264, 265, 5, 24, 0, 0, 265, 266, 3, 78, 39, 0, 266, - 267, 5, 25, 0, 0, 267, 269, 1, 0, 0, 0, 268, 254, 1, 0, 0, 0, 268, 255, - 1, 0, 0, 0, 268, 256, 1, 0, 0, 0, 268, 260, 1, 0, 0, 0, 268, 264, 1, 0, - 0, 0, 269, 59, 1, 0, 0, 0, 270, 271, 3, 6, 3, 0, 271, 272, 5, 23, 0, 0, - 272, 274, 1, 0, 0, 0, 273, 270, 1, 0, 0, 0, 273, 274, 1, 0, 0, 0, 274, - 275, 1, 0, 0, 0, 275, 276, 3, 12, 6, 0, 276, 278, 5, 4, 0, 0, 277, 279, - 3, 70, 35, 0, 278, 277, 1, 0, 0, 0, 278, 279, 1, 0, 0, 0, 279, 280, 1, - 0, 0, 0, 280, 281, 5, 5, 0, 0, 281, 61, 1, 0, 0, 0, 282, 286, 3, 64, 32, - 0, 283, 286, 3, 66, 33, 0, 284, 286, 3, 68, 34, 0, 285, 282, 1, 0, 0, 0, - 285, 283, 1, 0, 0, 0, 285, 284, 1, 0, 0, 0, 286, 63, 1, 0, 0, 0, 287, 288, - 5, 36, 0, 0, 288, 290, 5, 4, 0, 0, 289, 291, 3, 70, 35, 0, 290, 289, 1, - 0, 0, 0, 290, 291, 1, 0, 0, 0, 291, 292, 1, 0, 0, 0, 292, 293, 5, 5, 0, - 0, 293, 65, 1, 0, 0, 0, 294, 295, 5, 36, 0, 0, 295, 67, 1, 0, 0, 0, 296, - 297, 3, 24, 12, 0, 297, 299, 5, 4, 0, 0, 298, 300, 3, 70, 35, 0, 299, 298, - 1, 0, 0, 0, 299, 300, 1, 0, 0, 0, 300, 301, 1, 0, 0, 0, 301, 302, 5, 5, - 0, 0, 302, 69, 1, 0, 0, 0, 303, 308, 3, 72, 36, 0, 304, 305, 5, 8, 0, 0, - 305, 307, 3, 72, 36, 0, 306, 304, 1, 0, 0, 0, 307, 310, 1, 0, 0, 0, 308, - 306, 1, 0, 0, 0, 308, 309, 1, 0, 0, 0, 309, 71, 1, 0, 0, 0, 310, 308, 1, - 0, 0, 0, 311, 314, 3, 40, 20, 0, 312, 314, 5, 28, 0, 0, 313, 311, 1, 0, - 0, 0, 313, 312, 1, 0, 0, 0, 314, 73, 1, 0, 0, 0, 315, 316, 7, 5, 0, 0, - 316, 75, 1, 0, 0, 0, 317, 318, 7, 6, 0, 0, 318, 77, 1, 0, 0, 0, 319, 324, - 3, 76, 38, 0, 320, 321, 5, 8, 0, 0, 321, 323, 3, 76, 38, 0, 322, 320, 1, - 0, 0, 0, 323, 326, 1, 0, 0, 0, 324, 322, 1, 0, 0, 0, 324, 325, 1, 0, 0, - 0, 325, 79, 1, 0, 0, 0, 326, 324, 1, 0, 0, 0, 327, 332, 3, 82, 41, 0, 328, - 329, 5, 8, 0, 0, 329, 331, 3, 82, 41, 0, 330, 328, 1, 0, 0, 0, 331, 334, - 1, 0, 0, 0, 332, 330, 1, 0, 0, 0, 332, 333, 1, 0, 0, 0, 333, 81, 1, 0, - 0, 0, 334, 332, 1, 0, 0, 0, 335, 339, 3, 66, 33, 0, 336, 339, 3, 60, 30, - 0, 337, 339, 5, 28, 0, 0, 338, 335, 1, 0, 0, 0, 338, 336, 1, 0, 0, 0, 338, - 337, 1, 0, 0, 0, 339, 83, 1, 0, 0, 0, 31, 85, 88, 94, 102, 115, 121, 141, - 147, 161, 166, 177, 182, 198, 206, 214, 222, 230, 238, 244, 252, 268, 273, - 278, 285, 290, 299, 308, 313, 324, 332, 338, - } - deserializer := antlr.NewATNDeserializer(nil) - staticData.atn = deserializer.Deserialize(staticData.serializedATN) - atn := staticData.atn - staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState)) - decisionToDFA := staticData.decisionToDFA - for index, state := range atn.DecisionToState { - decisionToDFA[index] = antlr.NewDFA(state, index) - } -} - -// QueryParserInit initializes any static state used to implement QueryParser. By default the -// static state used to implement the parser is lazily initialized during the first call to -// NewQueryParser(). You can call this function if you wish to initialize the static state ahead -// of time. -func QueryParserInit() { - staticData := &QueryParserStaticData - staticData.once.Do(queryParserInit) -} - -// NewQueryParser produces a new parser instance for the optional input antlr.TokenStream. -func NewQueryParser(input antlr.TokenStream) *QueryParser { - QueryParserInit() - this := new(QueryParser) - this.BaseParser = antlr.NewBaseParser(input) - staticData := &QueryParserStaticData - this.Interpreter = antlr.NewParserATNSimulator(this, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache) - this.RuleNames = staticData.RuleNames - this.LiteralNames = staticData.LiteralNames - this.SymbolicNames = staticData.SymbolicNames - this.GrammarFileName = "Query.g4" - - return this -} - -// QueryParser tokens. -const ( - QueryParserEOF = antlr.TokenEOF - QueryParserT__0 = 1 - QueryParserT__1 = 2 - QueryParserT__2 = 3 - QueryParserT__3 = 4 - QueryParserT__4 = 5 - QueryParserT__5 = 6 - QueryParserT__6 = 7 - QueryParserT__7 = 8 - QueryParserT__8 = 9 - QueryParserT__9 = 10 - QueryParserT__10 = 11 - QueryParserT__11 = 12 - QueryParserT__12 = 13 - QueryParserT__13 = 14 - QueryParserT__14 = 15 - QueryParserT__15 = 16 - QueryParserT__16 = 17 - QueryParserT__17 = 18 - QueryParserT__18 = 19 - QueryParserT__19 = 20 - QueryParserT__20 = 21 - QueryParserT__21 = 22 - QueryParserT__22 = 23 - QueryParserT__23 = 24 - QueryParserT__24 = 25 - QueryParserT__25 = 26 - QueryParserT__26 = 27 - QueryParserSTRING = 28 - QueryParserSTRING_WITH_WILDCARD = 29 - QueryParserNUMBER = 30 - QueryParserPREDICATE = 31 - QueryParserFROM = 32 - QueryParserWHERE = 33 - QueryParserAS = 34 - QueryParserSELECT = 35 - QueryParserIDENTIFIER = 36 - QueryParserWS = 37 -) - -// QueryParser rules. -const ( - QueryParserRULE_query = 0 - QueryParserRULE_class_declarations = 1 - QueryParserRULE_class_declaration = 2 - QueryParserRULE_class_name = 3 - QueryParserRULE_method_declarations = 4 - QueryParserRULE_method_declaration = 5 - QueryParserRULE_method_name = 6 - QueryParserRULE_method_body = 7 - QueryParserRULE_return_statement = 8 - QueryParserRULE_return_type = 9 - QueryParserRULE_predicate_declarations = 10 - QueryParserRULE_predicate_declaration = 11 - QueryParserRULE_predicate_name = 12 - QueryParserRULE_parameter_list = 13 - QueryParserRULE_parameter = 14 - QueryParserRULE_type = 15 - QueryParserRULE_select_list = 16 - QueryParserRULE_select_item = 17 - QueryParserRULE_entity = 18 - QueryParserRULE_alias = 19 - QueryParserRULE_expression = 20 - QueryParserRULE_orExpression = 21 - QueryParserRULE_andExpression = 22 - QueryParserRULE_equalityExpression = 23 - QueryParserRULE_relationalExpression = 24 - QueryParserRULE_additiveExpression = 25 - QueryParserRULE_multiplicativeExpression = 26 - QueryParserRULE_unaryExpression = 27 - QueryParserRULE_primary = 28 - QueryParserRULE_operand = 29 - QueryParserRULE_method_chain = 30 - QueryParserRULE_method_or_variable = 31 - QueryParserRULE_method_invocation = 32 - QueryParserRULE_variable = 33 - QueryParserRULE_predicate_invocation = 34 - QueryParserRULE_argument_list = 35 - QueryParserRULE_argument = 36 - QueryParserRULE_comparator = 37 - QueryParserRULE_value = 38 - QueryParserRULE_value_list = 39 - QueryParserRULE_select_clause = 40 - QueryParserRULE_select_expression = 41 -) - -// IQueryContext is an interface to support dynamic dispatch. -type IQueryContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - FROM() antlr.TerminalNode - Select_list() ISelect_listContext - SELECT() antlr.TerminalNode - Select_clause() ISelect_clauseContext - Class_declarations() IClass_declarationsContext - Predicate_declarations() IPredicate_declarationsContext - WHERE() antlr.TerminalNode - Expression() IExpressionContext - - // IsQueryContext differentiates from other interfaces. - IsQueryContext() -} - -type QueryContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyQueryContext() *QueryContext { - var p = new(QueryContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_query - return p -} - -func InitEmptyQueryContext(p *QueryContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_query -} - -func (*QueryContext) IsQueryContext() {} - -func NewQueryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *QueryContext { - var p = new(QueryContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_query - - return p -} - -func (s *QueryContext) GetParser() antlr.Parser { return s.parser } - -func (s *QueryContext) FROM() antlr.TerminalNode { - return s.GetToken(QueryParserFROM, 0) -} - -func (s *QueryContext) Select_list() ISelect_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ISelect_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(ISelect_listContext) -} - -func (s *QueryContext) SELECT() antlr.TerminalNode { - return s.GetToken(QueryParserSELECT, 0) -} - -func (s *QueryContext) Select_clause() ISelect_clauseContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ISelect_clauseContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(ISelect_clauseContext) -} - -func (s *QueryContext) Class_declarations() IClass_declarationsContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_declarationsContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_declarationsContext) -} - -func (s *QueryContext) Predicate_declarations() IPredicate_declarationsContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_declarationsContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_declarationsContext) -} - -func (s *QueryContext) WHERE() antlr.TerminalNode { - return s.GetToken(QueryParserWHERE, 0) -} - -func (s *QueryContext) Expression() IExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IExpressionContext) -} - -func (s *QueryContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *QueryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *QueryContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterQuery(s) - } -} - -func (s *QueryContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitQuery(s) - } -} - -func (p *QueryParser) Query() (localctx IQueryContext) { - localctx = NewQueryContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 0, QueryParserRULE_query) - var _la int - - p.EnterOuterAlt(localctx, 1) - p.SetState(85) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if _la == QueryParserT__0 { - { - p.SetState(84) - p.Class_declarations() - } - - } - p.SetState(88) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if _la == QueryParserPREDICATE { - { - p.SetState(87) - p.Predicate_declarations() - } - - } - { - p.SetState(90) - p.Match(QueryParserFROM) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(91) - p.Select_list() - } - p.SetState(94) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if _la == QueryParserWHERE { - { - p.SetState(92) - p.Match(QueryParserWHERE) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(93) - p.Expression() - } - - } - { - p.SetState(96) - p.Match(QueryParserSELECT) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(97) - p.Select_clause() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IClass_declarationsContext is an interface to support dynamic dispatch. -type IClass_declarationsContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllClass_declaration() []IClass_declarationContext - Class_declaration(i int) IClass_declarationContext - - // IsClass_declarationsContext differentiates from other interfaces. - IsClass_declarationsContext() -} - -type Class_declarationsContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyClass_declarationsContext() *Class_declarationsContext { - var p = new(Class_declarationsContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_declarations - return p -} - -func InitEmptyClass_declarationsContext(p *Class_declarationsContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_declarations -} - -func (*Class_declarationsContext) IsClass_declarationsContext() {} - -func NewClass_declarationsContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Class_declarationsContext { - var p = new(Class_declarationsContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_class_declarations - - return p -} - -func (s *Class_declarationsContext) GetParser() antlr.Parser { return s.parser } - -func (s *Class_declarationsContext) AllClass_declaration() []IClass_declarationContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IClass_declarationContext); ok { - len++ - } - } - - tst := make([]IClass_declarationContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IClass_declarationContext); ok { - tst[i] = t.(IClass_declarationContext) - i++ - } - } - - return tst -} - -func (s *Class_declarationsContext) Class_declaration(i int) IClass_declarationContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_declarationContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IClass_declarationContext) -} - -func (s *Class_declarationsContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Class_declarationsContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Class_declarationsContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterClass_declarations(s) - } -} - -func (s *Class_declarationsContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitClass_declarations(s) - } -} - -func (p *QueryParser) Class_declarations() (localctx IClass_declarationsContext) { - localctx = NewClass_declarationsContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 2, QueryParserRULE_class_declarations) - var _la int - - p.EnterOuterAlt(localctx, 1) - p.SetState(100) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for ok := true; ok; ok = _la == QueryParserT__0 { - { - p.SetState(99) - p.Class_declaration() - } - - p.SetState(102) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IClass_declarationContext is an interface to support dynamic dispatch. -type IClass_declarationContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Class_name() IClass_nameContext - Method_declarations() IMethod_declarationsContext - - // IsClass_declarationContext differentiates from other interfaces. - IsClass_declarationContext() -} - -type Class_declarationContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyClass_declarationContext() *Class_declarationContext { - var p = new(Class_declarationContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_declaration - return p -} - -func InitEmptyClass_declarationContext(p *Class_declarationContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_declaration -} - -func (*Class_declarationContext) IsClass_declarationContext() {} - -func NewClass_declarationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Class_declarationContext { - var p = new(Class_declarationContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_class_declaration - - return p -} - -func (s *Class_declarationContext) GetParser() antlr.Parser { return s.parser } - -func (s *Class_declarationContext) Class_name() IClass_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_nameContext) -} - -func (s *Class_declarationContext) Method_declarations() IMethod_declarationsContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_declarationsContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_declarationsContext) -} - -func (s *Class_declarationContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Class_declarationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Class_declarationContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterClass_declaration(s) - } -} - -func (s *Class_declarationContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitClass_declaration(s) - } -} - -func (p *QueryParser) Class_declaration() (localctx IClass_declarationContext) { - localctx = NewClass_declarationContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 4, QueryParserRULE_class_declaration) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(104) - p.Match(QueryParserT__0) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(105) - p.Class_name() - } - { - p.SetState(106) - p.Match(QueryParserT__1) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(107) - p.Method_declarations() - } - { - p.SetState(108) - p.Match(QueryParserT__2) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IClass_nameContext is an interface to support dynamic dispatch. -type IClass_nameContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsClass_nameContext differentiates from other interfaces. - IsClass_nameContext() -} - -type Class_nameContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyClass_nameContext() *Class_nameContext { - var p = new(Class_nameContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_name - return p -} - -func InitEmptyClass_nameContext(p *Class_nameContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_class_name -} - -func (*Class_nameContext) IsClass_nameContext() {} - -func NewClass_nameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Class_nameContext { - var p = new(Class_nameContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_class_name - - return p -} - -func (s *Class_nameContext) GetParser() antlr.Parser { return s.parser } - -func (s *Class_nameContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *Class_nameContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Class_nameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Class_nameContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterClass_name(s) - } -} - -func (s *Class_nameContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitClass_name(s) - } -} - -func (p *QueryParser) Class_name() (localctx IClass_nameContext) { - localctx = NewClass_nameContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 6, QueryParserRULE_class_name) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(110) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_declarationsContext is an interface to support dynamic dispatch. -type IMethod_declarationsContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllMethod_declaration() []IMethod_declarationContext - Method_declaration(i int) IMethod_declarationContext - - // IsMethod_declarationsContext differentiates from other interfaces. - IsMethod_declarationsContext() -} - -type Method_declarationsContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_declarationsContext() *Method_declarationsContext { - var p = new(Method_declarationsContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_declarations - return p -} - -func InitEmptyMethod_declarationsContext(p *Method_declarationsContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_declarations -} - -func (*Method_declarationsContext) IsMethod_declarationsContext() {} - -func NewMethod_declarationsContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_declarationsContext { - var p = new(Method_declarationsContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_declarations - - return p -} - -func (s *Method_declarationsContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_declarationsContext) AllMethod_declaration() []IMethod_declarationContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IMethod_declarationContext); ok { - len++ - } - } - - tst := make([]IMethod_declarationContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IMethod_declarationContext); ok { - tst[i] = t.(IMethod_declarationContext) - i++ - } - } - - return tst -} - -func (s *Method_declarationsContext) Method_declaration(i int) IMethod_declarationContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_declarationContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IMethod_declarationContext) -} - -func (s *Method_declarationsContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_declarationsContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_declarationsContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_declarations(s) - } -} - -func (s *Method_declarationsContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_declarations(s) - } -} - -func (p *QueryParser) Method_declarations() (localctx IMethod_declarationsContext) { - localctx = NewMethod_declarationsContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 8, QueryParserRULE_method_declarations) - var _la int - - p.EnterOuterAlt(localctx, 1) - p.SetState(113) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for ok := true; ok; ok = _la == QueryParserIDENTIFIER { - { - p.SetState(112) - p.Method_declaration() - } - - p.SetState(115) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_declarationContext is an interface to support dynamic dispatch. -type IMethod_declarationContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Return_type() IReturn_typeContext - Method_name() IMethod_nameContext - Method_body() IMethod_bodyContext - Parameter_list() IParameter_listContext - - // IsMethod_declarationContext differentiates from other interfaces. - IsMethod_declarationContext() -} - -type Method_declarationContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_declarationContext() *Method_declarationContext { - var p = new(Method_declarationContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_declaration - return p -} - -func InitEmptyMethod_declarationContext(p *Method_declarationContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_declaration -} - -func (*Method_declarationContext) IsMethod_declarationContext() {} - -func NewMethod_declarationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_declarationContext { - var p = new(Method_declarationContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_declaration - - return p -} - -func (s *Method_declarationContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_declarationContext) Return_type() IReturn_typeContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IReturn_typeContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IReturn_typeContext) -} - -func (s *Method_declarationContext) Method_name() IMethod_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_nameContext) -} - -func (s *Method_declarationContext) Method_body() IMethod_bodyContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_bodyContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_bodyContext) -} - -func (s *Method_declarationContext) Parameter_list() IParameter_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IParameter_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IParameter_listContext) -} - -func (s *Method_declarationContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_declarationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_declarationContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_declaration(s) - } -} - -func (s *Method_declarationContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_declaration(s) - } -} - -func (p *QueryParser) Method_declaration() (localctx IMethod_declarationContext) { - localctx = NewMethod_declarationContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 10, QueryParserRULE_method_declaration) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(117) - p.Return_type() - } - { - p.SetState(118) - p.Method_name() - } - { - p.SetState(119) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - p.SetState(121) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if _la == QueryParserIDENTIFIER { - { - p.SetState(120) - p.Parameter_list() - } - - } - { - p.SetState(123) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(124) - p.Match(QueryParserT__1) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(125) - p.Method_body() - } - { - p.SetState(126) - p.Match(QueryParserT__2) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_nameContext is an interface to support dynamic dispatch. -type IMethod_nameContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsMethod_nameContext differentiates from other interfaces. - IsMethod_nameContext() -} - -type Method_nameContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_nameContext() *Method_nameContext { - var p = new(Method_nameContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_name - return p -} - -func InitEmptyMethod_nameContext(p *Method_nameContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_name -} - -func (*Method_nameContext) IsMethod_nameContext() {} - -func NewMethod_nameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_nameContext { - var p = new(Method_nameContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_name - - return p -} - -func (s *Method_nameContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_nameContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *Method_nameContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_nameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_nameContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_name(s) - } -} - -func (s *Method_nameContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_name(s) - } -} - -func (p *QueryParser) Method_name() (localctx IMethod_nameContext) { - localctx = NewMethod_nameContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 12, QueryParserRULE_method_name) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(128) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_bodyContext is an interface to support dynamic dispatch. -type IMethod_bodyContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Return_statement() IReturn_statementContext - - // IsMethod_bodyContext differentiates from other interfaces. - IsMethod_bodyContext() -} - -type Method_bodyContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_bodyContext() *Method_bodyContext { - var p = new(Method_bodyContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_body - return p -} - -func InitEmptyMethod_bodyContext(p *Method_bodyContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_body -} - -func (*Method_bodyContext) IsMethod_bodyContext() {} - -func NewMethod_bodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_bodyContext { - var p = new(Method_bodyContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_body - - return p -} - -func (s *Method_bodyContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_bodyContext) Return_statement() IReturn_statementContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IReturn_statementContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IReturn_statementContext) -} - -func (s *Method_bodyContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_bodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_bodyContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_body(s) - } -} - -func (s *Method_bodyContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_body(s) - } -} - -func (p *QueryParser) Method_body() (localctx IMethod_bodyContext) { - localctx = NewMethod_bodyContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 14, QueryParserRULE_method_body) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(130) - p.Return_statement() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IReturn_statementContext is an interface to support dynamic dispatch. -type IReturn_statementContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Value() IValueContext - - // IsReturn_statementContext differentiates from other interfaces. - IsReturn_statementContext() -} - -type Return_statementContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyReturn_statementContext() *Return_statementContext { - var p = new(Return_statementContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_return_statement - return p -} - -func InitEmptyReturn_statementContext(p *Return_statementContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_return_statement -} - -func (*Return_statementContext) IsReturn_statementContext() {} - -func NewReturn_statementContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Return_statementContext { - var p = new(Return_statementContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_return_statement - - return p -} - -func (s *Return_statementContext) GetParser() antlr.Parser { return s.parser } - -func (s *Return_statementContext) Value() IValueContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IValueContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IValueContext) -} - -func (s *Return_statementContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Return_statementContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Return_statementContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterReturn_statement(s) - } -} - -func (s *Return_statementContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitReturn_statement(s) - } -} - -func (p *QueryParser) Return_statement() (localctx IReturn_statementContext) { - localctx = NewReturn_statementContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 16, QueryParserRULE_return_statement) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(132) - p.Match(QueryParserT__5) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(133) - p.Match(QueryParserT__6) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(134) - p.Value() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IReturn_typeContext is an interface to support dynamic dispatch. -type IReturn_typeContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Type_() ITypeContext - - // IsReturn_typeContext differentiates from other interfaces. - IsReturn_typeContext() -} - -type Return_typeContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyReturn_typeContext() *Return_typeContext { - var p = new(Return_typeContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_return_type - return p -} - -func InitEmptyReturn_typeContext(p *Return_typeContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_return_type -} - -func (*Return_typeContext) IsReturn_typeContext() {} - -func NewReturn_typeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Return_typeContext { - var p = new(Return_typeContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_return_type - - return p -} - -func (s *Return_typeContext) GetParser() antlr.Parser { return s.parser } - -func (s *Return_typeContext) Type_() ITypeContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ITypeContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(ITypeContext) -} - -func (s *Return_typeContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Return_typeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Return_typeContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterReturn_type(s) - } -} - -func (s *Return_typeContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitReturn_type(s) - } -} - -func (p *QueryParser) Return_type() (localctx IReturn_typeContext) { - localctx = NewReturn_typeContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 18, QueryParserRULE_return_type) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(136) - p.Type_() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IPredicate_declarationsContext is an interface to support dynamic dispatch. -type IPredicate_declarationsContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllPredicate_declaration() []IPredicate_declarationContext - Predicate_declaration(i int) IPredicate_declarationContext - - // IsPredicate_declarationsContext differentiates from other interfaces. - IsPredicate_declarationsContext() -} - -type Predicate_declarationsContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyPredicate_declarationsContext() *Predicate_declarationsContext { - var p = new(Predicate_declarationsContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_declarations - return p -} - -func InitEmptyPredicate_declarationsContext(p *Predicate_declarationsContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_declarations -} - -func (*Predicate_declarationsContext) IsPredicate_declarationsContext() {} - -func NewPredicate_declarationsContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Predicate_declarationsContext { - var p = new(Predicate_declarationsContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_predicate_declarations - - return p -} - -func (s *Predicate_declarationsContext) GetParser() antlr.Parser { return s.parser } - -func (s *Predicate_declarationsContext) AllPredicate_declaration() []IPredicate_declarationContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IPredicate_declarationContext); ok { - len++ - } - } - - tst := make([]IPredicate_declarationContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IPredicate_declarationContext); ok { - tst[i] = t.(IPredicate_declarationContext) - i++ - } - } - - return tst -} - -func (s *Predicate_declarationsContext) Predicate_declaration(i int) IPredicate_declarationContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_declarationContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_declarationContext) -} - -func (s *Predicate_declarationsContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Predicate_declarationsContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Predicate_declarationsContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterPredicate_declarations(s) - } -} - -func (s *Predicate_declarationsContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitPredicate_declarations(s) - } -} - -func (p *QueryParser) Predicate_declarations() (localctx IPredicate_declarationsContext) { - localctx = NewPredicate_declarationsContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 20, QueryParserRULE_predicate_declarations) - var _la int - - p.EnterOuterAlt(localctx, 1) - p.SetState(139) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for ok := true; ok; ok = _la == QueryParserPREDICATE { - { - p.SetState(138) - p.Predicate_declaration() - } - - p.SetState(141) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IPredicate_declarationContext is an interface to support dynamic dispatch. -type IPredicate_declarationContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - PREDICATE() antlr.TerminalNode - Predicate_name() IPredicate_nameContext - Expression() IExpressionContext - Parameter_list() IParameter_listContext - - // IsPredicate_declarationContext differentiates from other interfaces. - IsPredicate_declarationContext() -} - -type Predicate_declarationContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyPredicate_declarationContext() *Predicate_declarationContext { - var p = new(Predicate_declarationContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_declaration - return p -} - -func InitEmptyPredicate_declarationContext(p *Predicate_declarationContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_declaration -} - -func (*Predicate_declarationContext) IsPredicate_declarationContext() {} - -func NewPredicate_declarationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Predicate_declarationContext { - var p = new(Predicate_declarationContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_predicate_declaration - - return p -} - -func (s *Predicate_declarationContext) GetParser() antlr.Parser { return s.parser } - -func (s *Predicate_declarationContext) PREDICATE() antlr.TerminalNode { - return s.GetToken(QueryParserPREDICATE, 0) -} - -func (s *Predicate_declarationContext) Predicate_name() IPredicate_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_nameContext) -} - -func (s *Predicate_declarationContext) Expression() IExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IExpressionContext) -} - -func (s *Predicate_declarationContext) Parameter_list() IParameter_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IParameter_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IParameter_listContext) -} - -func (s *Predicate_declarationContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Predicate_declarationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Predicate_declarationContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterPredicate_declaration(s) - } -} - -func (s *Predicate_declarationContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitPredicate_declaration(s) - } -} - -func (p *QueryParser) Predicate_declaration() (localctx IPredicate_declarationContext) { - localctx = NewPredicate_declarationContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 22, QueryParserRULE_predicate_declaration) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(143) - p.Match(QueryParserPREDICATE) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(144) - p.Predicate_name() - } - { - p.SetState(145) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - p.SetState(147) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if _la == QueryParserIDENTIFIER { - { - p.SetState(146) - p.Parameter_list() - } - - } - { - p.SetState(149) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(150) - p.Match(QueryParserT__1) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(151) - p.Expression() - } - { - p.SetState(152) - p.Match(QueryParserT__2) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IPredicate_nameContext is an interface to support dynamic dispatch. -type IPredicate_nameContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsPredicate_nameContext differentiates from other interfaces. - IsPredicate_nameContext() -} - -type Predicate_nameContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyPredicate_nameContext() *Predicate_nameContext { - var p = new(Predicate_nameContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_name - return p -} - -func InitEmptyPredicate_nameContext(p *Predicate_nameContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_name -} - -func (*Predicate_nameContext) IsPredicate_nameContext() {} - -func NewPredicate_nameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Predicate_nameContext { - var p = new(Predicate_nameContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_predicate_name - - return p -} - -func (s *Predicate_nameContext) GetParser() antlr.Parser { return s.parser } - -func (s *Predicate_nameContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *Predicate_nameContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Predicate_nameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Predicate_nameContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterPredicate_name(s) - } -} - -func (s *Predicate_nameContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitPredicate_name(s) - } -} - -func (p *QueryParser) Predicate_name() (localctx IPredicate_nameContext) { - localctx = NewPredicate_nameContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 24, QueryParserRULE_predicate_name) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(154) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IParameter_listContext is an interface to support dynamic dispatch. -type IParameter_listContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllParameter() []IParameterContext - Parameter(i int) IParameterContext - - // IsParameter_listContext differentiates from other interfaces. - IsParameter_listContext() -} - -type Parameter_listContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyParameter_listContext() *Parameter_listContext { - var p = new(Parameter_listContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_parameter_list - return p -} - -func InitEmptyParameter_listContext(p *Parameter_listContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_parameter_list -} - -func (*Parameter_listContext) IsParameter_listContext() {} - -func NewParameter_listContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Parameter_listContext { - var p = new(Parameter_listContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_parameter_list - - return p -} - -func (s *Parameter_listContext) GetParser() antlr.Parser { return s.parser } - -func (s *Parameter_listContext) AllParameter() []IParameterContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IParameterContext); ok { - len++ - } - } - - tst := make([]IParameterContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IParameterContext); ok { - tst[i] = t.(IParameterContext) - i++ - } - } - - return tst -} - -func (s *Parameter_listContext) Parameter(i int) IParameterContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IParameterContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IParameterContext) -} - -func (s *Parameter_listContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Parameter_listContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Parameter_listContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterParameter_list(s) - } -} - -func (s *Parameter_listContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitParameter_list(s) - } -} - -func (p *QueryParser) Parameter_list() (localctx IParameter_listContext) { - localctx = NewParameter_listContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 26, QueryParserRULE_parameter_list) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(156) - p.Parameter() - } - p.SetState(161) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__7 { - { - p.SetState(157) - p.Match(QueryParserT__7) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(158) - p.Parameter() - } - - p.SetState(163) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IParameterContext is an interface to support dynamic dispatch. -type IParameterContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - Type_() ITypeContext - Class_name() IClass_nameContext - - // IsParameterContext differentiates from other interfaces. - IsParameterContext() -} - -type ParameterContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyParameterContext() *ParameterContext { - var p = new(ParameterContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_parameter - return p -} - -func InitEmptyParameterContext(p *ParameterContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_parameter -} - -func (*ParameterContext) IsParameterContext() {} - -func NewParameterContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ParameterContext { - var p = new(ParameterContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_parameter - - return p -} - -func (s *ParameterContext) GetParser() antlr.Parser { return s.parser } - -func (s *ParameterContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *ParameterContext) Type_() ITypeContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ITypeContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(ITypeContext) -} - -func (s *ParameterContext) Class_name() IClass_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_nameContext) -} - -func (s *ParameterContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *ParameterContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *ParameterContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterParameter(s) - } -} - -func (s *ParameterContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitParameter(s) - } -} - -func (p *QueryParser) Parameter() (localctx IParameterContext) { - localctx = NewParameterContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 28, QueryParserRULE_parameter) - p.EnterOuterAlt(localctx, 1) - p.SetState(166) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) { - case 1: - { - p.SetState(164) - p.Type_() - } - - case 2: - { - p.SetState(165) - p.Class_name() - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - { - p.SetState(168) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// ITypeContext is an interface to support dynamic dispatch. -type ITypeContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsTypeContext differentiates from other interfaces. - IsTypeContext() -} - -type TypeContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyTypeContext() *TypeContext { - var p = new(TypeContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_type - return p -} - -func InitEmptyTypeContext(p *TypeContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_type -} - -func (*TypeContext) IsTypeContext() {} - -func NewTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeContext { - var p = new(TypeContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_type - - return p -} - -func (s *TypeContext) GetParser() antlr.Parser { return s.parser } - -func (s *TypeContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *TypeContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *TypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *TypeContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterType(s) - } -} - -func (s *TypeContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitType(s) - } -} - -func (p *QueryParser) Type_() (localctx ITypeContext) { - localctx = NewTypeContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 30, QueryParserRULE_type) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(170) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// ISelect_listContext is an interface to support dynamic dispatch. -type ISelect_listContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllSelect_item() []ISelect_itemContext - Select_item(i int) ISelect_itemContext - - // IsSelect_listContext differentiates from other interfaces. - IsSelect_listContext() -} - -type Select_listContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptySelect_listContext() *Select_listContext { - var p = new(Select_listContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_list - return p -} - -func InitEmptySelect_listContext(p *Select_listContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_list -} - -func (*Select_listContext) IsSelect_listContext() {} - -func NewSelect_listContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Select_listContext { - var p = new(Select_listContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_select_list - - return p -} - -func (s *Select_listContext) GetParser() antlr.Parser { return s.parser } - -func (s *Select_listContext) AllSelect_item() []ISelect_itemContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(ISelect_itemContext); ok { - len++ - } - } - - tst := make([]ISelect_itemContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(ISelect_itemContext); ok { - tst[i] = t.(ISelect_itemContext) - i++ - } - } - - return tst -} - -func (s *Select_listContext) Select_item(i int) ISelect_itemContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ISelect_itemContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(ISelect_itemContext) -} - -func (s *Select_listContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Select_listContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Select_listContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterSelect_list(s) - } -} - -func (s *Select_listContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitSelect_list(s) - } -} - -func (p *QueryParser) Select_list() (localctx ISelect_listContext) { - localctx = NewSelect_listContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 32, QueryParserRULE_select_list) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(172) - p.Select_item() - } - p.SetState(177) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__7 { - { - p.SetState(173) - p.Match(QueryParserT__7) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(174) - p.Select_item() - } - - p.SetState(179) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// ISelect_itemContext is an interface to support dynamic dispatch. -type ISelect_itemContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AS() antlr.TerminalNode - Alias() IAliasContext - Entity() IEntityContext - Class_name() IClass_nameContext - - // IsSelect_itemContext differentiates from other interfaces. - IsSelect_itemContext() -} - -type Select_itemContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptySelect_itemContext() *Select_itemContext { - var p = new(Select_itemContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_item - return p -} - -func InitEmptySelect_itemContext(p *Select_itemContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_item -} - -func (*Select_itemContext) IsSelect_itemContext() {} - -func NewSelect_itemContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Select_itemContext { - var p = new(Select_itemContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_select_item - - return p -} - -func (s *Select_itemContext) GetParser() antlr.Parser { return s.parser } - -func (s *Select_itemContext) AS() antlr.TerminalNode { - return s.GetToken(QueryParserAS, 0) -} - -func (s *Select_itemContext) Alias() IAliasContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IAliasContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IAliasContext) -} - -func (s *Select_itemContext) Entity() IEntityContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IEntityContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IEntityContext) -} - -func (s *Select_itemContext) Class_name() IClass_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_nameContext) -} - -func (s *Select_itemContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Select_itemContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Select_itemContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterSelect_item(s) - } -} - -func (s *Select_itemContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitSelect_item(s) - } -} - -func (p *QueryParser) Select_item() (localctx ISelect_itemContext) { - localctx = NewSelect_itemContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 34, QueryParserRULE_select_item) - p.EnterOuterAlt(localctx, 1) - p.SetState(182) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 11, p.GetParserRuleContext()) { - case 1: - { - p.SetState(180) - p.Entity() - } - - case 2: - { - p.SetState(181) - p.Class_name() - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - { - p.SetState(184) - p.Match(QueryParserAS) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(185) - p.Alias() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IEntityContext is an interface to support dynamic dispatch. -type IEntityContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsEntityContext differentiates from other interfaces. - IsEntityContext() -} - -type EntityContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyEntityContext() *EntityContext { - var p = new(EntityContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_entity - return p -} - -func InitEmptyEntityContext(p *EntityContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_entity -} - -func (*EntityContext) IsEntityContext() {} - -func NewEntityContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *EntityContext { - var p = new(EntityContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_entity - - return p -} - -func (s *EntityContext) GetParser() antlr.Parser { return s.parser } - -func (s *EntityContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *EntityContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *EntityContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *EntityContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterEntity(s) - } -} - -func (s *EntityContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitEntity(s) - } -} - -func (p *QueryParser) Entity() (localctx IEntityContext) { - localctx = NewEntityContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 36, QueryParserRULE_entity) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(187) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IAliasContext is an interface to support dynamic dispatch. -type IAliasContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsAliasContext differentiates from other interfaces. - IsAliasContext() -} - -type AliasContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyAliasContext() *AliasContext { - var p = new(AliasContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_alias - return p -} - -func InitEmptyAliasContext(p *AliasContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_alias -} - -func (*AliasContext) IsAliasContext() {} - -func NewAliasContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AliasContext { - var p = new(AliasContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_alias - - return p -} - -func (s *AliasContext) GetParser() antlr.Parser { return s.parser } - -func (s *AliasContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *AliasContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *AliasContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *AliasContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterAlias(s) - } -} - -func (s *AliasContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitAlias(s) - } -} - -func (p *QueryParser) Alias() (localctx IAliasContext) { - localctx = NewAliasContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 38, QueryParserRULE_alias) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(189) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IExpressionContext is an interface to support dynamic dispatch. -type IExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - OrExpression() IOrExpressionContext - - // IsExpressionContext differentiates from other interfaces. - IsExpressionContext() -} - -type ExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyExpressionContext() *ExpressionContext { - var p = new(ExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_expression - return p -} - -func InitEmptyExpressionContext(p *ExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_expression -} - -func (*ExpressionContext) IsExpressionContext() {} - -func NewExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ExpressionContext { - var p = new(ExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_expression - - return p -} - -func (s *ExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *ExpressionContext) OrExpression() IOrExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IOrExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IOrExpressionContext) -} - -func (s *ExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *ExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *ExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterExpression(s) - } -} - -func (s *ExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitExpression(s) - } -} - -func (p *QueryParser) Expression() (localctx IExpressionContext) { - localctx = NewExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 40, QueryParserRULE_expression) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(191) - p.OrExpression() - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IOrExpressionContext is an interface to support dynamic dispatch. -type IOrExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllAndExpression() []IAndExpressionContext - AndExpression(i int) IAndExpressionContext - - // IsOrExpressionContext differentiates from other interfaces. - IsOrExpressionContext() -} - -type OrExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyOrExpressionContext() *OrExpressionContext { - var p = new(OrExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_orExpression - return p -} - -func InitEmptyOrExpressionContext(p *OrExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_orExpression -} - -func (*OrExpressionContext) IsOrExpressionContext() {} - -func NewOrExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *OrExpressionContext { - var p = new(OrExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_orExpression - - return p -} - -func (s *OrExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *OrExpressionContext) AllAndExpression() []IAndExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IAndExpressionContext); ok { - len++ - } - } - - tst := make([]IAndExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IAndExpressionContext); ok { - tst[i] = t.(IAndExpressionContext) - i++ - } - } - - return tst -} - -func (s *OrExpressionContext) AndExpression(i int) IAndExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IAndExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IAndExpressionContext) -} - -func (s *OrExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *OrExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *OrExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterOrExpression(s) - } -} - -func (s *OrExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitOrExpression(s) - } -} - -func (p *QueryParser) OrExpression() (localctx IOrExpressionContext) { - localctx = NewOrExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 42, QueryParserRULE_orExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(193) - p.AndExpression() - } - p.SetState(198) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__8 { - { - p.SetState(194) - p.Match(QueryParserT__8) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(195) - p.AndExpression() - } - - p.SetState(200) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IAndExpressionContext is an interface to support dynamic dispatch. -type IAndExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllEqualityExpression() []IEqualityExpressionContext - EqualityExpression(i int) IEqualityExpressionContext - - // IsAndExpressionContext differentiates from other interfaces. - IsAndExpressionContext() -} - -type AndExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyAndExpressionContext() *AndExpressionContext { - var p = new(AndExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_andExpression - return p -} - -func InitEmptyAndExpressionContext(p *AndExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_andExpression -} - -func (*AndExpressionContext) IsAndExpressionContext() {} - -func NewAndExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AndExpressionContext { - var p = new(AndExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_andExpression - - return p -} - -func (s *AndExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *AndExpressionContext) AllEqualityExpression() []IEqualityExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IEqualityExpressionContext); ok { - len++ - } - } - - tst := make([]IEqualityExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IEqualityExpressionContext); ok { - tst[i] = t.(IEqualityExpressionContext) - i++ - } - } - - return tst -} - -func (s *AndExpressionContext) EqualityExpression(i int) IEqualityExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IEqualityExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IEqualityExpressionContext) -} - -func (s *AndExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *AndExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *AndExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterAndExpression(s) - } -} - -func (s *AndExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitAndExpression(s) - } -} - -func (p *QueryParser) AndExpression() (localctx IAndExpressionContext) { - localctx = NewAndExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 44, QueryParserRULE_andExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(201) - p.EqualityExpression() - } - p.SetState(206) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__9 { - { - p.SetState(202) - p.Match(QueryParserT__9) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(203) - p.EqualityExpression() - } - - p.SetState(208) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IEqualityExpressionContext is an interface to support dynamic dispatch. -type IEqualityExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllRelationalExpression() []IRelationalExpressionContext - RelationalExpression(i int) IRelationalExpressionContext - - // IsEqualityExpressionContext differentiates from other interfaces. - IsEqualityExpressionContext() -} - -type EqualityExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyEqualityExpressionContext() *EqualityExpressionContext { - var p = new(EqualityExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_equalityExpression - return p -} - -func InitEmptyEqualityExpressionContext(p *EqualityExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_equalityExpression -} - -func (*EqualityExpressionContext) IsEqualityExpressionContext() {} - -func NewEqualityExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *EqualityExpressionContext { - var p = new(EqualityExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_equalityExpression - - return p -} - -func (s *EqualityExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *EqualityExpressionContext) AllRelationalExpression() []IRelationalExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IRelationalExpressionContext); ok { - len++ - } - } - - tst := make([]IRelationalExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IRelationalExpressionContext); ok { - tst[i] = t.(IRelationalExpressionContext) - i++ - } - } - - return tst -} - -func (s *EqualityExpressionContext) RelationalExpression(i int) IRelationalExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IRelationalExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IRelationalExpressionContext) -} - -func (s *EqualityExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *EqualityExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *EqualityExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterEqualityExpression(s) - } -} - -func (s *EqualityExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitEqualityExpression(s) - } -} - -func (p *QueryParser) EqualityExpression() (localctx IEqualityExpressionContext) { - localctx = NewEqualityExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 46, QueryParserRULE_equalityExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(209) - p.RelationalExpression() - } - p.SetState(214) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__10 || _la == QueryParserT__11 { - { - p.SetState(210) - _la = p.GetTokenStream().LA(1) - - if !(_la == QueryParserT__10 || _la == QueryParserT__11) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - { - p.SetState(211) - p.RelationalExpression() - } - - p.SetState(216) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IRelationalExpressionContext is an interface to support dynamic dispatch. -type IRelationalExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllAdditiveExpression() []IAdditiveExpressionContext - AdditiveExpression(i int) IAdditiveExpressionContext - - // IsRelationalExpressionContext differentiates from other interfaces. - IsRelationalExpressionContext() -} - -type RelationalExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyRelationalExpressionContext() *RelationalExpressionContext { - var p = new(RelationalExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_relationalExpression - return p -} - -func InitEmptyRelationalExpressionContext(p *RelationalExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_relationalExpression -} - -func (*RelationalExpressionContext) IsRelationalExpressionContext() {} - -func NewRelationalExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RelationalExpressionContext { - var p = new(RelationalExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_relationalExpression - - return p -} - -func (s *RelationalExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *RelationalExpressionContext) AllAdditiveExpression() []IAdditiveExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IAdditiveExpressionContext); ok { - len++ - } - } - - tst := make([]IAdditiveExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IAdditiveExpressionContext); ok { - tst[i] = t.(IAdditiveExpressionContext) - i++ - } - } - - return tst -} - -func (s *RelationalExpressionContext) AdditiveExpression(i int) IAdditiveExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IAdditiveExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IAdditiveExpressionContext) -} - -func (s *RelationalExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *RelationalExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *RelationalExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterRelationalExpression(s) - } -} - -func (s *RelationalExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitRelationalExpression(s) - } -} - -func (p *QueryParser) RelationalExpression() (localctx IRelationalExpressionContext) { - localctx = NewRelationalExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 48, QueryParserRULE_relationalExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(217) - p.AdditiveExpression() - } - p.SetState(222) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&253952) != 0 { - { - p.SetState(218) - _la = p.GetTokenStream().LA(1) - - if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&253952) != 0) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - { - p.SetState(219) - p.AdditiveExpression() - } - - p.SetState(224) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IAdditiveExpressionContext is an interface to support dynamic dispatch. -type IAdditiveExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllMultiplicativeExpression() []IMultiplicativeExpressionContext - MultiplicativeExpression(i int) IMultiplicativeExpressionContext - - // IsAdditiveExpressionContext differentiates from other interfaces. - IsAdditiveExpressionContext() -} - -type AdditiveExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyAdditiveExpressionContext() *AdditiveExpressionContext { - var p = new(AdditiveExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_additiveExpression - return p -} - -func InitEmptyAdditiveExpressionContext(p *AdditiveExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_additiveExpression -} - -func (*AdditiveExpressionContext) IsAdditiveExpressionContext() {} - -func NewAdditiveExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AdditiveExpressionContext { - var p = new(AdditiveExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_additiveExpression - - return p -} - -func (s *AdditiveExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *AdditiveExpressionContext) AllMultiplicativeExpression() []IMultiplicativeExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IMultiplicativeExpressionContext); ok { - len++ - } - } - - tst := make([]IMultiplicativeExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IMultiplicativeExpressionContext); ok { - tst[i] = t.(IMultiplicativeExpressionContext) - i++ - } - } - - return tst -} - -func (s *AdditiveExpressionContext) MultiplicativeExpression(i int) IMultiplicativeExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMultiplicativeExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IMultiplicativeExpressionContext) -} - -func (s *AdditiveExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *AdditiveExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *AdditiveExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterAdditiveExpression(s) - } -} - -func (s *AdditiveExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitAdditiveExpression(s) - } -} - -func (p *QueryParser) AdditiveExpression() (localctx IAdditiveExpressionContext) { - localctx = NewAdditiveExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 50, QueryParserRULE_additiveExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(225) - p.MultiplicativeExpression() - } - p.SetState(230) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__17 || _la == QueryParserT__18 { - { - p.SetState(226) - _la = p.GetTokenStream().LA(1) - - if !(_la == QueryParserT__17 || _la == QueryParserT__18) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - { - p.SetState(227) - p.MultiplicativeExpression() - } - - p.SetState(232) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMultiplicativeExpressionContext is an interface to support dynamic dispatch. -type IMultiplicativeExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllUnaryExpression() []IUnaryExpressionContext - UnaryExpression(i int) IUnaryExpressionContext - - // IsMultiplicativeExpressionContext differentiates from other interfaces. - IsMultiplicativeExpressionContext() -} - -type MultiplicativeExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMultiplicativeExpressionContext() *MultiplicativeExpressionContext { - var p = new(MultiplicativeExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_multiplicativeExpression - return p -} - -func InitEmptyMultiplicativeExpressionContext(p *MultiplicativeExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_multiplicativeExpression -} - -func (*MultiplicativeExpressionContext) IsMultiplicativeExpressionContext() {} - -func NewMultiplicativeExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MultiplicativeExpressionContext { - var p = new(MultiplicativeExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_multiplicativeExpression - - return p -} - -func (s *MultiplicativeExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *MultiplicativeExpressionContext) AllUnaryExpression() []IUnaryExpressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IUnaryExpressionContext); ok { - len++ - } - } - - tst := make([]IUnaryExpressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IUnaryExpressionContext); ok { - tst[i] = t.(IUnaryExpressionContext) - i++ - } - } - - return tst -} - -func (s *MultiplicativeExpressionContext) UnaryExpression(i int) IUnaryExpressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IUnaryExpressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IUnaryExpressionContext) -} - -func (s *MultiplicativeExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *MultiplicativeExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *MultiplicativeExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMultiplicativeExpression(s) - } -} - -func (s *MultiplicativeExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMultiplicativeExpression(s) - } -} - -func (p *QueryParser) MultiplicativeExpression() (localctx IMultiplicativeExpressionContext) { - localctx = NewMultiplicativeExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 52, QueryParserRULE_multiplicativeExpression) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(233) - p.UnaryExpression() - } - p.SetState(238) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__19 || _la == QueryParserT__20 { - { - p.SetState(234) - _la = p.GetTokenStream().LA(1) - - if !(_la == QueryParserT__19 || _la == QueryParserT__20) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - { - p.SetState(235) - p.UnaryExpression() - } - - p.SetState(240) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IUnaryExpressionContext is an interface to support dynamic dispatch. -type IUnaryExpressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - UnaryExpression() IUnaryExpressionContext - Primary() IPrimaryContext - - // IsUnaryExpressionContext differentiates from other interfaces. - IsUnaryExpressionContext() -} - -type UnaryExpressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyUnaryExpressionContext() *UnaryExpressionContext { - var p = new(UnaryExpressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_unaryExpression - return p -} - -func InitEmptyUnaryExpressionContext(p *UnaryExpressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_unaryExpression -} - -func (*UnaryExpressionContext) IsUnaryExpressionContext() {} - -func NewUnaryExpressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *UnaryExpressionContext { - var p = new(UnaryExpressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_unaryExpression - - return p -} - -func (s *UnaryExpressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *UnaryExpressionContext) UnaryExpression() IUnaryExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IUnaryExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IUnaryExpressionContext) -} - -func (s *UnaryExpressionContext) Primary() IPrimaryContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPrimaryContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPrimaryContext) -} - -func (s *UnaryExpressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *UnaryExpressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *UnaryExpressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterUnaryExpression(s) - } -} - -func (s *UnaryExpressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitUnaryExpression(s) - } -} - -func (p *QueryParser) UnaryExpression() (localctx IUnaryExpressionContext) { - localctx = NewUnaryExpressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 54, QueryParserRULE_unaryExpression) - var _la int - - p.SetState(244) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetTokenStream().LA(1) { - case QueryParserT__18, QueryParserT__21: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(241) - _la = p.GetTokenStream().LA(1) - - if !(_la == QueryParserT__18 || _la == QueryParserT__21) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - { - p.SetState(242) - p.UnaryExpression() - } - - case QueryParserT__3, QueryParserT__23, QueryParserSTRING, QueryParserSTRING_WITH_WILDCARD, QueryParserNUMBER, QueryParserIDENTIFIER: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(243) - p.Primary() - } - - default: - p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil)) - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IPrimaryContext is an interface to support dynamic dispatch. -type IPrimaryContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Operand() IOperandContext - Predicate_invocation() IPredicate_invocationContext - Expression() IExpressionContext - - // IsPrimaryContext differentiates from other interfaces. - IsPrimaryContext() -} - -type PrimaryContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyPrimaryContext() *PrimaryContext { - var p = new(PrimaryContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_primary - return p -} - -func InitEmptyPrimaryContext(p *PrimaryContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_primary -} - -func (*PrimaryContext) IsPrimaryContext() {} - -func NewPrimaryContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PrimaryContext { - var p = new(PrimaryContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_primary - - return p -} - -func (s *PrimaryContext) GetParser() antlr.Parser { return s.parser } - -func (s *PrimaryContext) Operand() IOperandContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IOperandContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IOperandContext) -} - -func (s *PrimaryContext) Predicate_invocation() IPredicate_invocationContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_invocationContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_invocationContext) -} - -func (s *PrimaryContext) Expression() IExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IExpressionContext) -} - -func (s *PrimaryContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *PrimaryContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *PrimaryContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterPrimary(s) - } -} - -func (s *PrimaryContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitPrimary(s) - } -} - -func (p *QueryParser) Primary() (localctx IPrimaryContext) { - localctx = NewPrimaryContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 56, QueryParserRULE_primary) - p.SetState(252) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 19, p.GetParserRuleContext()) { - case 1: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(246) - p.Operand() - } - - case 2: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(247) - p.Predicate_invocation() - } - - case 3: - p.EnterOuterAlt(localctx, 3) - { - p.SetState(248) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(249) - p.Expression() - } - { - p.SetState(250) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IOperandContext is an interface to support dynamic dispatch. -type IOperandContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Value() IValueContext - Variable() IVariableContext - Alias() IAliasContext - Method_chain() IMethod_chainContext - Class_name() IClass_nameContext - Value_list() IValue_listContext - - // IsOperandContext differentiates from other interfaces. - IsOperandContext() -} - -type OperandContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyOperandContext() *OperandContext { - var p = new(OperandContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_operand - return p -} - -func InitEmptyOperandContext(p *OperandContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_operand -} - -func (*OperandContext) IsOperandContext() {} - -func NewOperandContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *OperandContext { - var p = new(OperandContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_operand - - return p -} - -func (s *OperandContext) GetParser() antlr.Parser { return s.parser } - -func (s *OperandContext) Value() IValueContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IValueContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IValueContext) -} - -func (s *OperandContext) Variable() IVariableContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IVariableContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IVariableContext) -} - -func (s *OperandContext) Alias() IAliasContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IAliasContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IAliasContext) -} - -func (s *OperandContext) Method_chain() IMethod_chainContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_chainContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_chainContext) -} - -func (s *OperandContext) Class_name() IClass_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_nameContext) -} - -func (s *OperandContext) Value_list() IValue_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IValue_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IValue_listContext) -} - -func (s *OperandContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *OperandContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *OperandContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterOperand(s) - } -} - -func (s *OperandContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitOperand(s) - } -} - -func (p *QueryParser) Operand() (localctx IOperandContext) { - localctx = NewOperandContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 58, QueryParserRULE_operand) - p.SetState(268) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 20, p.GetParserRuleContext()) { - case 1: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(254) - p.Value() - } - - case 2: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(255) - p.Variable() - } - - case 3: - p.EnterOuterAlt(localctx, 3) - { - p.SetState(256) - p.Alias() - } - { - p.SetState(257) - p.Match(QueryParserT__22) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(258) - p.Method_chain() - } - - case 4: - p.EnterOuterAlt(localctx, 4) - { - p.SetState(260) - p.Class_name() - } - { - p.SetState(261) - p.Match(QueryParserT__22) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(262) - p.Method_chain() - } - - case 5: - p.EnterOuterAlt(localctx, 5) - { - p.SetState(264) - p.Match(QueryParserT__23) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(265) - p.Value_list() - } - { - p.SetState(266) - p.Match(QueryParserT__24) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_chainContext is an interface to support dynamic dispatch. -type IMethod_chainContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Method_name() IMethod_nameContext - Class_name() IClass_nameContext - Argument_list() IArgument_listContext - - // IsMethod_chainContext differentiates from other interfaces. - IsMethod_chainContext() -} - -type Method_chainContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_chainContext() *Method_chainContext { - var p = new(Method_chainContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_chain - return p -} - -func InitEmptyMethod_chainContext(p *Method_chainContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_chain -} - -func (*Method_chainContext) IsMethod_chainContext() {} - -func NewMethod_chainContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_chainContext { - var p = new(Method_chainContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_chain - - return p -} - -func (s *Method_chainContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_chainContext) Method_name() IMethod_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_nameContext) -} - -func (s *Method_chainContext) Class_name() IClass_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IClass_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IClass_nameContext) -} - -func (s *Method_chainContext) Argument_list() IArgument_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IArgument_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IArgument_listContext) -} - -func (s *Method_chainContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_chainContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_chainContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_chain(s) - } -} - -func (s *Method_chainContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_chain(s) - } -} - -func (p *QueryParser) Method_chain() (localctx IMethod_chainContext) { - localctx = NewMethod_chainContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 60, QueryParserRULE_method_chain) - var _la int - - p.EnterOuterAlt(localctx, 1) - p.SetState(273) - p.GetErrorHandler().Sync(p) - - if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 21, p.GetParserRuleContext()) == 1 { - { - p.SetState(270) - p.Class_name() - } - { - p.SetState(271) - p.Match(QueryParserT__22) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - } else if p.HasError() { // JIM - goto errorExit - } - { - p.SetState(275) - p.Method_name() - } - { - p.SetState(276) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - p.SetState(278) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&70620020752) != 0 { - { - p.SetState(277) - p.Argument_list() - } - - } - { - p.SetState(280) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_or_variableContext is an interface to support dynamic dispatch. -type IMethod_or_variableContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Method_invocation() IMethod_invocationContext - Variable() IVariableContext - Predicate_invocation() IPredicate_invocationContext - - // IsMethod_or_variableContext differentiates from other interfaces. - IsMethod_or_variableContext() -} - -type Method_or_variableContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_or_variableContext() *Method_or_variableContext { - var p = new(Method_or_variableContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_or_variable - return p -} - -func InitEmptyMethod_or_variableContext(p *Method_or_variableContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_or_variable -} - -func (*Method_or_variableContext) IsMethod_or_variableContext() {} - -func NewMethod_or_variableContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_or_variableContext { - var p = new(Method_or_variableContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_or_variable - - return p -} - -func (s *Method_or_variableContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_or_variableContext) Method_invocation() IMethod_invocationContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_invocationContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_invocationContext) -} - -func (s *Method_or_variableContext) Variable() IVariableContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IVariableContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IVariableContext) -} - -func (s *Method_or_variableContext) Predicate_invocation() IPredicate_invocationContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_invocationContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_invocationContext) -} - -func (s *Method_or_variableContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_or_variableContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_or_variableContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_or_variable(s) - } -} - -func (s *Method_or_variableContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_or_variable(s) - } -} - -func (p *QueryParser) Method_or_variable() (localctx IMethod_or_variableContext) { - localctx = NewMethod_or_variableContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 62, QueryParserRULE_method_or_variable) - p.SetState(285) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 23, p.GetParserRuleContext()) { - case 1: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(282) - p.Method_invocation() - } - - case 2: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(283) - p.Variable() - } - - case 3: - p.EnterOuterAlt(localctx, 3) - { - p.SetState(284) - p.Predicate_invocation() - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IMethod_invocationContext is an interface to support dynamic dispatch. -type IMethod_invocationContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - Argument_list() IArgument_listContext - - // IsMethod_invocationContext differentiates from other interfaces. - IsMethod_invocationContext() -} - -type Method_invocationContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyMethod_invocationContext() *Method_invocationContext { - var p = new(Method_invocationContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_invocation - return p -} - -func InitEmptyMethod_invocationContext(p *Method_invocationContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_method_invocation -} - -func (*Method_invocationContext) IsMethod_invocationContext() {} - -func NewMethod_invocationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Method_invocationContext { - var p = new(Method_invocationContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_method_invocation - - return p -} - -func (s *Method_invocationContext) GetParser() antlr.Parser { return s.parser } - -func (s *Method_invocationContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *Method_invocationContext) Argument_list() IArgument_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IArgument_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IArgument_listContext) -} - -func (s *Method_invocationContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Method_invocationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Method_invocationContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterMethod_invocation(s) - } -} - -func (s *Method_invocationContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitMethod_invocation(s) - } -} - -func (p *QueryParser) Method_invocation() (localctx IMethod_invocationContext) { - localctx = NewMethod_invocationContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 64, QueryParserRULE_method_invocation) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(287) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(288) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - p.SetState(290) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&70620020752) != 0 { - { - p.SetState(289) - p.Argument_list() - } - - } - { - p.SetState(292) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IVariableContext is an interface to support dynamic dispatch. -type IVariableContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - IDENTIFIER() antlr.TerminalNode - - // IsVariableContext differentiates from other interfaces. - IsVariableContext() -} - -type VariableContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyVariableContext() *VariableContext { - var p = new(VariableContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_variable - return p -} - -func InitEmptyVariableContext(p *VariableContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_variable -} - -func (*VariableContext) IsVariableContext() {} - -func NewVariableContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *VariableContext { - var p = new(VariableContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_variable - - return p -} - -func (s *VariableContext) GetParser() antlr.Parser { return s.parser } - -func (s *VariableContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(QueryParserIDENTIFIER, 0) -} - -func (s *VariableContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *VariableContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *VariableContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterVariable(s) - } -} - -func (s *VariableContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitVariable(s) - } -} - -func (p *QueryParser) Variable() (localctx IVariableContext) { - localctx = NewVariableContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 66, QueryParserRULE_variable) - p.EnterOuterAlt(localctx, 1) - { - p.SetState(294) - p.Match(QueryParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IPredicate_invocationContext is an interface to support dynamic dispatch. -type IPredicate_invocationContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Predicate_name() IPredicate_nameContext - Argument_list() IArgument_listContext - - // IsPredicate_invocationContext differentiates from other interfaces. - IsPredicate_invocationContext() -} - -type Predicate_invocationContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyPredicate_invocationContext() *Predicate_invocationContext { - var p = new(Predicate_invocationContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_invocation - return p -} - -func InitEmptyPredicate_invocationContext(p *Predicate_invocationContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_predicate_invocation -} - -func (*Predicate_invocationContext) IsPredicate_invocationContext() {} - -func NewPredicate_invocationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Predicate_invocationContext { - var p = new(Predicate_invocationContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_predicate_invocation - - return p -} - -func (s *Predicate_invocationContext) GetParser() antlr.Parser { return s.parser } - -func (s *Predicate_invocationContext) Predicate_name() IPredicate_nameContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IPredicate_nameContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IPredicate_nameContext) -} - -func (s *Predicate_invocationContext) Argument_list() IArgument_listContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IArgument_listContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IArgument_listContext) -} - -func (s *Predicate_invocationContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Predicate_invocationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Predicate_invocationContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterPredicate_invocation(s) - } -} - -func (s *Predicate_invocationContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitPredicate_invocation(s) - } -} - -func (p *QueryParser) Predicate_invocation() (localctx IPredicate_invocationContext) { - localctx = NewPredicate_invocationContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 68, QueryParserRULE_predicate_invocation) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(296) - p.Predicate_name() - } - { - p.SetState(297) - p.Match(QueryParserT__3) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - p.SetState(299) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&70620020752) != 0 { - { - p.SetState(298) - p.Argument_list() - } - - } - { - p.SetState(301) - p.Match(QueryParserT__4) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IArgument_listContext is an interface to support dynamic dispatch. -type IArgument_listContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllArgument() []IArgumentContext - Argument(i int) IArgumentContext - - // IsArgument_listContext differentiates from other interfaces. - IsArgument_listContext() -} - -type Argument_listContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyArgument_listContext() *Argument_listContext { - var p = new(Argument_listContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_argument_list - return p -} - -func InitEmptyArgument_listContext(p *Argument_listContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_argument_list -} - -func (*Argument_listContext) IsArgument_listContext() {} - -func NewArgument_listContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Argument_listContext { - var p = new(Argument_listContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_argument_list - - return p -} - -func (s *Argument_listContext) GetParser() antlr.Parser { return s.parser } - -func (s *Argument_listContext) AllArgument() []IArgumentContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IArgumentContext); ok { - len++ - } - } - - tst := make([]IArgumentContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IArgumentContext); ok { - tst[i] = t.(IArgumentContext) - i++ - } - } - - return tst -} - -func (s *Argument_listContext) Argument(i int) IArgumentContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IArgumentContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IArgumentContext) -} - -func (s *Argument_listContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Argument_listContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Argument_listContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterArgument_list(s) - } -} - -func (s *Argument_listContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitArgument_list(s) - } -} - -func (p *QueryParser) Argument_list() (localctx IArgument_listContext) { - localctx = NewArgument_listContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 70, QueryParserRULE_argument_list) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(303) - p.Argument() - } - p.SetState(308) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__7 { - { - p.SetState(304) - p.Match(QueryParserT__7) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(305) - p.Argument() - } - - p.SetState(310) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IArgumentContext is an interface to support dynamic dispatch. -type IArgumentContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Expression() IExpressionContext - STRING() antlr.TerminalNode - - // IsArgumentContext differentiates from other interfaces. - IsArgumentContext() -} - -type ArgumentContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyArgumentContext() *ArgumentContext { - var p = new(ArgumentContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_argument - return p -} - -func InitEmptyArgumentContext(p *ArgumentContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_argument -} - -func (*ArgumentContext) IsArgumentContext() {} - -func NewArgumentContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ArgumentContext { - var p = new(ArgumentContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_argument - - return p -} - -func (s *ArgumentContext) GetParser() antlr.Parser { return s.parser } - -func (s *ArgumentContext) Expression() IExpressionContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IExpressionContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IExpressionContext) -} - -func (s *ArgumentContext) STRING() antlr.TerminalNode { - return s.GetToken(QueryParserSTRING, 0) -} - -func (s *ArgumentContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *ArgumentContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *ArgumentContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterArgument(s) - } -} - -func (s *ArgumentContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitArgument(s) - } -} - -func (p *QueryParser) Argument() (localctx IArgumentContext) { - localctx = NewArgumentContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 72, QueryParserRULE_argument) - p.SetState(313) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 27, p.GetParserRuleContext()) { - case 1: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(311) - p.Expression() - } - - case 2: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(312) - p.Match(QueryParserSTRING) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IComparatorContext is an interface to support dynamic dispatch. -type IComparatorContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - // IsComparatorContext differentiates from other interfaces. - IsComparatorContext() -} - -type ComparatorContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyComparatorContext() *ComparatorContext { - var p = new(ComparatorContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_comparator - return p -} - -func InitEmptyComparatorContext(p *ComparatorContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_comparator -} - -func (*ComparatorContext) IsComparatorContext() {} - -func NewComparatorContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ComparatorContext { - var p = new(ComparatorContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_comparator - - return p -} - -func (s *ComparatorContext) GetParser() antlr.Parser { return s.parser } -func (s *ComparatorContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *ComparatorContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *ComparatorContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterComparator(s) - } -} - -func (s *ComparatorContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitComparator(s) - } -} - -func (p *QueryParser) Comparator() (localctx IComparatorContext) { - localctx = NewComparatorContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 74, QueryParserRULE_comparator) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(315) - _la = p.GetTokenStream().LA(1) - - if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&201455616) != 0) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IValueContext is an interface to support dynamic dispatch. -type IValueContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - STRING() antlr.TerminalNode - NUMBER() antlr.TerminalNode - STRING_WITH_WILDCARD() antlr.TerminalNode - - // IsValueContext differentiates from other interfaces. - IsValueContext() -} - -type ValueContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyValueContext() *ValueContext { - var p = new(ValueContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_value - return p -} - -func InitEmptyValueContext(p *ValueContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_value -} - -func (*ValueContext) IsValueContext() {} - -func NewValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueContext { - var p = new(ValueContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_value - - return p -} - -func (s *ValueContext) GetParser() antlr.Parser { return s.parser } - -func (s *ValueContext) STRING() antlr.TerminalNode { - return s.GetToken(QueryParserSTRING, 0) -} - -func (s *ValueContext) NUMBER() antlr.TerminalNode { - return s.GetToken(QueryParserNUMBER, 0) -} - -func (s *ValueContext) STRING_WITH_WILDCARD() antlr.TerminalNode { - return s.GetToken(QueryParserSTRING_WITH_WILDCARD, 0) -} - -func (s *ValueContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *ValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *ValueContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterValue(s) - } -} - -func (s *ValueContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitValue(s) - } -} - -func (p *QueryParser) Value() (localctx IValueContext) { - localctx = NewValueContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 76, QueryParserRULE_value) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(317) - _la = p.GetTokenStream().LA(1) - - if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&1879048192) != 0) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() - } - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// IValue_listContext is an interface to support dynamic dispatch. -type IValue_listContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllValue() []IValueContext - Value(i int) IValueContext - - // IsValue_listContext differentiates from other interfaces. - IsValue_listContext() -} - -type Value_listContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptyValue_listContext() *Value_listContext { - var p = new(Value_listContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_value_list - return p -} - -func InitEmptyValue_listContext(p *Value_listContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_value_list -} - -func (*Value_listContext) IsValue_listContext() {} - -func NewValue_listContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Value_listContext { - var p = new(Value_listContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_value_list - - return p -} - -func (s *Value_listContext) GetParser() antlr.Parser { return s.parser } - -func (s *Value_listContext) AllValue() []IValueContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(IValueContext); ok { - len++ - } - } - - tst := make([]IValueContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(IValueContext); ok { - tst[i] = t.(IValueContext) - i++ - } - } - - return tst -} - -func (s *Value_listContext) Value(i int) IValueContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IValueContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(IValueContext) -} - -func (s *Value_listContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Value_listContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Value_listContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterValue_list(s) - } -} - -func (s *Value_listContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitValue_list(s) - } -} - -func (p *QueryParser) Value_list() (localctx IValue_listContext) { - localctx = NewValue_listContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 78, QueryParserRULE_value_list) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(319) - p.Value() - } - p.SetState(324) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__7 { - { - p.SetState(320) - p.Match(QueryParserT__7) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(321) - p.Value() - } - - p.SetState(326) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// ISelect_clauseContext is an interface to support dynamic dispatch. -type ISelect_clauseContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - AllSelect_expression() []ISelect_expressionContext - Select_expression(i int) ISelect_expressionContext - - // IsSelect_clauseContext differentiates from other interfaces. - IsSelect_clauseContext() -} - -type Select_clauseContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptySelect_clauseContext() *Select_clauseContext { - var p = new(Select_clauseContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_clause - return p -} - -func InitEmptySelect_clauseContext(p *Select_clauseContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_clause -} - -func (*Select_clauseContext) IsSelect_clauseContext() {} - -func NewSelect_clauseContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Select_clauseContext { - var p = new(Select_clauseContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_select_clause - - return p -} - -func (s *Select_clauseContext) GetParser() antlr.Parser { return s.parser } - -func (s *Select_clauseContext) AllSelect_expression() []ISelect_expressionContext { - children := s.GetChildren() - len := 0 - for _, ctx := range children { - if _, ok := ctx.(ISelect_expressionContext); ok { - len++ - } - } - - tst := make([]ISelect_expressionContext, len) - i := 0 - for _, ctx := range children { - if t, ok := ctx.(ISelect_expressionContext); ok { - tst[i] = t.(ISelect_expressionContext) - i++ - } - } - - return tst -} - -func (s *Select_clauseContext) Select_expression(i int) ISelect_expressionContext { - var t antlr.RuleContext - j := 0 - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(ISelect_expressionContext); ok { - if j == i { - t = ctx.(antlr.RuleContext) - break - } - j++ - } - } - - if t == nil { - return nil - } - - return t.(ISelect_expressionContext) -} - -func (s *Select_clauseContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Select_clauseContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Select_clauseContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterSelect_clause(s) - } -} - -func (s *Select_clauseContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitSelect_clause(s) - } -} - -func (p *QueryParser) Select_clause() (localctx ISelect_clauseContext) { - localctx = NewSelect_clauseContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 80, QueryParserRULE_select_clause) - var _la int - - p.EnterOuterAlt(localctx, 1) - { - p.SetState(327) - p.Select_expression() - } - p.SetState(332) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - - for _la == QueryParserT__7 { - { - p.SetState(328) - p.Match(QueryParserT__7) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - { - p.SetState(329) - p.Select_expression() - } - - p.SetState(334) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} - -// ISelect_expressionContext is an interface to support dynamic dispatch. -type ISelect_expressionContext interface { - antlr.ParserRuleContext - - // GetParser returns the parser. - GetParser() antlr.Parser - - // Getter signatures - Variable() IVariableContext - Method_chain() IMethod_chainContext - STRING() antlr.TerminalNode - - // IsSelect_expressionContext differentiates from other interfaces. - IsSelect_expressionContext() -} - -type Select_expressionContext struct { - antlr.BaseParserRuleContext - parser antlr.Parser -} - -func NewEmptySelect_expressionContext() *Select_expressionContext { - var p = new(Select_expressionContext) - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_expression - return p -} - -func InitEmptySelect_expressionContext(p *Select_expressionContext) { - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1) - p.RuleIndex = QueryParserRULE_select_expression -} - -func (*Select_expressionContext) IsSelect_expressionContext() {} - -func NewSelect_expressionContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *Select_expressionContext { - var p = new(Select_expressionContext) - - antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState) - - p.parser = parser - p.RuleIndex = QueryParserRULE_select_expression - - return p -} - -func (s *Select_expressionContext) GetParser() antlr.Parser { return s.parser } - -func (s *Select_expressionContext) Variable() IVariableContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IVariableContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IVariableContext) -} - -func (s *Select_expressionContext) Method_chain() IMethod_chainContext { - var t antlr.RuleContext - for _, ctx := range s.GetChildren() { - if _, ok := ctx.(IMethod_chainContext); ok { - t = ctx.(antlr.RuleContext) - break - } - } - - if t == nil { - return nil - } - - return t.(IMethod_chainContext) -} - -func (s *Select_expressionContext) STRING() antlr.TerminalNode { - return s.GetToken(QueryParserSTRING, 0) -} - -func (s *Select_expressionContext) GetRuleContext() antlr.RuleContext { - return s -} - -func (s *Select_expressionContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string { - return antlr.TreesStringTree(s, ruleNames, recog) -} - -func (s *Select_expressionContext) EnterRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.EnterSelect_expression(s) - } -} - -func (s *Select_expressionContext) ExitRule(listener antlr.ParseTreeListener) { - if listenerT, ok := listener.(QueryListener); ok { - listenerT.ExitSelect_expression(s) - } -} - -func (p *QueryParser) Select_expression() (localctx ISelect_expressionContext) { - localctx = NewSelect_expressionContext(p, p.GetParserRuleContext(), p.GetState()) - p.EnterRule(localctx, 82, QueryParserRULE_select_expression) - p.SetState(338) - p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - - switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 30, p.GetParserRuleContext()) { - case 1: - p.EnterOuterAlt(localctx, 1) - { - p.SetState(335) - p.Variable() - } - - case 2: - p.EnterOuterAlt(localctx, 2) - { - p.SetState(336) - p.Method_chain() - } - - case 3: - p.EnterOuterAlt(localctx, 3) - { - p.SetState(337) - p.Match(QueryParserSTRING) - if p.HasError() { - // Recognition error - abort rule - goto errorExit - } - } - - case antlr.ATNInvalidAltNumber: - goto errorExit - } - -errorExit: - if p.HasError() { - v := p.GetError() - localctx.SetException(v) - p.GetErrorHandler().ReportError(p, v) - p.GetErrorHandler().Recover(p, v) - p.SetError(nil) - } - p.ExitRule() - return localctx - goto errorExit // Trick to prevent compiler error if the label is not used -} diff --git a/sourcecode-parser/cmd/ci.go b/sourcecode-parser/cmd/ci.go index 942a6b07..3a2fa798 100644 --- a/sourcecode-parser/cmd/ci.go +++ b/sourcecode-parser/cmd/ci.go @@ -1,304 +1,19 @@ package cmd import ( - "encoding/json" "fmt" - "io" - "net/http" - "os" - "path/filepath" - "strings" - - "github.com/owenrumney/go-sarif/v2/sarif" - - "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph" "github.com/spf13/cobra" ) -type Rule struct { - ID string `json:"id"` - Description string `json:"description"` - Impact string `json:"impact"` - Severity string `json:"severity"` - Passed bool `json:"passed" default:"true"` - Query string `json:"query"` - RuleProvider string `json:"ruleProvider"` -} - var ciCmd = &cobra.Command{ Use: "ci", - Short: "Scan a project for vulnerabilities with ruleset in ci mode", - Run: func(cmd *cobra.Command, _ []string) { - rulesetConfig := cmd.Flag("ruleset").Value.String() - projectInput := cmd.Flag("project").Value.String() - output := cmd.Flag("output").Value.String() - outputFile := cmd.Flag("output-file").Value.String() - verboseFlag, _ = cmd.Flags().GetBool("verbose") //nolint:all - - var ruleset []string - var outputResult []map[string]interface{} - var err error - - if verboseFlag { - fmt.Println("Executing in CI mode") - } - - if rulesetConfig == "" { - fmt.Println("ruleset are not specified. Please specify a ruleset eg: cpf/java or directory path") - os.Exit(1) - } - - if projectInput == "" { - fmt.Println("Project not specified") - os.Exit(1) - } - - ruleset, err = loadRules(rulesetConfig, strings.HasPrefix(rulesetConfig, "cpf/")) - if err != nil { - if verboseFlag { - fmt.Printf("%s - error loading rules or ruleset not found: \nStacktrace: \n%s \n", rulesetConfig, err) - } - os.Exit(1) - } - codeGraph := initializeProject(projectInput) - for _, rule := range ruleset { - queryInput := ParseQuery(rule) - rulesetResult := make(map[string]interface{}) - result, err := processQuery(queryInput.Query, codeGraph, output, 0, 0) - - if output == "json" || output == "sarif" { - var resultObject map[string]interface{} - json.Unmarshal([]byte(result), &resultObject) //nolint:all - rulesetResult["query"] = queryInput.Query - rulesetResult["rule"] = queryInput - rulesetResult["result"] = resultObject - outputResult = append(outputResult, rulesetResult) - } else { - fmt.Println(result) - } - if err != nil { - fmt.Println("Error processing query: ", err) - } - } - - // TODO: Add sarif file support - if output == "json" { - if outputFile != "" { - if graph.IsGitHubActions() { - // append GITHUB_WORKSPACE to output file path - outputFile = os.Getenv("GITHUB_WORKSPACE") + "/" + outputFile - } - file, err := os.Create(outputFile) - if err != nil { - fmt.Println("Error creating output file: ", err) - } - defer func(file *os.File) { - err := file.Close() - if err != nil { - fmt.Println("Error closing output file: ", err) - os.Exit(1) - } - }(file) - // convert outputResult to json - outputResultJSON, err := json.MarshalIndent(outputResult, "", " ") - if err != nil { - fmt.Println("Error converting output to json: ", err) - } - _, err = file.WriteString(string(outputResultJSON)) - if err != nil { - fmt.Println("Error writing output file: ", err) - } - } - } else if output == "sarif" { - sarifReport, err := generateSarifReport(outputResult) - if err != nil { - fmt.Println("Error generating sarif report: ", err) - os.Exit(1) - } - if graph.IsGitHubActions() { - // append GITHUB_WORKSPACE to output file path - outputFile = os.Getenv("GITHUB_WORKSPACE") + "/" + outputFile - } - if err := sarifReport.WriteFile(outputFile); err != nil { - fmt.Println("Error writing sarif report: ", err) - os.Exit(1) - } - } + Short: "CI mode - Python DSL implementation in progress", + RunE: func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("CI command not yet implemented in new architecture") }, } -func generateSarifReport(results []map[string]interface{}) (*sarif.Report, error) { - report, err := sarif.New(sarif.Version210) - if err != nil { - return nil, err - } - run := sarif.NewRunWithInformationURI("CodePathFinder", "https://codepathfinder.dev") - for _, result := range results { - localresult := result["result"].(map[string]interface{}) //nolint:all - resultSet := localresult["result_set"].([]interface{}) //nolint:all - pb := sarif.NewPropertyBag() - rule := result["rule"].(Rule) //nolint:all - pb.Add("impact", rule.Impact) - pb.Add("ruleProvider", rule.RuleProvider) - - run.AddRule(rule.ID). - WithDescription(rule.Description). - WithProperties(pb.Properties). - WithMarkdownHelp("# markdown") - - for _, finding := range resultSet { - findingMap := finding.(map[string]interface{}) //nolint:all - file, _ := findingMap["file"].(string) //nolint:all - line, _ := findingMap["line"].(float64) //nolint:all - // convert line to int - lineInt := int(line) - - run.CreateResultForRule(rule.ID). - WithLevel(strings.ToLower(rule.Severity)). - WithMessage(sarif.NewTextMessage(rule.Description)). - AddLocation( - sarif.NewLocationWithPhysicalLocation( - sarif.NewPhysicalLocation(). - WithArtifactLocation( - sarif.NewSimpleArtifactLocation(file), - ).WithRegion( - sarif.NewSimpleRegion(lineInt, lineInt), - ), - ), - ) - } - } - report.AddRun(run) - return report, nil -} - func init() { rootCmd.AddCommand(ciCmd) - ciCmd.Flags().StringP("output", "o", "", "Supported output format: json, sarif") - ciCmd.Flags().StringP("output-file", "f", "", "Output file path") - ciCmd.Flags().StringP("project", "p", "", "Source code to analyze") - ciCmd.Flags().StringP("ruleset", "r", "", "Ruleset to use example: cfp/java or directory path") -} - -func loadRules(rulesDirectory string, isHosted bool) ([]string, error) { - var rules []string - var err error - - if isHosted { - rules, err = downloadRuleset(rulesDirectory) - if err != nil { - return nil, err - } - } else { - err = filepath.Walk(rulesDirectory, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() && strings.HasSuffix(info.Name(), ".cql") { - contents, err := os.ReadFile(path) - if err != nil { - fmt.Printf("Error reading file %s: %v\n", path, err) - return nil - } - rules = append(rules, string(contents)) - } - return nil - }) - if err != nil { - return nil, fmt.Errorf("error walking through rules directory: %w", err) - } - } - - return rules, nil -} - -func downloadRuleset(ruleset string) ([]string, error) { - rules := []string{} - ruleset = strings.TrimPrefix(ruleset, "cpf/") - url := "https://codepathfinder.dev/rules/" + ruleset + ".json" - //nolint:all - resp, err := http.Get(url) - if err != nil { - err := fmt.Errorf("error downloading ruleset: %w", err) - return nil, err - } - defer resp.Body.Close() - // read response body - body, err := io.ReadAll(resp.Body) - if err != nil { - err := fmt.Errorf("error downloading ruleset: %w", err) - return nil, err - } - // parse response body - var response map[string]interface{} - err = json.Unmarshal(body, &response) - if err != nil { - err := fmt.Errorf("error downloading ruleset: %w", err) - return nil, err - } - // add rules to rules - if files, ok := response["files"].([]interface{}); ok { - for _, file := range files { - if rule, ok := file.(map[string]interface{}); ok { - if content, ok := rule["content"].(string); ok { - rules = append(rules, content) - } - } - } - } - return rules, nil -} - -func ParseQuery(query string) Rule { - // split query into lines - lines := strings.Split(query, "\n") - findLineFound := false - commentLineFound := false - query = "" - comment := "" - rule := Rule{} - for _, line := range lines { - // check if line starts with : - if strings.HasPrefix(strings.TrimSpace(line), "/*") { //nolint:all - comment += line - commentLineFound = true - } else if strings.HasPrefix(strings.TrimSpace(line), "predicate") || strings.HasPrefix(strings.TrimSpace(line), "FROM") { - findLineFound = true - query += line + " " - } else if findLineFound { - query += line + " " - } else if commentLineFound { - comment += line - key, value := ParseCommentLine(line) - switch key { - case "@id": - rule.ID = value - case "@description": - rule.Description = value - case "@problem.severity": - rule.Severity = value - case "@security-severity": - rule.Impact = value - case "@ruleprovider": - rule.RuleProvider = value - } - } else if strings.HasPrefix(strings.TrimSpace(line), "*/") { - commentLineFound = false - } - } - rule.Query = strings.TrimSpace(query) - return rule -} - -func ParseCommentLine(line string) (key, value string) { - // parse comment start with "* @name " - comment := strings.TrimSpace(line) - comment = strings.TrimPrefix(comment, "*") - comment = strings.TrimSpace(comment) - parts := strings.Split(comment, " ") - if len(parts) > 1 { - return parts[0], strings.Join(parts[1:], " ") - } - return "", "" } diff --git a/sourcecode-parser/cmd/ci_test.go b/sourcecode-parser/cmd/ci_test.go deleted file mode 100644 index 76df577c..00000000 --- a/sourcecode-parser/cmd/ci_test.go +++ /dev/null @@ -1,213 +0,0 @@ -package cmd - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" -) - -func TestCiCmd(t *testing.T) { - tests := []struct { - name string - args []string - expectedOutput string - }{ - { - name: "Basic CI command", - args: []string{"ci", "--help"}, - expectedOutput: "Scan a project for vulnerabilities with ruleset in ci mode\n\nUsage:\n pathfinder ci [flags]\n\nFlags:\n -h, --help help for ci\n -o, --output string Supported output format: json, sarif\n -f, --output-file string Output file path\n -p, --project string Source code to analyze\n -r, --ruleset string Ruleset to use example: cfp/java or directory path\n", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - cmd := &cobra.Command{Use: "pathfinder"} - cmd.AddCommand(ciCmd) - - b := bytes.NewBufferString("") - cmd.SetOut(b) - cmd.SetArgs(tt.args) - - err := cmd.Execute() - assert.NoError(t, err) - assert.Equal(t, tt.expectedOutput, b.String()) - }) - } -} - -func TestCiCmdFlags(t *testing.T) { - cmd := &cobra.Command{Use: "pathfinder"} - cmd.AddCommand(ciCmd) - - assert.NotNil(t, ciCmd) - assert.Equal(t, "ci", ciCmd.Use) - assert.Equal(t, "Scan a project for vulnerabilities with ruleset in ci mode", ciCmd.Short) -} - -func TestCiCmdAddedToRootCmd(t *testing.T) { - foundCiCmd := false - for _, cmd := range rootCmd.Commands() { - if cmd.Use == "ci" { - foundCiCmd = true - break - } - } - assert.True(t, foundCiCmd, "ci command should be added to root command") -} - -func TestParseQuery(t *testing.T) { - tests := []struct { - name string - input string - expected Rule - }{ - { - name: "Single predicate", - input: "predicate foo()\n{\n bar\n}", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "predicate foo() { bar }", RuleProvider: ""}, - }, - { - name: "Multiple predicates", - input: "some code\npredicate foo()\n{\n bar\n}\npredicate baz()\n{\n qux\n}", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "predicate foo() { bar } predicate baz() { qux }", RuleProvider: ""}}, - { - name: "FROM clause", - input: "SELECT *\nFROM table\nWHERE condition", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "FROM table WHERE condition", RuleProvider: ""}, - }, - { - name: "Mixed predicates and FROM", - input: "predicate foo()\n{\n bar\n}\nSELECT *\nFROM table\nWHERE condition", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "predicate foo() { bar } SELECT * FROM table WHERE condition", RuleProvider: ""}, - }, - { - name: "No matching lines", - input: "cmd.Rule(cmd.Rule{ID:\"\", Description:\"\", Impact:\"\", Severity:\"\", Passed:false, Query:\"\", RuleProvider:\"\"})", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "", RuleProvider: ""}, - }, - { - name: "Empty input", - input: "", - expected: Rule{ID: "", Description: "", Impact: "", Severity: "", Passed: false, Query: "", RuleProvider: ""}, - }, - { - name: "Single line comment", - input: "/**\n * @name Android WebView JavaScript settings\n * @description Enabling setAllowFileAccessFromFileURLs leak s&&box access to file:/// URLs.\n * @kind problem\n * @id java/Android/webview-javascript-enabled\n * @problem.severity warning\n * @security-severity 6.1\n * @precision medium\n * @tags security\n * external/cwe/cwe-079\n * @ruleprovider android\n */\nFROM method_invocation AS mi\nWHERE mi.getName() == \"setAllowFileAccessFromFileURLs\" && \"true\" in mi.getArgumentName()\nSELECT mi.getName(), \"File access enabled\"", - expected: Rule{ID: "java/Android/webview-javascript-enabled", Description: "Enabling setAllowFileAccessFromFileURLs leak s&&box access to file:/// URLs.", Impact: "6.1", Severity: "warning", Passed: false, Query: "FROM method_invocation AS mi WHERE mi.getName() == \"setAllowFileAccessFromFileURLs\" && \"true\" in mi.getArgumentName() SELECT mi.getName(), \"File access enabled\"", RuleProvider: "android"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := ParseQuery(tt.input) - assert.Equal(t, tt.expected, result) - }) - } -} - -func TestLoadRules(t *testing.T) { - tests := []struct { - name string - rulesDirectory string - isHosted bool - expectedRules int - expectError bool - }{ - { - name: "Local rules directory", - rulesDirectory: "../../pathfinder-rules", - isHosted: false, - expectedRules: 13, - expectError: false, - }, - { - name: "Hosted rules", - rulesDirectory: "cpf/java", - isHosted: true, - expectedRules: 7, - expectError: false, - }, - { - name: "Non-existent local directory", - rulesDirectory: "testdata/nonexistent", - isHosted: false, - expectedRules: 0, - expectError: true, - }, - { - name: "Invalid hosted URL", - rulesDirectory: "https://invalid.example.com/rules", - isHosted: true, - expectedRules: 0, - expectError: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - rules, err := loadRules(tt.rulesDirectory, tt.isHosted) - fmt.Println(len(rules)) - - if tt.expectError { - assert.Error(t, err) - } else { - assert.NoError(t, err) - assert.Len(t, rules, tt.expectedRules) - } - }) - } -} - -func TestLoadRulesLocalFileContent(t *testing.T) { - tempDir, err := os.MkdirTemp("", "rules_test") - assert.NoError(t, err) - defer os.RemoveAll(tempDir) - - testRule := "predicate test() { foo }" - err = os.WriteFile(filepath.Join(tempDir, "test.cql"), []byte(testRule), 0644) - assert.NoError(t, err) - - rules, err := loadRules(tempDir, false) - assert.NoError(t, err) - assert.Len(t, rules, 1) - assert.Equal(t, testRule, rules[0]) -} - -func TestLoadRulesIgnoreNonCQLFiles(t *testing.T) { - tempDir, err := os.MkdirTemp("", "rules_test") - assert.NoError(t, err) - defer os.RemoveAll(tempDir) - - err = os.WriteFile(filepath.Join(tempDir, "test.cql"), []byte("predicate test() { foo }"), 0644) - assert.NoError(t, err) - err = os.WriteFile(filepath.Join(tempDir, "ignore.txt"), []byte("This should be ignored"), 0644) - assert.NoError(t, err) - - rules, err := loadRules(tempDir, false) - assert.NoError(t, err) - assert.Len(t, rules, 1) -} - -func TestLoadRulesNestedDirectories(t *testing.T) { - tempDir, err := os.MkdirTemp("", "rules_test") - assert.NoError(t, err) - defer os.RemoveAll(tempDir) - - nestedDir := filepath.Join(tempDir, "nested") - err = os.Mkdir(nestedDir, 0755) - assert.NoError(t, err) - - err = os.WriteFile(filepath.Join(tempDir, "test1.cql"), []byte("predicate test1() { foo }"), 0644) - assert.NoError(t, err) - err = os.WriteFile(filepath.Join(nestedDir, "test2.cql"), []byte("predicate test2() { bar }"), 0644) - assert.NoError(t, err) - - rules, err := loadRules(tempDir, false) - assert.NoError(t, err) - assert.Len(t, rules, 2) -} diff --git a/sourcecode-parser/cmd/query.go b/sourcecode-parser/cmd/query.go index c6a0aa57..c8d667ed 100644 --- a/sourcecode-parser/cmd/query.go +++ b/sourcecode-parser/cmd/query.go @@ -1,280 +1,19 @@ package cmd import ( - "bufio" - "encoding/json" "fmt" - "os" - "sort" - "strings" - "github.com/fatih/color" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/analytics" - parser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph" "github.com/spf13/cobra" ) var queryCmd = &cobra.Command{ Use: "query", - Short: "Execute queries on the source code", - Run: func(cmd *cobra.Command, _ []string) { - // Implement query execution logic here - queryFile := cmd.Flag("query-file").Value.String() - queryInput := cmd.Flag("query").Value.String() - projectInput := cmd.Flag("project").Value.String() - output := cmd.Flag("output").Value.String() - outputFile := cmd.Flag("output-file").Value.String() - stdin, _ := cmd.Flags().GetBool("stdin") //nolint:all - page, _ := cmd.Flags().GetInt("page") - size, _ := cmd.Flags().GetInt("size") - - if queryFile != "" { - extractedQuery, err := ExtractQueryFromFile(queryFile) - if err != nil { - fmt.Println("Error extracting query from file:", err) - return - } - queryInput = extractedQuery - } - - result, err := executeCLIQuery(projectInput, queryInput, output, stdin, page, size) - if err != nil { - fmt.Println(err) - } - if outputFile != "" { - file, err := os.Create(outputFile) - if err != nil { - fmt.Println("Error creating output file: ", err) - } - defer func(file *os.File) { - err := file.Close() - if err != nil { - fmt.Println("Error closing output file: ", err) - os.Exit(1) - } - }(file) - _, err = file.WriteString(result) - if err != nil { - fmt.Println("Error writing output file: ", err) - } - } else { - fmt.Println(result) - } + Short: "Query mode - Python DSL implementation in progress", + RunE: func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("Query command not yet implemented in new architecture") }, } func init() { rootCmd.AddCommand(queryCmd) - queryCmd.Flags().StringP("output", "o", "", "Supported output format: json") - queryCmd.Flags().StringP("output-file", "f", "", "Output file path") - queryCmd.Flags().StringP("project", "p", "", "Project to analyze") - queryCmd.Flags().StringP("query", "q", "", "Query to execute") - queryCmd.Flags().Bool("stdin", false, "Read query from stdin") - queryCmd.Flags().String("query-file", "", "File containing query to execute") - // Pagination flags – optional. Page is 1‑based; size 0 disables pagination. - queryCmd.Flags().Int("page", 0, "Page number (1‑based, 0 for no pagination)") - queryCmd.Flags().Int("size", 0, "Page size (number of results per page, 0 for all)") -} - -func initializeProject(project string) *graph.CodeGraph { - codeGraph := graph.NewCodeGraph() - if project != "" { - codeGraph = graph.Initialize(project) - } - return codeGraph -} - -func executeCLIQuery(project, query, output string, stdin bool, page, size int) (string, error) { - codeGraph := initializeProject(project) - - if stdin { - // read from stdin - for { - fmt.Print("Path-Finder Query Console: \n>") - in := bufio.NewReader(os.Stdin) - - input, err := in.ReadString('\n') - analytics.ReportEvent(analytics.QueryCommandStdin) - if err != nil { - return "", fmt.Errorf("error processing query: %w", err) - } - // if input starts with :quit string - if strings.HasPrefix(input, ":quit") { - return "Okay, Bye!", nil - } - result, err := processQuery(input, codeGraph, output, page, size) - if err != nil { - analytics.ReportEvent(analytics.ErrorProcessingQuery) - err := fmt.Errorf("PathFinder Query syntax error: %w", err) - fmt.Println(err) - } else { - fmt.Println(result) - } - } - } else { - // read from command line - result, err := processQuery(query, codeGraph, output, page, size) - if err != nil { - analytics.ReportEvent(analytics.ErrorProcessingQuery) - return "", fmt.Errorf("PathFinder Query syntax error: %w", err) - } - return result, nil - } -} - -func processQuery(input string, codeGraph *graph.CodeGraph, output string, page, size int) (string, error) { - fmt.Println("Executing query: " + input) - parsedQuery, err := parser.ParseQuery(input) - if err != nil { - return "", err - } - parts := strings.SplitN(input, "WHERE", 2) - if len(parts) > 1 { - parsedQuery.Expression = strings.SplitN(parts[1], "SELECT", 2)[0] - } - entities, formattedOutput := graph.QueryEntities(codeGraph, parsedQuery) - - // Sort results deterministically for consistent pagination. - // Sorting by: File (primary), LineNumber (secondary), ID (tertiary). - // Need to keep entities and formattedOutput in sync during sort. - type resultPair struct { - entity []*graph.Node - output []interface{} - } - - // Combine entities and formattedOutput into pairs - pairs := make([]resultPair, len(entities)) - for i := range entities { - pairs[i] = resultPair{ - entity: entities[i], - output: formattedOutput[i], - } - } - - // Sort the pairs - sort.SliceStable(pairs, func(i, j int) bool { - // Get first node from each result set for comparison - if len(pairs[i].entity) == 0 || len(pairs[j].entity) == 0 { - return len(pairs[i].entity) > 0 - } - nodeI := pairs[i].entity[0] - nodeJ := pairs[j].entity[0] - - // Compare by File first - if nodeI.File != nodeJ.File { - return nodeI.File < nodeJ.File - } - // Then by LineNumber - if nodeI.LineNumber != nodeJ.LineNumber { - return nodeI.LineNumber < nodeJ.LineNumber - } - // Finally by ID for tie-breaking - return nodeI.ID < nodeJ.ID - }) - - // Split pairs back into entities and formattedOutput - for i := range pairs { - entities[i] = pairs[i].entity - formattedOutput[i] = pairs[i].output - } - - // Apply pagination if requested (page is 1‑based). If size == 0, return all. - if size > 0 && page > 0 { - total := len(entities) - start := (page - 1) * size - if start >= total { - // Empty result set for out‑of‑range page - entities = [][]*graph.Node{} - formattedOutput = [][]interface{}{} - } else { - end := start + size - if end > total { - end = total - } - entities = entities[start:end] - formattedOutput = formattedOutput[start:end] - } - } - if output == "json" || output == "sarif" { - analytics.ReportEvent(analytics.QueryCommandJSON) - // convert struct to query_results - results := make(map[string]interface{}) - results["result_set"] = make([]map[string]interface{}, 0) - results["output"] = formattedOutput - for _, entity := range entities { - for _, entityObject := range entity { - result := make(map[string]interface{}) - result["file"] = entityObject.File - result["line"] = entityObject.LineNumber - result["code"] = entityObject.GetCodeSnippet() - - results["result_set"] = append(results["result_set"].([]map[string]interface{}), result) //nolint:all - } - } - queryResults, err := json.Marshal(results) - if err != nil { - return "", fmt.Errorf("error processing query results: %w", err) - } - return string(queryResults), nil - } - result := "" - verticalLine := "|" - yellowCode := color.New(color.FgYellow).SprintFunc() - greenCode := color.New(color.FgGreen).SprintFunc() - for i, entity := range entities { - for _, entityObject := range entity { - header := fmt.Sprintf("\tFile: %s, Line: %s \n", greenCode(entityObject.File), greenCode(entityObject.LineNumber)) - // add formatted output to result - output := "\tResult: " - for _, outputObject := range formattedOutput[i] { - output += graph.FormatType(outputObject) - output += " " - output += verticalLine + " " - } - header += output + "\n" - result += header - result += "\n" - codeSnippetArray := strings.Split(entityObject.GetCodeSnippet(), "\n") - for i := 0; i < len(codeSnippetArray); i++ { - lineNumber := color.New(color.FgCyan).SprintfFunc()("%4d", int(entityObject.LineNumber)+i) - result += fmt.Sprintf("%s%s %s %s\n", strings.Repeat("\t", 2), lineNumber, verticalLine, yellowCode(codeSnippetArray[i])) - } - result += "\n" - } - } - return result, nil -} - -func ExtractQueryFromFile(file string) (string, error) { - // read from file - queryFileContent, err := os.Open(file) - if err != nil { - fmt.Println("Error opening file: ", err) - return "", err - } - defer func(queryFileContent *os.File) { - err := queryFileContent.Close() - if err != nil { - fmt.Println("Error closing file: ", err) - os.Exit(1) - } - }(queryFileContent) - query := "" - scanner := bufio.NewScanner(queryFileContent) - findLineFound := false - for scanner.Scan() { - line := scanner.Text() - if strings.HasPrefix(strings.TrimSpace(line), "predicate") || strings.HasPrefix(strings.TrimSpace(line), "FROM") { - findLineFound = true - query += line + " " - } else if findLineFound { - query += line + " " - } - } - query = strings.TrimSpace(query) - if err := scanner.Err(); err != nil { - return "", err - } - return query, nil } diff --git a/sourcecode-parser/cmd/query_test.go b/sourcecode-parser/cmd/query_test.go index fe379a5e..4cfc411d 100644 --- a/sourcecode-parser/cmd/query_test.go +++ b/sourcecode-parser/cmd/query_test.go @@ -1,468 +1,19 @@ package cmd import ( - "encoding/json" - "fmt" - "io" - "os" - "strings" "testing" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph" - "github.com/spf13/cobra" "github.com/stretchr/testify/assert" ) -func TestExecuteCLIQuery(t *testing.T) { - tests := []struct { - name string - project string - query string - output string - stdin bool - expectedOutput string - expectedError string - }{ - { - name: "Basic query", - project: "../../test-src/android", - query: "FROM method_declaration AS md WHERE md.getName() == \"onCreateOptionsMenu\" SELECT md.getName()", - output: "", - stdin: false, - expectedOutput: "File: ../../test-src/android/app/src/main/java/com/ivb/udacity/movieListActivity.java, Line: 96 \n\tResult: onCreateOptionsMenu | onCreateOptionsMenu | \n\n\t\t 96 | @Override\n\t\t 97 | public boolean onCreateOptionsMenu(Menu menu) {\n\t\t 98 | MenuInflater inflater = getMenuInflater();\n\t\t 99 | inflater.inflate(R.menu.main, menu);\n\t\t 100 | return true;\n\t\t 101 | }", - expectedError: "", - }, - { - name: "JSON output", - project: "../../test-src/android", - query: "FROM method_declaration AS md WHERE md.getName() == \"onCreateOptionsMenu\" SELECT md.getName()", - output: "json", - stdin: false, - expectedOutput: `{"output":[["onCreateOptionsMenu","onCreateOptionsMenu"]],"result_set":[{"code":"@Override\n public boolean onCreateOptionsMenu(Menu menu) {\n MenuInflater inflater = getMenuInflater();\n inflater.inflate(R.menu.main, menu);\n return true;\n }","file":"../../test-src/android/app/src/main/java/com/ivb/udacity/movieListActivity.java","line":96}]}`, - expectedError: "", - }, - } +func TestQueryCommandStub(t *testing.T) { + cmd := queryCmd - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result, err := executeCLIQuery(tt.project, tt.query, tt.output, tt.stdin, 0, 0) + assert.NotNil(t, cmd) + assert.Equal(t, "query", cmd.Use) - if tt.expectedError != "" { - assert.Error(t, err) - assert.Contains(t, err.Error(), tt.expectedError) - } else { - assert.NoError(t, err) - assert.Equal(t, tt.expectedOutput, strings.TrimSpace(result)) - } - }) - } -} - -func TestProcessQuery(t *testing.T) { - codeGraph := graph.NewCodeGraph() - codeGraph.AddNode(&graph.Node{ - Type: "method_declaration", - Name: "testFunc", - File: "test.java", - LineNumber: 5, - CodeSnippet: "public void testFunc() {}", - }) - - tests := []struct { - name string - input string - output string - expectedResult string - expectedError string - }{ - { - name: "Basic query", - input: "FROM method_declaration AS md WHERE md.getName() == \"testFunc\" SELECT md.getName()", - output: "", - expectedResult: "\tFile: test.java, Line: 5 \n\tResult: testFunc | testFunc | \n\n\t\t 5 | public void testFunc() {}\n\n", - expectedError: "", - }, - { - name: "JSON output", - input: "FROM method_declaration AS md WHERE md.getName() == \"testFunc\" SELECT md.getName()", - output: "json", - expectedResult: `{"output":[["testFunc","testFunc"]],"result_set":[{"code":"public void testFunc() {}","file":"test.java","line":5}]}`, - expectedError: "", - }, - { - name: "Basic query with predicate", - input: "predicate isTest(method_declaration md) { md.getName() == \"testFunc\" } FROM method_declaration AS md WHERE isTest(md) SELECT md.getName()", - output: "json", - expectedResult: `{"output":[["testFunc","testFunc"]],"result_set":[{"code":"public void testFunc() {}","file":"test.java","line":5}]}`, - expectedError: "", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result, err := processQuery(tt.input, codeGraph, tt.output, 0, 0) - - if tt.expectedError != "" { - assert.Error(t, err) - assert.Contains(t, err.Error(), tt.expectedError) - } else { - assert.NoError(t, err) - if tt.output == "json" { - var expectedJSON, resultJSON map[string]interface{} - fmt.Println(result) - err = json.Unmarshal([]byte(tt.expectedResult), &expectedJSON) - assert.NoError(t, err) - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - assert.Equal(t, expectedJSON, resultJSON) - } else { - assert.Equal(t, tt.expectedResult, result) - } - } - }) - } -} - -func TestExtractQueryFromFile(t *testing.T) { - tests := []struct { - name string - fileContent string - expectedQuery string - expectedError string - }{ - { - name: "Valid query file", - fileContent: ` - // This is a comment - FROM method_declaration AS md - WHERE md.getName() == "test" - AND md.getVisibility() == "public" - `, - expectedQuery: "FROM method_declaration AS md \t\t\t\tWHERE md.getName() == \"test\" \t\t\t\tAND md.getVisibility() == \"public\"", - expectedError: "", - }, - { - name: "Query file without FIND", - fileContent: ` - // This is a comment - SELECT function - WHERE name = 'test' - `, - expectedQuery: "", - expectedError: "", - }, - { - name: "Yet another valid query file", - fileContent: ` - // This is a comment - predicate isPublic(method_declaration md) { - md.getVisibility() == "public" - } - - FROM method_declaration AS md - WHERE md.getName() == "test" - AND isPublic(md) - `, - expectedQuery: "predicate isPublic(method_declaration md) { \t\t\t\t\tmd.getVisibility() == \"public\" \t\t\t\t} \t\t\t\tFROM method_declaration AS md \t\t\t\tWHERE md.getName() == \"test\" \t\t\t\tAND isPublic(md)", - expectedError: "", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tempFile, err := os.CreateTemp("", "query_*.txt") - assert.NoError(t, err) - defer os.Remove(tempFile.Name()) - - _, err = tempFile.WriteString(tt.fileContent) - assert.NoError(t, err) - tempFile.Close() - - result, err := ExtractQueryFromFile(tempFile.Name()) - - if tt.expectedError != "" { - assert.Error(t, err) - assert.Contains(t, err.Error(), tt.expectedError) - } else { - assert.NoError(t, err) - assert.Equal(t, tt.expectedQuery, result) - } - }) - } -} - -func TestQueryCmdFlags(t *testing.T) { - cmd := &cobra.Command{Use: "pathfinder"} - cmd.AddCommand(queryCmd) - - tests := []struct { - name string - flag string - expected string - }{ - {"output flag", "output", ""}, - {"output-file flag", "output-file", ""}, - {"project flag", "project", ""}, - {"query flag", "query", ""}, - {"stdin flag", "stdin", "false"}, - {"query-file flag", "query-file", ""}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - flag := queryCmd.Flag(tt.flag) - assert.NotNil(t, flag) - assert.Equal(t, tt.expected, flag.Value.String()) - }) - } -} - -func TestQueryCmdStdinInput(t *testing.T) { - oldStdin := os.Stdin - defer func() { os.Stdin = oldStdin }() - - input := ":quit\n" - r, w, _ := os.Pipe() - os.Stdin = r - - go func() { - _, _ = w.WriteString(input) - w.Close() - }() - - result, err := executeCLIQuery("../../test-src/android", "", "", true, 0, 0) - fmt.Println(result) - assert.NoError(t, err) - assert.Equal(t, "Okay, Bye!", result) - - _, _ = io.Copy(io.Discard, r) -} - -func TestPaginationFlags(t *testing.T) { - cmd := &cobra.Command{Use: "pathfinder"} - cmd.AddCommand(queryCmd) - - tests := []struct { - name string - flag string - expected string - }{ - {"page flag", "page", "0"}, - {"size flag", "size", "0"}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - flag := queryCmd.Flag(tt.flag) - assert.NotNil(t, flag) - assert.Equal(t, tt.expected, flag.Value.String()) - }) - } -} - -func TestPaginationSorting(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add nodes in non-sorted order to verify sorting works - codeGraph.AddNode(&graph.Node{ - ID: "3", - Type: "method_declaration", - Name: "methodC", - File: "b.java", - LineNumber: 10, - CodeSnippet: "public void methodC() {}", - }) - codeGraph.AddNode(&graph.Node{ - ID: "1", - Type: "method_declaration", - Name: "methodA", - File: "a.java", - LineNumber: 5, - CodeSnippet: "public void methodA() {}", - }) - codeGraph.AddNode(&graph.Node{ - ID: "2", - Type: "method_declaration", - Name: "methodB", - File: "a.java", - LineNumber: 15, - CodeSnippet: "public void methodB() {}", - }) - - // Query without pagination should return all results sorted - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 0, 0) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 3, len(resultSet)) - - // Verify results are sorted by File, then LineNumber - first := resultSet[0].(map[string]interface{}) - assert.Equal(t, "a.java", first["file"]) - assert.Equal(t, float64(5), first["line"]) - - second := resultSet[1].(map[string]interface{}) - assert.Equal(t, "a.java", second["file"]) - assert.Equal(t, float64(15), second["line"]) - - third := resultSet[2].(map[string]interface{}) - assert.Equal(t, "b.java", third["file"]) - assert.Equal(t, float64(10), third["line"]) -} - -func TestPaginationPage1(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add 5 nodes - for i := 1; i <= 5; i++ { - codeGraph.AddNode(&graph.Node{ - ID: fmt.Sprintf("%d", i), - Type: "method_declaration", - Name: fmt.Sprintf("method%d", i), - File: "test.java", - LineNumber: uint32(i * 10), - CodeSnippet: fmt.Sprintf("public void method%d() {}", i), - }) - } - - // Request page 1 with size 2 - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 1, 2) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 2, len(resultSet), "Page 1 with size 2 should return 2 results") - - // Verify first page contains first 2 results - first := resultSet[0].(map[string]interface{}) - assert.Equal(t, float64(10), first["line"]) - - second := resultSet[1].(map[string]interface{}) - assert.Equal(t, float64(20), second["line"]) -} - -func TestPaginationPage2(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add 5 nodes - for i := 1; i <= 5; i++ { - codeGraph.AddNode(&graph.Node{ - ID: fmt.Sprintf("%d", i), - Type: "method_declaration", - Name: fmt.Sprintf("method%d", i), - File: "test.java", - LineNumber: uint32(i * 10), - CodeSnippet: fmt.Sprintf("public void method%d() {}", i), - }) - } - - // Request page 2 with size 2 - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 2, 2) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 2, len(resultSet), "Page 2 with size 2 should return 2 results") - - // Verify second page contains next 2 results - first := resultSet[0].(map[string]interface{}) - assert.Equal(t, float64(30), first["line"]) - - second := resultSet[1].(map[string]interface{}) - assert.Equal(t, float64(40), second["line"]) -} - -func TestPaginationOutOfRange(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add only 3 nodes - for i := 1; i <= 3; i++ { - codeGraph.AddNode(&graph.Node{ - ID: fmt.Sprintf("%d", i), - Type: "method_declaration", - Name: fmt.Sprintf("method%d", i), - File: "test.java", - LineNumber: uint32(i * 10), - CodeSnippet: fmt.Sprintf("public void method%d() {}", i), - }) - } - - // Request page 5 with size 2 (out of range) - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 5, 2) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 0, len(resultSet), "Out of range page should return empty result set") -} - -func TestPaginationPartialLastPage(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add 5 nodes - for i := 1; i <= 5; i++ { - codeGraph.AddNode(&graph.Node{ - ID: fmt.Sprintf("%d", i), - Type: "method_declaration", - Name: fmt.Sprintf("method%d", i), - File: "test.java", - LineNumber: uint32(i * 10), - CodeSnippet: fmt.Sprintf("public void method%d() {}", i), - }) - } - - // Request page 3 with size 2 (should return only 1 result) - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 3, 2) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 1, len(resultSet), "Last page with partial results should return remaining items") - - // Verify it's the last result - first := resultSet[0].(map[string]interface{}) - assert.Equal(t, float64(50), first["line"]) -} - -func TestPaginationDisabled(t *testing.T) { - codeGraph := graph.NewCodeGraph() - - // Add 3 nodes - for i := 1; i <= 3; i++ { - codeGraph.AddNode(&graph.Node{ - ID: fmt.Sprintf("%d", i), - Type: "method_declaration", - Name: fmt.Sprintf("method%d", i), - File: "test.java", - LineNumber: uint32(i * 10), - CodeSnippet: fmt.Sprintf("public void method%d() {}", i), - }) - } - - // Request with page=0 and size=0 (pagination disabled) - result, err := processQuery("FROM method_declaration AS md SELECT md.getName()", codeGraph, "json", 0, 0) - assert.NoError(t, err) - - var resultJSON map[string]interface{} - err = json.Unmarshal([]byte(result), &resultJSON) - assert.NoError(t, err) - - resultSet := resultJSON["result_set"].([]interface{}) - assert.Equal(t, 3, len(resultSet), "Pagination disabled should return all results") + // Test execution returns error for unimplemented command + err := cmd.RunE(cmd, []string{}) + assert.Error(t, err) + assert.Contains(t, err.Error(), "not yet implemented") } diff --git a/sourcecode-parser/cmd/scan.go b/sourcecode-parser/cmd/scan.go index fd3e7818..9514847e 100644 --- a/sourcecode-parser/cmd/scan.go +++ b/sourcecode-parser/cmd/scan.go @@ -2,68 +2,18 @@ package cmd import ( "fmt" - "os" - "path/filepath" "github.com/spf13/cobra" ) var scanCmd = &cobra.Command{ Use: "scan", - Short: "Scan a project for vulnerabilities with ruleset", - Run: func(cmd *cobra.Command, _ []string) { - ruleset := cmd.Flag("ruleset").Value.String() - project := cmd.Flag("project").Value.String() - - if ruleset == "" { - fmt.Println("Please provide a ruleset directory path") - return - } - - if project == "" { - fmt.Println("Please provide a project directory path") - return - } - - queryFiles := getAllRulesetFile(ruleset) - - for _, queryFile := range queryFiles { - extractedQuery, err := ExtractQueryFromFile(queryFile) - if err != nil { - fmt.Println("Error extracting query from file:", err) - return - } - result, err := executeCLIQuery(project, extractedQuery, "json", false, 0, 0) - if err != nil { - fmt.Println(err) - } - fmt.Println(result) - } + Short: "Scan mode - Python DSL implementation in progress", + RunE: func(cmd *cobra.Command, args []string) error { + return fmt.Errorf("Scan command not yet implemented in new architecture") }, } -func getAllRulesetFile(directory string) []string { - var files []string - err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - if filepath.Ext(path) == ".cql" { - files = append(files, path) - } - } - return nil - }) - if err != nil { - fmt.Println("Please provide a valid ruleset directory path") - return nil - } - return files -} - func init() { rootCmd.AddCommand(scanCmd) - scanCmd.Flags().StringP("ruleset", "o", "", "Ruleset directory path") - scanCmd.Flags().StringP("project", "f", "", "project to scan path") } diff --git a/sourcecode-parser/cmd/scan_test.go b/sourcecode-parser/cmd/scan_test.go deleted file mode 100644 index 03508cdd..00000000 --- a/sourcecode-parser/cmd/scan_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package cmd - -import ( - "io" - "os" - "path/filepath" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" -) - -func TestScanCmd(t *testing.T) { - tests := []struct { - name string - rulesetDir string - projectDir string - expectedOutput string - }{ - { - name: "Missing ruleset", - rulesetDir: "", - projectDir: "testproject", - expectedOutput: "Please provide a ruleset directory path\n", - }, - { - name: "Missing project", - rulesetDir: "testruleset", - projectDir: "", - expectedOutput: "Please provide a project directory path\n", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - cmd := &cobra.Command{} - cmd.Flags().String("ruleset", tt.rulesetDir, "") - cmd.Flags().String("project", tt.projectDir, "") - - output := captureOutput(func() { - scanCmd.Run(cmd, []string{}) - }) - - assert.Contains(t, output, tt.expectedOutput) - }) - } -} - -func TestGetAllRulesetFile(t *testing.T) { - tempDir, err := os.MkdirTemp("", "ruleset_test") - assert.NoError(t, err) - defer os.RemoveAll(tempDir) - - // Create test files - validFiles := []string{"rule1.cql", "rule2.cql", "nested/rule3.cql"} - invalidFiles := []string{"invalid1.txt", "invalid2.json"} - - for _, file := range append(validFiles, invalidFiles...) { - path := filepath.Join(tempDir, file) - err := os.MkdirAll(filepath.Dir(path), 0o755) - assert.NoError(t, err) - _, err = os.Create(path) - assert.NoError(t, err) - } - - result := getAllRulesetFile(tempDir) - - assert.Equal(t, len(validFiles), len(result)) - for _, file := range validFiles { - assert.Contains(t, result, filepath.Join(tempDir, file)) - } - for _, file := range invalidFiles { - assert.NotContains(t, result, filepath.Join(tempDir, file)) - } -} - -func TestGetAllRulesetFileInvalidDirectory(t *testing.T) { - invalidDir := "/nonexistent/directory" - result := getAllRulesetFile(invalidDir) - assert.Nil(t, result) -} - -func captureOutput(f func()) string { - oldStdout := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - - f() - - w.Close() - out, _ := io.ReadAll(r) - os.Stdout = oldStdout - - return string(out) -} diff --git a/sourcecode-parser/go.mod b/sourcecode-parser/go.mod index eedb2923..ef45e169 100644 --- a/sourcecode-parser/go.mod +++ b/sourcecode-parser/go.mod @@ -5,8 +5,6 @@ go 1.25.3 require github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82 require ( - github.com/antlr4-go/antlr/v4 v4.13.1 - github.com/expr-lang/expr v1.17.6 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 github.com/posthog/posthog-go v1.6.11 @@ -14,21 +12,15 @@ require ( ) require ( - github.com/fatih/color v1.18.0 github.com/owenrumney/go-sarif/v2 v2.3.3 github.com/stretchr/testify v1.10.0 ) -require golang.org/x/exp v0.0.0-20251017212417-90e834f514db // indirect - require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/mattn/go-colorable v0.1.14 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.10 // indirect - golang.org/x/sys v0.37.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sourcecode-parser/go.sum b/sourcecode-parser/go.sum index f169ed21..14e05dfd 100644 --- a/sourcecode-parser/go.sum +++ b/sourcecode-parser/go.sum @@ -1,14 +1,8 @@ -github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= -github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/expr-lang/expr v1.17.6 h1:1h6i8ONk9cexhDmowO/A64VPxHScu7qfSl2k8OlINec= -github.com/expr-lang/expr v1.17.6/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4= -github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= -github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -25,10 +19,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= -github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/owenrumney/go-sarif v1.1.1/go.mod h1:dNDiPlF04ESR/6fHlPyq7gHKmrM0sHUvAGjsoh8ZH0U= github.com/owenrumney/go-sarif/v2 v2.3.3 h1:ubWDJcF5i3L/EIOER+ZyQ03IfplbSU1BLOE26uKQIIU= github.com/owenrumney/go-sarif/v2 v2.3.3/go.mod h1:MSqMMx9WqlBSY7pXoOZWgEsVB4FDNfhcaXDA1j6Sr+w= @@ -52,14 +42,9 @@ github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/exp v0.0.0-20251017212417-90e834f514db h1:by6IehL4BH5k3e3SJmcoNbOobMey2SLpAF79iPOEBvw= -golang.org/x/exp v0.0.0-20251017212417-90e834f514db/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/sourcecode-parser/graph/parser_python_test.go b/sourcecode-parser/graph/parser_python_test.go index 3e30a6ce..c145484c 100644 --- a/sourcecode-parser/graph/parser_python_test.go +++ b/sourcecode-parser/graph/parser_python_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - queryparser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr" sitter "github.com/smacker/go-tree-sitter" "github.com/smacker/go-tree-sitter/python" ) @@ -223,134 +222,3 @@ func TestParsePythonAssignment(t *testing.T) { } } -// TestPythonEndToEndQueryIntegration tests the full flow from parsing Python code to querying it. -func TestPythonEndToEndQueryIntegration(t *testing.T) { - pythonCode := ` -class Calculator: - """A simple calculator class""" - - def add(self, x, y): - """Add two numbers""" - return x + y - - def subtract(self, x, y): - """Subtract two numbers""" - return x - y - -def process_data(data): - """Process data function""" - return data * 2 -` - - parser := sitter.NewParser() - parser.SetLanguage(python.GetLanguage()) - defer parser.Close() - - tree, err := parser.ParseCtx(context.Background(), nil, []byte(pythonCode)) - if err != nil { - t.Fatalf("Failed to parse: %v", err) - } - defer tree.Close() - - graph := NewCodeGraph() - root := tree.RootNode() - buildGraphFromAST(root, []byte(pythonCode), graph, nil, "test.py") - - t.Run("Query Python classes", func(t *testing.T) { - query := queryparser.Query{ - SelectList: []queryparser.SelectList{{Entity: "class_definition", Alias: "c"}}, - Expression: "c.getName() == \"Calculator\"", - Condition: []string{ - "c.getName()==\"Calculator\"", - }, - } - - resultSet, _ := QueryEntities(graph, query) - if len(resultSet) != 1 { - t.Errorf("Expected 1 class, got %d", len(resultSet)) - } - - if len(resultSet) > 0 && resultSet[0][0].Name != "Calculator" { - t.Errorf("Expected class name 'Calculator', got %s", resultSet[0][0].Name) - } - }) - - t.Run("Query Python functions", func(t *testing.T) { - query := queryparser.Query{ - SelectList: []queryparser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "f.getName() == \"process_data\"", - Condition: []string{ - "f.getName()==\"process_data\"", - }, - } - - resultSet, _ := QueryEntities(graph, query) - if len(resultSet) != 1 { - t.Errorf("Expected 1 function, got %d", len(resultSet)) - } - - if len(resultSet) > 0 && resultSet[0][0].Name != "process_data" { - t.Errorf("Expected function name 'process_data', got %s", resultSet[0][0].Name) - } - }) - - t.Run("Query all Python functions", func(t *testing.T) { - query := queryparser.Query{ - SelectList: []queryparser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "", - Condition: []string{}, - } - - resultSet, _ := QueryEntities(graph, query) - // Should find: add, subtract, process_data (3 functions total) - if len(resultSet) < 3 { - t.Errorf("Expected at least 3 functions, got %d", len(resultSet)) - } - }) - - t.Run("Query Python functions with argument filtering", func(t *testing.T) { - query := queryparser.Query{ - SelectList: []queryparser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "len(f.getArgumentName()) == 3", - Condition: []string{ - "len(f.getArgumentName())==3", - }, - } - - resultSet, _ := QueryEntities(graph, query) - // Should find: add and subtract (both have self, x, y) - if len(resultSet) != 2 { - t.Errorf("Expected 2 functions with 3 arguments, got %d", len(resultSet)) - } - }) - - t.Run("Verify toString method works", func(t *testing.T) { - query := queryparser.Query{ - SelectList: []queryparser.SelectList{{Entity: "class_definition", Alias: "c"}}, - SelectOutput: []queryparser.SelectOutput{ - {Type: "variable", SelectEntity: "c"}, - }, - Expression: "c.getName() == \"Calculator\"", - Condition: []string{ - "c.getName()==\"Calculator\"", - }, - } - - resultSet, output := QueryEntities(graph, query) - if len(resultSet) != 1 { - t.Errorf("Expected 1 class, got %d", len(resultSet)) - } - - if len(output) != 1 { - t.Errorf("Expected 1 output, got %d", len(output)) - } - - // Verify that output doesn't contain error about missing toString - if len(output) > 0 && len(output[0]) > 0 { - outputStr, ok := output[0][0].(string) - if !ok || outputStr == "" { - t.Error("Expected non-empty string output from toString") - } - } - }) -} diff --git a/sourcecode-parser/graph/query.go b/sourcecode-parser/graph/query.go deleted file mode 100644 index 63a5cf3d..00000000 --- a/sourcecode-parser/graph/query.go +++ /dev/null @@ -1,936 +0,0 @@ -package graph - -import ( - "fmt" - "log" - "strings" - "sync" - - "github.com/expr-lang/expr" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/analytics" - parser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/model" -) - -type Env struct { - Node *Node -} - -func (env *Env) GetVisibility() string { - return env.Node.Modifier -} - -func (env *Env) GetAnnotations() []string { - return env.Node.Annotation -} - -func (env *Env) GetReturnType() string { - return env.Node.ReturnType -} - -func (env *Env) GetName() string { - return env.Node.Name -} - -func (env *Env) GetArgumentTypes() []string { - return env.Node.MethodArgumentsType -} - -func (env *Env) GetArgumentNames() []string { - return env.Node.MethodArgumentsValue -} - -func (env *Env) GetSuperClass() string { - return env.Node.SuperClass -} - -func (env *Env) GetInterfaces() []string { - return env.Node.Interface -} - -func (env *Env) GetScope() string { - return env.Node.Scope -} - -func (env *Env) GetVariableValue() string { - return env.Node.VariableValue -} - -func (env *Env) GetVariableDataType() string { - return env.Node.DataType -} - -func (env *Env) GetThrowsTypes() []string { - return env.Node.ThrowsExceptions -} - -func (env *Env) HasAccess() bool { - return env.Node.hasAccess -} - -func (env *Env) IsJavaSourceFile() bool { - return env.Node.isJavaSourceFile -} - -func (env *Env) GetDoc() *model.Javadoc { - if env.Node.JavaDoc == nil { - env.Node.JavaDoc = &model.Javadoc{} - } - return env.Node.JavaDoc -} - -func (env *Env) GetBinaryExpr() *model.BinaryExpr { - return env.Node.BinaryExpr -} - -func (env *Env) GetLeftOperand() string { - return env.Node.BinaryExpr.LeftOperand.NodeString -} - -func (env *Env) ToString() string { - return fmt.Sprintf("Node{Type: %s, Name: %s, Modifier: %s, Annotation: %v, ReturnType: %s, MethodArgumentsType: %v, MethodArgumentsValue: %v, SuperClass: %s, Interface: %v, Scope: %s, VariableValue: %s, DataType: %s, ThrowsExceptions: %v, hasAccess: %t, isJavaSourceFile: %t, JavaDoc: %+v, BinaryExpr: %+v}", - env.Node.Type, - env.Node.Name, - env.Node.Modifier, - env.Node.Annotation, - env.Node.ReturnType, - env.Node.MethodArgumentsType, - env.Node.MethodArgumentsValue, - env.Node.SuperClass, - env.Node.Interface, - env.Node.Scope, - env.Node.VariableValue, - env.Node.DataType, - env.Node.ThrowsExceptions, - env.Node.hasAccess, - env.Node.isJavaSourceFile, - env.Node.JavaDoc, - env.Node.BinaryExpr) -} - -func (env *Env) GetRightOperand() string { - return env.Node.BinaryExpr.RightOperand.NodeString -} - -func (env *Env) GetClassInstanceExpr() *model.ClassInstanceExpr { - return env.Node.ClassInstanceExpr -} - -func (env *Env) GetClassInstanceExprName() string { - return env.Node.ClassInstanceExpr.ClassName -} - -func (env *Env) GetIfStmt() *model.IfStmt { - return env.Node.IfStmt -} - -func (env *Env) GetWhileStmt() *model.WhileStmt { - return env.Node.WhileStmt -} - -func (env *Env) GetDoStmt() *model.DoStmt { - return env.Node.DoStmt -} - -func (env *Env) GetForStmt() *model.ForStmt { - return env.Node.ForStmt -} - -func (env *Env) GetBreakStmt() *model.BreakStmt { - return env.Node.BreakStmt -} - -func (env *Env) GetContinueStmt() *model.ContinueStmt { - return env.Node.ContinueStmt -} - -func (env *Env) GetYieldStmt() *model.YieldStmt { - return env.Node.YieldStmt -} - -func (env *Env) GetAssertStmt() *model.AssertStmt { - return env.Node.AssertStmt -} - -func (env *Env) GetReturnStmt() *model.ReturnStmt { - return env.Node.ReturnStmt -} - -func (env *Env) GetBlockStmt() *model.BlockStmt { - return env.Node.BlockStmt -} - -// Pool for small environment maps to reduce allocations. -var envMapPool = sync.Pool{ - New: func() interface{} { - return make(map[string]interface{}, 10) - }, -} - -// getEnvMapFromPool gets a map from the pool and clears it. -func getEnvMapFromPool() map[string]interface{} { - m := envMapPool.Get().(map[string]interface{}) - // Clear the map - for k := range m { - delete(m, k) - } - return m -} - -// returnEnvMapToPool returns a map to the pool. -func returnEnvMapToPool(m map[string]interface{}) { - if m != nil && len(m) < 100 { // Only pool reasonably-sized maps - envMapPool.Put(m) - } -} - -// buildEntityEnv creates the environment map for a specific entity type only. -// This avoids creating all 28 entity type maps when only 1 is needed. -func buildEntityEnv(proxyenv *Env, entityType string, _ string) map[string]interface{} { - switch entityType { - case "method_declaration": - return map[string]interface{}{ - "getVisibility": proxyenv.GetVisibility, - "getAnnotation": proxyenv.GetAnnotations, - "getReturnType": proxyenv.GetReturnType, - "getName": proxyenv.GetName, - "getArgumentType": proxyenv.GetArgumentTypes, - "getArgumentName": proxyenv.GetArgumentNames, - "getThrowsType": proxyenv.GetThrowsTypes, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - } - case "class_declaration": - return map[string]interface{}{ - "getSuperClass": proxyenv.GetSuperClass, - "getName": proxyenv.GetName, - "getAnnotation": proxyenv.GetAnnotations, - "getVisibility": proxyenv.GetVisibility, - "getInterface": proxyenv.GetInterfaces, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - } - case "method_invocation": - return map[string]interface{}{ - "getArgumentName": proxyenv.GetArgumentNames, - "getName": proxyenv.GetName, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - } - case "variable_declaration": - return map[string]interface{}{ - "getName": proxyenv.GetName, - "getVisibility": proxyenv.GetVisibility, - "getVariableValue": proxyenv.GetVariableValue, - "getVariableDataType": proxyenv.GetVariableDataType, - "getScope": proxyenv.GetScope, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - } - case "binary_expression": - return map[string]interface{}{ - "getLeftOperand": proxyenv.GetLeftOperand, - "getRightOperand": proxyenv.GetRightOperand, - "toString": proxyenv.ToString, - } - case "function_definition": - return map[string]interface{}{ - "getName": proxyenv.GetName, - "getArgumentName": proxyenv.GetArgumentNames, - "toString": proxyenv.ToString, - } - case "class_definition": - return map[string]interface{}{ - "getName": proxyenv.GetName, - "getInterface": proxyenv.GetInterfaces, - "toString": proxyenv.ToString, - } - case "add_expression", "sub_expression", "mul_expression", "div_expression": - op := "+" - switch entityType { - case "sub_expression": - op = "-" - case "mul_expression": - op = "*" - case "div_expression": - op = "/" - } - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": op, - "toString": proxyenv.ToString, - } - case "comparison_expression", "equal_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "==", - "toString": proxyenv.ToString, - } - case "not_equal_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "!=", - "toString": proxyenv.ToString, - } - case "remainder_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "%", - "toString": proxyenv.ToString, - } - case "right_shift_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": ">>", - "toString": proxyenv.ToString, - } - case "left_shift_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "<<", - "toString": proxyenv.ToString, - } - case "and_bitwise_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "&", - "toString": proxyenv.ToString, - } - case "and_logical_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "&&", - "toString": proxyenv.ToString, - } - case "or_logical_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "||", - "toString": proxyenv.ToString, - } - case "or_bitwise_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "|", - "toString": proxyenv.ToString, - } - case "unsigned_right_shift_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": ">>>", - "toString": proxyenv.ToString, - } - case "xor_bitwise_expression": - return map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "^", - "toString": proxyenv.ToString, - } - case "ClassInstanceExpr": - return map[string]interface{}{ - "getName": proxyenv.GetName, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - "getClassInstanceExpr": proxyenv.GetClassInstanceExpr, - } - case "IfStmt": - return map[string]interface{}{ - "getIfStmt": proxyenv.GetIfStmt, - "toString": proxyenv.ToString, - } - case "WhileStmt": - return map[string]interface{}{ - "getWhileStmt": proxyenv.GetWhileStmt, - "toString": proxyenv.ToString, - } - case "DoStmt": - return map[string]interface{}{ - "getDoStmt": proxyenv.GetDoStmt, - "toString": proxyenv.ToString, - } - case "ForStmt": - return map[string]interface{}{ - "getForStmt": proxyenv.GetForStmt, - "toString": proxyenv.ToString, - } - case "BreakStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getBreakStmt": proxyenv.GetBreakStmt, - } - case "ContinueStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getContinueStmt": proxyenv.GetContinueStmt, - } - case "YieldStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getYieldStmt": proxyenv.GetYieldStmt, - } - case "AssertStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getAssertStmt": proxyenv.GetAssertStmt, - } - case "ReturnStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getReturnStmt": proxyenv.GetReturnStmt, - } - case "BlockStmt": - return map[string]interface{}{ - "toString": proxyenv.ToString, - "getBlockStmt": proxyenv.GetBlockStmt, - } - default: - // Fallback for unknown types - return map[string]interface{}{ - "getName": proxyenv.GetName, - "toString": proxyenv.ToString, - } - } -} - -func QueryEntities(graph *CodeGraph, query parser.Query) (nodes [][]*Node, output [][]interface{}) { - result := make([][]*Node, 0) - - // log query select list alone - for _, entity := range query.SelectList { - analytics.ReportEvent(entity.Entity) - } - - cartesianProduct := generateCartesianProduct(graph, query.SelectList, query.Condition) - - for _, nodeSet := range cartesianProduct { - if FilterEntities(nodeSet, query) { - result = append(result, nodeSet) - } - } - output = generateOutput(result, query) - nodes = result - return nodes, output -} - -func generateOutput(nodeSet [][]*Node, query parser.Query) [][]interface{} { - results := make([][]interface{}, 0, len(nodeSet)) - for _, nodeSet := range nodeSet { - var result []interface{} - for _, outputFormat := range query.SelectOutput { - switch outputFormat.Type { - case "string": - outputFormat.SelectEntity = strings.ReplaceAll(outputFormat.SelectEntity, "\"", "") - result = append(result, outputFormat.SelectEntity) - case "method_chain", "variable": - if outputFormat.Type == "variable" { - outputFormat.SelectEntity += ".toString()" - } else if outputFormat.Type == "method_chain" { - if !strings.Contains(outputFormat.SelectEntity, ".") { - continue - } - } - response, err := evaluateExpression(nodeSet, outputFormat.SelectEntity, query) - if err != nil { - log.Print(err) - } - result = append(result, response) - } - } - results = append(results, result) - } - return results -} - -func evaluateExpression(node []*Node, expression string, query parser.Query) (interface{}, error) { - env := generateProxyEnvForSet(node, query) - defer returnEnvMapToPool(env) // Return to pool when done - - program, err := expr.Compile(expression, expr.Env(env)) - if err != nil { - Log("Error compiling expression: ", err) - return "", err - } - output, err := expr.Run(program, env) - if err != nil { - Log("Error evaluating expression: ", err) - return "", err - } - return output, nil -} - -func generateCartesianProduct(graph *CodeGraph, selectList []parser.SelectList, conditions []string) [][]*Node { - typeIndex := make(map[string][]*Node) - - // value and reference based reducing search space - for _, condition := range conditions { - // this code helps to reduce search space - // if there is single entity in select list, the condition is easy to reduce the search space - // if there are multiple entities in select list, the condition is hard to reduce the search space, - // but I have tried my best using O(n^2) time complexity to reduce the search space - if len(selectList) > 1 { - lhsNodes := graph.FindNodesByType(selectList[0].Entity) - rhsNodes := graph.FindNodesByType(selectList[1].Entity) - for _, lhsNode := range lhsNodes { - for _, rhsNode := range rhsNodes { - if FilterEntities([]*Node{lhsNode, rhsNode}, parser.Query{Expression: condition, SelectList: selectList}) { - typeIndex[lhsNode.Type] = appendUnique(typeIndex[lhsNode.Type], lhsNode) - typeIndex[rhsNode.Type] = appendUnique(typeIndex[rhsNode.Type], rhsNode) - } - } - } - } else { - filteredNodes := graph.FindNodesByType(selectList[0].Entity) - for _, node := range filteredNodes { - query := parser.Query{Expression: condition, SelectList: selectList} - if FilterEntities([]*Node{node}, query) { - typeIndex[node.Type] = appendUnique(typeIndex[node.Type], node) - } - } - } - } - - if len(conditions) == 0 { - for _, node := range graph.Nodes { - typeIndex[node.Type] = append(typeIndex[node.Type], node) - } - } - - sets := make([][]interface{}, 0, len(selectList)) - - for _, entity := range selectList { - set := make([]interface{}, 0) - if nodes, ok := typeIndex[entity.Entity]; ok { - for _, node := range nodes { - set = append(set, node) - } - } - sets = append(sets, set) - } - - product := cartesianProduct(sets) - - result := make([][]*Node, len(product)) - for i, p := range product { - result[i] = make([]*Node, len(p)) - for j, node := range p { - if n, ok := node.(*Node); ok { - result[i][j] = n - } else { - // Handle the error case, e.g., skip this node or log an error - // You might want to customize this part based on your error handling strategy - log.Printf("Warning: Expected *Node type, got %T", node) - } - } - } - - return result -} - -func cartesianProduct(sets [][]interface{}) [][]interface{} { - result := [][]interface{}{{}} - for _, set := range sets { - var newResult [][]interface{} - for _, item := range set { - for _, subResult := range result { - newSubResult := make([]interface{}, len(subResult), len(subResult)+1) - copy(newSubResult, subResult) - newSubResult = append(newSubResult, item) - newResult = append(newResult, newSubResult) - } - } - result = newResult - } - - return result -} - -func generateProxyEnv(node *Node, query parser.Query) map[string]interface{} { - proxyenv := Env{Node: node} - methodDeclaration := "method_declaration" - classDeclaration := "class_declaration" - methodInvocation := "method_invocation" - variableDeclaration := "variable_declaration" - binaryExpression := "binary_expression" - functionDefinition := "function_definition" - classDefinition := "class_definition" - addExpression := "add_expression" - subExpression := "sub_expression" - mulExpression := "mul_expression" - divExpression := "div_expression" - comparisionExpression := "comparison_expression" - remainderExpression := "remainder_expression" - rightShiftExpression := "right_shift_expression" - leftShiftExpression := "left_shift_expression" - notEqualExpression := "not_equal_expression" - equalExpression := "equal_expression" - andBitwiseExpression := "and_bitwise_expression" - andLogicalExpression := "and_logical_expression" - orLogicalExpression := "or_logical_expression" - orBitwiseExpression := "or_bitwise_expression" - unsignedRightShiftExpression := "unsigned_right_shift_expression" - xorBitwsieExpression := "xor_bitwise_expression" - classInstanceExpression := "ClassInstanceExpr" - ifStmt := "IfStmt" - whileStmt := "WhileStmt" - doStmt := "DoStmt" - forStmt := "ForStmt" - breakStmt := "BreakStmt" - continueStmt := "ContinueStmt" - yieldStmt := "YieldStmt" - assertStmt := "AssertStmt" - returnStmt := "ReturnStmt" - blockStmt := "BlockStmt" - - // print query select list - for _, entity := range query.SelectList { - switch entity.Entity { - case "method_declaration": - methodDeclaration = entity.Alias - case "class_declaration": - classDeclaration = entity.Alias - case "method_invocation": - methodInvocation = entity.Alias - case "variable_declaration": - variableDeclaration = entity.Alias - case "binary_expression": - binaryExpression = entity.Alias - case "function_definition": - functionDefinition = entity.Alias - case "class_definition": - classDefinition = entity.Alias - case "add_expression": - addExpression = entity.Alias - case "sub_expression": - subExpression = entity.Alias - case "mul_expression": - mulExpression = entity.Alias - case "div_expression": - divExpression = entity.Alias - case "comparison_expression": - comparisionExpression = entity.Alias - case "remainder_expression": - remainderExpression = entity.Alias - case "right_shift_expression": - rightShiftExpression = entity.Alias - case "left_shift_expression": - leftShiftExpression = entity.Alias - case "not_equal_expression": - notEqualExpression = entity.Alias - case "equal_expression": - equalExpression = entity.Alias - case "and_bitwise_expression": - andBitwiseExpression = entity.Alias - case "and_logical_expression": - andLogicalExpression = entity.Alias - case "or_logical_expression": - orLogicalExpression = entity.Alias - case "or_bitwise_expression": - orBitwiseExpression = entity.Alias - case "unsigned_right_shift_expression": - unsignedRightShiftExpression = entity.Alias - case "xor_bitwise_expression": - xorBitwsieExpression = entity.Alias - case "ClassInstanceExpr": - classInstanceExpression = entity.Alias - case "IfStmt": - ifStmt = entity.Alias - case "WhileStmt": - whileStmt = entity.Alias - case "DoStmt": - doStmt = entity.Alias - case "ForStmt": - forStmt = entity.Alias - case "BreakStmt": - breakStmt = entity.Alias - case "ContinueStmt": - continueStmt = entity.Alias - case "YieldStmt": - yieldStmt = entity.Alias - case "AssertStmt": - assertStmt = entity.Alias - case "ReturnStmt": - returnStmt = entity.Alias - case "BlockStmt": - blockStmt = entity.Alias - } - } - env := map[string]interface{}{ - "isJavaSourceFile": proxyenv.IsJavaSourceFile(), - methodDeclaration: map[string]interface{}{ - "getVisibility": proxyenv.GetVisibility, - "getAnnotation": proxyenv.GetAnnotations, - "getReturnType": proxyenv.GetReturnType, - "getName": proxyenv.GetName, - "getArgumentType": proxyenv.GetArgumentTypes, - "getArgumentName": proxyenv.GetArgumentNames, - "getThrowsType": proxyenv.GetThrowsTypes, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - }, - classDeclaration: map[string]interface{}{ - "getSuperClass": proxyenv.GetSuperClass, - "getName": proxyenv.GetName, - "getAnnotation": proxyenv.GetAnnotations, - "getVisibility": proxyenv.GetVisibility, - "getInterface": proxyenv.GetInterfaces, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - }, - methodInvocation: map[string]interface{}{ - "getArgumentName": proxyenv.GetArgumentNames, - "getName": proxyenv.GetName, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - }, - variableDeclaration: map[string]interface{}{ - "getName": proxyenv.GetName, - "getVisibility": proxyenv.GetVisibility, - "getVariableValue": proxyenv.GetVariableValue, - "getVariableDataType": proxyenv.GetVariableDataType, - "getScope": proxyenv.GetScope, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - }, - binaryExpression: map[string]interface{}{ - "getLeftOperand": proxyenv.GetLeftOperand, - "getRightOperand": proxyenv.GetRightOperand, - "toString": proxyenv.ToString, - }, - addExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "+", - "toString": proxyenv.ToString, - }, - subExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "-", - "toString": proxyenv.ToString, - }, - mulExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "*", - "toString": proxyenv.ToString, - }, - divExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "/", - "toString": proxyenv.ToString, - }, - comparisionExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "==", - "toString": proxyenv.ToString, - }, - remainderExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "%", - "toString": proxyenv.ToString, - }, - rightShiftExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": ">>", - "toString": proxyenv.ToString, - }, - leftShiftExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "<<", - "toString": proxyenv.ToString, - }, - notEqualExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "!=", - "toString": proxyenv.ToString, - }, - equalExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "==", - "toString": proxyenv.ToString, - }, - andBitwiseExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "&", - "toString": proxyenv.ToString, - }, - andLogicalExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "&&", - "toString": proxyenv.ToString, - }, - orLogicalExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "||", - "toString": proxyenv.ToString, - }, - orBitwiseExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "|", - "toString": proxyenv.ToString, - }, - unsignedRightShiftExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": ">>>", - "toString": proxyenv.ToString, - }, - xorBitwsieExpression: map[string]interface{}{ - "getBinaryExpr": proxyenv.GetBinaryExpr, - "getOperator": "^", - "toString": proxyenv.ToString, - }, - classInstanceExpression: map[string]interface{}{ - "getName": proxyenv.GetName, - "getDoc": proxyenv.GetDoc, - "toString": proxyenv.ToString, - "getClassInstanceExpr": proxyenv.GetClassInstanceExpr, - }, - ifStmt: map[string]interface{}{ - "getIfStmt": proxyenv.GetIfStmt, - "toString": proxyenv.ToString, - }, - whileStmt: map[string]interface{}{ - "getWhileStmt": proxyenv.GetWhileStmt, - "toString": proxyenv.ToString, - }, - doStmt: map[string]interface{}{ - "getDoStmt": proxyenv.GetDoStmt, - "toString": proxyenv.ToString, - }, - forStmt: map[string]interface{}{ - "getForStmt": proxyenv.GetForStmt, - "toString": proxyenv.ToString, - }, - breakStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getBreakStmt": proxyenv.GetBreakStmt, - }, - continueStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getContinueStmt": proxyenv.GetContinueStmt, - }, - yieldStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getYieldStmt": proxyenv.GetYieldStmt, - }, - assertStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getAssertStmt": proxyenv.GetAssertStmt, - }, - returnStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getReturnStmt": proxyenv.GetReturnStmt, - }, - blockStmt: map[string]interface{}{ - "toString": proxyenv.ToString, - "getBlockStmt": proxyenv.GetBlockStmt, - }, - functionDefinition: map[string]interface{}{ - "getName": proxyenv.GetName, - "getArgumentName": proxyenv.GetArgumentNames, - "toString": proxyenv.ToString, - }, - classDefinition: map[string]interface{}{ - "getName": proxyenv.GetName, - "getInterface": proxyenv.GetInterfaces, - "toString": proxyenv.ToString, - }, - } - return env -} - -func ReplacePredicateVariables(query parser.Query) string { - expression := query.Expression - if expression == "" { - return query.Expression - } - - for _, invokedPredicate := range query.PredicateInvocation { - predicateExpression := invokedPredicate.PredicateName + "(" - for i, param := range invokedPredicate.Parameter { - predicateExpression += param.Name + "," - for _, entity := range query.SelectList { - if entity.Alias == param.Name { - matchedPredicate := invokedPredicate.Predicate - invokedPredicate.Predicate.Body = strings.ReplaceAll(invokedPredicate.Predicate.Body, matchedPredicate.Parameter[i].Name, entity.Alias) - } - } - } - // remove the last comma - predicateExpression = predicateExpression[:len(predicateExpression)-1] - predicateExpression += ")" - invokedPredicate.Predicate.Body = "(" + invokedPredicate.Predicate.Body + ")" - expression = strings.ReplaceAll(expression, predicateExpression, invokedPredicate.Predicate.Body) - } - return expression -} - -func FilterEntities(node []*Node, query parser.Query) bool { - expression := query.Expression - if expression == "" { - return true - } - - env := generateProxyEnvForSet(node, query) - defer returnEnvMapToPool(env) // Return to pool when done - - expression = ReplacePredicateVariables(query) - - program, err := expr.Compile(expression, expr.Env(env)) - if err != nil { - Log("Error compiling expression: ", err) - return false - } - output, err := expr.Run(program, env) - if err != nil { - Log("Error evaluating expression: ", err) - return false - } - if output.(bool) { //nolint:all - return true - } - return false -} - -type classInstance struct { - Class *parser.ClassDeclaration - Methods map[string]string // method name -> result -} - -func generateProxyEnvForSet(nodeSet []*Node, query parser.Query) map[string]interface{} { - env := getEnvMapFromPool() - - for i, entity := range query.SelectList { - // Check if entity is a class type - classDecl := findClassDeclaration(entity.Entity, query.Classes) - if classDecl != nil { - env[entity.Alias] = createClassInstance(classDecl) - } else { - // OPTIMIZED: Only build the specific entity type map needed - // instead of creating all 28 entity type maps - proxyEnvWrapper := &Env{Node: nodeSet[i]} - env[entity.Alias] = buildEntityEnv(proxyEnvWrapper, entity.Entity, entity.Alias) - } - } - return env -} - -func findClassDeclaration(className string, classes []parser.ClassDeclaration) *parser.ClassDeclaration { - for _, class := range classes { - if class.Name == className { - return &class - } - } - return nil -} - -func createClassInstance(class *parser.ClassDeclaration) *classInstance { - instance := &classInstance{ - Class: class, - Methods: make(map[string]string), - } - - // Initialize method results - for _, method := range class.Methods { - instance.Methods[method.Name] = method.Body - } - - return instance -} diff --git a/sourcecode-parser/graph/query_test.go b/sourcecode-parser/graph/query_test.go deleted file mode 100644 index d259baa4..00000000 --- a/sourcecode-parser/graph/query_test.go +++ /dev/null @@ -1,577 +0,0 @@ -package graph - -import ( - "fmt" - "testing" - "time" - - parser "github.com/shivasurya/code-pathfinder/sourcecode-parser/antlr" - "github.com/shivasurya/code-pathfinder/sourcecode-parser/model" - "github.com/stretchr/testify/assert" -) - -func TestQueryEntities(t *testing.T) { - graph := NewCodeGraph() - node1 := &Node{ID: "abcd", Type: "method_declaration", Name: "testMethod", Modifier: "public"} - node2 := &Node{ID: "cdef", Type: "class_declaration", Name: "TestClass", Modifier: "private"} - graph.AddNode(node1) - graph.AddNode(node2) - - tests := []struct { - name string - query parser.Query - expected int - }{ - { - name: "Query with expression", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getVisibility() == \"public\"", - Condition: []string{ - "md.getVisibility()==\"public\"", - }, - }, - expected: 1, - }, - { - name: "Query with no results", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getVisibility() == \"private\"", - Condition: []string{ - "md.getVisibility()==\"private\"", - }, - }, - expected: 0, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - resultSet, output := QueryEntities(graph, tt.query) - fmt.Println(resultSet) - fmt.Println(output) - assert.Equal(t, tt.expected, len(resultSet)) - }) - } -} - -func TestFilterEntities(t *testing.T) { - tests := []struct { - name string - node *Node - query parser.Query - expected bool - }{ - { - name: "Filter method by visibility", - node: &Node{Type: "method_declaration", Modifier: "public"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getVisibility() == \"public\"", - }, - expected: true, - }, - { - name: "Filter class by name", - node: &Node{Type: "class_declaration", Name: "TestClass"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_declaration", Alias: "cd"}}, - Expression: "cd.getName() == \"TestClass\"", - }, - expected: true, - }, - { - name: "Filter method by return type", - node: &Node{Type: "method_declaration", ReturnType: "void"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getReturnType() == \"void\"", - }, - expected: true, - }, - { - name: "Filter variable by data type", - node: &Node{Type: "variable_declaration", DataType: "int"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "variable_declaration", Alias: "vd"}}, - Expression: "vd.getVariableDataType() == \"int\"", - }, - expected: true, - }, - { - name: "Filter with complex expression", - node: &Node{Type: "method_declaration", Modifier: "public", ReturnType: "String", Name: "getName"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getVisibility() == \"public\" && md.getReturnType() == \"String\" && md.getName() == \"getName\"", - }, - expected: true, - }, - { - name: "Filter with false condition", - node: &Node{Type: "method_declaration", Modifier: "private"}, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - Expression: "md.getVisibility() == \"public\"", - }, - expected: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := FilterEntities([]*Node{tt.node}, tt.query) - assert.Equal(t, tt.expected, result) - }) - } -} - -func TestGenerateProxyEnv(t *testing.T) { - node := &Node{ - Type: "method_declaration", - Name: "testMethod", - Modifier: "public", - ReturnType: "String", - MethodArgumentsType: []string{"int", "boolean"}, - MethodArgumentsValue: []string{"arg1", "arg2"}, - ThrowsExceptions: []string{"IOException"}, - JavaDoc: &model.Javadoc{}, - } - - query := parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "md"}}, - } - - env := generateProxyEnv(node, query) - assert.NotNil(t, env) - assert.Contains(t, env, "md") - methodEnv := env["md"].(map[string]interface{}) - - assert.NotNil(t, methodEnv["getVisibility"]) - assert.NotNil(t, methodEnv["getAnnotation"]) - assert.NotNil(t, methodEnv["getReturnType"]) - assert.NotNil(t, methodEnv["getName"]) - assert.NotNil(t, methodEnv["getArgumentType"]) - assert.NotNil(t, methodEnv["getArgumentName"]) - assert.NotNil(t, methodEnv["getThrowsType"]) - assert.NotNil(t, methodEnv["getDoc"]) - - visibility := methodEnv["getVisibility"].(func() string)() - assert.Equal(t, "public", visibility) - - name := methodEnv["getName"].(func() string)() - assert.Equal(t, "testMethod", name) - - returnType := methodEnv["getReturnType"].(func() string)() - assert.Equal(t, "String", returnType) - - argTypes := methodEnv["getArgumentType"].(func() []string)() - assert.Equal(t, []string{"int", "boolean"}, argTypes) - - argNames := methodEnv["getArgumentName"].(func() []string)() - assert.Equal(t, []string{"arg1", "arg2"}, argNames) - - throwsTypes := methodEnv["getThrowsType"].(func() []string)() - assert.Equal(t, []string{"IOException"}, throwsTypes) -} - -func TestCartesianProduct(t *testing.T) { - tests := []struct { - name string - input [][]interface{} - expected [][]interface{} - }{ - { - name: "Empty input", - input: [][]interface{}{}, - expected: [][]interface{}{{}}, - }, - { - name: "Single set", - input: [][]interface{}{{1, 2, 3}}, - expected: [][]interface{}{{1}, {2}, {3}}, - }, - { - name: "Two sets", - input: [][]interface{}{{1, 2}, {"a", "b"}}, - expected: [][]interface{}{{1, "a"}, {2, "a"}, {1, "b"}, {2, "b"}}, - }, - { - name: "Three sets", - input: [][]interface{}{{1, 2}, {"a", "b"}, {true, false}}, - expected: [][]interface{}{ - {1, "a", true}, {2, "a", true}, - {1, "b", true}, {2, "b", true}, - {1, "a", false}, {2, "a", false}, - {1, "b", false}, {2, "b", false}, - }, - }, - { - name: "Mixed types", - input: [][]interface{}{{1, "x"}, {true, 3.14}}, - expected: [][]interface{}{{1, true}, {"x", true}, {1, 3.14}, {"x", 3.14}}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := cartesianProduct(tt.input) - assert.Equal(t, tt.expected, result) - }) - } -} - -func TestCartesianProductLargeInput(t *testing.T) { - input := [][]interface{}{ - {1, 2, 3, 4, 5}, - {"a", "b", "c", "d", "e"}, - {true, false}, - } - result := cartesianProduct(input) - assert.Equal(t, 50, len(result)) - assert.Equal(t, 3, len(result[0])) -} - -func TestCartesianProductPerformance(t *testing.T) { - input := make([][]interface{}, 10) - for i := range input { - input[i] = make([]interface{}, 5) - for j := range input[i] { - input[i][j] = j - } - } - - start := time.Now() - result := cartesianProduct(input) - duration := time.Since(start) - - assert.Equal(t, 9765625, len(result)) - assert.Less(t, duration, 10*time.Second) -} - -// TestPythonClassDefinitionSupport tests that Python class_definition entities are properly supported. -func TestPythonClassDefinitionSupport(t *testing.T) { - graph := NewCodeGraph() - node := &Node{ - ID: "python_class_1", - Type: "class_definition", - Name: "Calculator", - Interface: []string{"object"}, - isPythonSourceFile: true, - } - graph.AddNode(node) - - tests := []struct { - name string - query parser.Query - expected int - }{ - { - name: "Query Python class by name", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - Expression: "c.getName() == \"Calculator\"", - Condition: []string{ - "c.getName()==\"Calculator\"", - }, - }, - expected: 1, - }, - { - name: "Query all Python classes", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - Expression: "", - Condition: []string{}, - }, - expected: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - resultSet, output := QueryEntities(graph, tt.query) - assert.Equal(t, tt.expected, len(resultSet)) - assert.NotNil(t, output) - }) - } -} - -// TestPythonFunctionDefinitionSupport tests that Python function_definition entities are properly supported. -func TestPythonFunctionDefinitionSupport(t *testing.T) { - graph := NewCodeGraph() - node := &Node{ - ID: "python_func_1", - Type: "function_definition", - Name: "process_data", - MethodArgumentsValue: []string{"data", "options"}, - isPythonSourceFile: true, - } - graph.AddNode(node) - - tests := []struct { - name string - query parser.Query - expected int - }{ - { - name: "Query Python function by name", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "f.getName() == \"process_data\"", - Condition: []string{ - "f.getName()==\"process_data\"", - }, - }, - expected: 1, - }, - { - name: "Query all Python functions", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "", - Condition: []string{}, - }, - expected: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - resultSet, output := QueryEntities(graph, tt.query) - assert.Equal(t, tt.expected, len(resultSet)) - assert.NotNil(t, output) - }) - } -} - -// TestGenerateProxyEnvForPythonClass tests that proxy environment is correctly generated for Python classes. -func TestGenerateProxyEnvForPythonClass(t *testing.T) { - node := &Node{ - Type: "class_definition", - Name: "TestClass", - Interface: []string{"BaseClass", "Mixin"}, - isPythonSourceFile: true, - } - - query := parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - } - - env := generateProxyEnv(node, query) - assert.NotNil(t, env) - assert.Contains(t, env, "c") - classEnv := env["c"].(map[string]interface{}) - - // Verify all expected methods are present - assert.NotNil(t, classEnv["getName"]) - assert.NotNil(t, classEnv["getInterface"]) - assert.NotNil(t, classEnv["toString"]) - - // Test getName - name := classEnv["getName"].(func() string)() - assert.Equal(t, "TestClass", name) - - // Test getInterface - interfaces := classEnv["getInterface"].(func() []string)() - assert.Equal(t, []string{"BaseClass", "Mixin"}, interfaces) - - // Test toString - toString := classEnv["toString"].(func() string)() - assert.Contains(t, toString, "TestClass") - assert.Contains(t, toString, "class_definition") -} - -// TestGenerateProxyEnvForPythonFunction tests that proxy environment is correctly generated for Python functions. -func TestGenerateProxyEnvForPythonFunction(t *testing.T) { - node := &Node{ - Type: "function_definition", - Name: "calculate", - MethodArgumentsValue: []string{"x", "y", "z"}, - isPythonSourceFile: true, - } - - query := parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - } - - env := generateProxyEnv(node, query) - assert.NotNil(t, env) - assert.Contains(t, env, "f") - funcEnv := env["f"].(map[string]interface{}) - - // Verify all expected methods are present - assert.NotNil(t, funcEnv["getName"]) - assert.NotNil(t, funcEnv["getArgumentName"]) - assert.NotNil(t, funcEnv["toString"]) - - // Test getName - name := funcEnv["getName"].(func() string)() - assert.Equal(t, "calculate", name) - - // Test getArgumentName - argNames := funcEnv["getArgumentName"].(func() []string)() - assert.Equal(t, []string{"x", "y", "z"}, argNames) - - // Test toString - toString := funcEnv["toString"].(func() string)() - assert.Contains(t, toString, "calculate") - assert.Contains(t, toString, "function_definition") -} - -// TestFilterPythonEntities tests filtering of Python entities. -func TestFilterPythonEntities(t *testing.T) { - tests := []struct { - name string - node *Node - query parser.Query - expected bool - }{ - { - name: "Filter Python class by name", - node: &Node{ - Type: "class_definition", - Name: "Calculator", - isPythonSourceFile: true, - }, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - Expression: "c.getName() == \"Calculator\"", - }, - expected: true, - }, - { - name: "Filter Python function by name", - node: &Node{ - Type: "function_definition", - Name: "process_data", - isPythonSourceFile: true, - }, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "f.getName() == \"process_data\"", - }, - expected: true, - }, - { - name: "Filter Python class with false condition", - node: &Node{ - Type: "class_definition", - Name: "TestClass", - isPythonSourceFile: true, - }, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - Expression: "c.getName() == \"DifferentClass\"", - }, - expected: false, - }, - { - name: "Filter Python function by arguments", - node: &Node{ - Type: "function_definition", - Name: "add", - MethodArgumentsValue: []string{"x", "y"}, - isPythonSourceFile: true, - }, - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - Expression: "len(f.getArgumentName()) == 2", - }, - expected: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := FilterEntities([]*Node{tt.node}, tt.query) - assert.Equal(t, tt.expected, result) - }) - } -} - -// TestMixedJavaAndPythonEntities tests querying both Java and Python entities. -func TestMixedJavaAndPythonEntities(t *testing.T) { - graph := NewCodeGraph() - - // Add Java class - javaClass := &Node{ - ID: "java_class_1", - Type: "class_declaration", - Name: "JavaClass", - Modifier: "public", - isJavaSourceFile: true, - } - graph.AddNode(javaClass) - - // Add Python class - pythonClass := &Node{ - ID: "python_class_1", - Type: "class_definition", - Name: "PythonClass", - isPythonSourceFile: true, - } - graph.AddNode(pythonClass) - - // Add Java method - javaMethod := &Node{ - ID: "java_method_1", - Type: "method_declaration", - Name: "javaMethod", - Modifier: "public", - isJavaSourceFile: true, - } - graph.AddNode(javaMethod) - - // Add Python function - pythonFunc := &Node{ - ID: "python_func_1", - Type: "function_definition", - Name: "python_function", - isPythonSourceFile: true, - } - graph.AddNode(pythonFunc) - - tests := []struct { - name string - query parser.Query - expected int - }{ - { - name: "Query only Java classes", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_declaration", Alias: "c"}}, - }, - expected: 1, - }, - { - name: "Query only Python classes", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "class_definition", Alias: "c"}}, - }, - expected: 1, - }, - { - name: "Query only Java methods", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "method_declaration", Alias: "m"}}, - }, - expected: 1, - }, - { - name: "Query only Python functions", - query: parser.Query{ - SelectList: []parser.SelectList{{Entity: "function_definition", Alias: "f"}}, - }, - expected: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - resultSet, _ := QueryEntities(graph, tt.query) - assert.Equal(t, tt.expected, len(resultSet)) - }) - } -} diff --git a/sourcecode-parser/main_test.go b/sourcecode-parser/main_test.go index 33cae261..cdac8417 100644 --- a/sourcecode-parser/main_test.go +++ b/sourcecode-parser/main_test.go @@ -23,7 +23,7 @@ func TestExecute(t *testing.T) { { name: "Successful execution", mockExecuteErr: nil, - expectedOutput: "Code Pathfinder is designed for identifying vulnerabilities in source code.\n\nUsage:\n pathfinder [command]\n\nAvailable Commands:\n analyze Analyze source code for security vulnerabilities using call graph\n ci Scan a project for vulnerabilities with ruleset in ci mode\n completion Generate the autocompletion script for the specified shell\n diagnose Validate intra-procedural taint analysis against LLM ground truth\n help Help about any command\n query Execute queries on the source code\n resolution-report Generate a diagnostic report on call resolution statistics\n scan Scan a project for vulnerabilities with ruleset\n version Print the version and commit information\n\nFlags:\n --disable-metrics Disable metrics collection\n -h, --help help for pathfinder\n --verbose Verbose output\n\nUse \"pathfinder [command] --help\" for more information about a command.\n", + expectedOutput: "Code Pathfinder is designed for identifying vulnerabilities in source code.\n\nUsage:\n pathfinder [command]\n\nAvailable Commands:\n analyze Analyze source code for security vulnerabilities using call graph\n ci CI mode - Python DSL implementation in progress\n completion Generate the autocompletion script for the specified shell\n diagnose Validate intra-procedural taint analysis against LLM ground truth\n help Help about any command\n query Query mode - Python DSL implementation in progress\n resolution-report Generate a diagnostic report on call resolution statistics\n scan Scan mode - Python DSL implementation in progress\n version Print the version and commit information\n\nFlags:\n --disable-metrics Disable metrics collection\n -h, --help help for pathfinder\n --verbose Verbose output\n\nUse \"pathfinder [command] --help\" for more information about a command.\n", expectedExit: 0, }, }