• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 %name PreprocessorGrammarParse
18 %token_prefix PPTK_
19 %start_symbol input
20 
21 %include {
22 #include "src/trace_processor/perfetto_sql/preprocessor/preprocessor_grammar_interface.h"
23 
24 #define YYNOERRORRECOVERY 1
25 #define YYPARSEFREENEVERNULL 1
26 }
27 
28 %token_type {struct PreprocessorGrammarToken}
29 %default_type {struct PreprocessorGrammarTokenBounds}
30 
31 %extra_context {struct PreprocessorGrammarState* state}
32 %syntax_error {
33   OnPreprocessorSyntaxError(state, &yyminor);
34 }
35 
36 input ::= cmd.  {
37   OnPreprocessorEnd(state);
38 }
39 
40 cmd ::= sql SEMI.
41 cmd ::= apply SEMI.
42 
43 apply ::= APPLY COMMA|AND(J) TRUE|FALSE(P) ID(X) LP applylist(Y) RP. {
44   OnPreprocessorApply(state, &X, &J, &P, Y, 0);
45 }
46 apply ::= APPLY COMMA|AND(J) TRUE|FALSE(P) ID(X) LP applylist(Y) RP LP applylist(Z) RP. {
47   OnPreprocessorApply(state, &X, &J, &P, Y, Z);
48 }
49 
50 %type applylist {struct PreprocessorGrammarApplyList*}
51 %destructor applylist { OnPreprocessorFreeApplyList(state, $$); }
52 applylist(A) ::= applylist(F) COMMA tokenlist(X). {
53   A = OnPreprocessorAppendApplyList(F, &X);
54 }
55 applylist(A) ::= tokenlist(F). {
56   A = OnPreprocessorAppendApplyList(OnPreprocessorCreateApplyList(), &F);
57 }
58 applylist(A) ::=. {
59   A = OnPreprocessorCreateApplyList();
60 }
61 
62 sql ::= sql sqltoken.
63 sql ::= sqltoken.
64 
65 sqltoken ::= COMMA.
66 sqltoken ::= commalesssqltoken.
67 
68 commalesssqltoken(A) ::= OPAQUE(X). {
69   A = (struct PreprocessorGrammarTokenBounds) {X, X};
70 }
71 commalesssqltoken(A) ::= minvocationid(S) EXCLAIM LP marglist RP(F). {
72   A = (struct PreprocessorGrammarTokenBounds) {S, F};
73   OnPreprocessorMacroEnd(state, &S, &F);
74 }
75 commalesssqltoken(A) ::= LP(S) sql RP(F).  {
76   A = (struct PreprocessorGrammarTokenBounds) {S, F};
77 }
78 commalesssqltoken(A) ::= LP(S) RP(F). {
79   A = (struct PreprocessorGrammarTokenBounds) {S, F};
80 }
81 commalesssqltoken(A) ::= ID(X). {
82   A = (struct PreprocessorGrammarTokenBounds) {X, X};
83 }
84 commalesssqltoken(A) ::= VARIABLE(X). {
85   A = (struct PreprocessorGrammarTokenBounds) {X, X};
86   OnPreprocessorVariable(state, &X);
87 }
88 
89 %type minvocationid {struct PreprocessorGrammarToken}
90 minvocationid(A) ::= ID(X). {
91   A = X;
92   OnPreprocessorMacroId(state, &X);
93 }
94 
95 marglist ::= marglistinner.
96 marglist ::=.
97 
98 marglistinner ::= marglistinner COMMA marg.
99 marglistinner ::= marg.
100 
101 marg ::= tokenlist(X). {
102   OnPreprocessorMacroArg(state, &X);
103 }
104 
105 tokenlist(A) ::= tokenlist(S) commalesssqltoken(F). {
106   A = (struct PreprocessorGrammarTokenBounds) {S.start, F.end};
107 }
108 tokenlist(A) ::= commalesssqltoken(X). {
109   A = (struct PreprocessorGrammarTokenBounds) {X.start, X.end};
110 }
111