• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2025 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15@top Program { expression* }
16
17expression {
18  String |
19  Number |
20  Boolean |
21  Keyword |
22  Function |
23  MacroVariable |
24  Identifier
25}
26
27Keyword {
28  @specialize<Identifier,
29    "select" |
30    "perfetto" |
31    "table" |
32    "from" |
33    "where" |
34    "and" |
35    "or" |
36    "join" |
37    "on" |
38    "as" |
39    "create" |
40    "replace" |
41    "view" |
42    "with" |
43    "limit" |
44    "include" |
45    "module" |
46    "function" |
47    "returns" |
48    "values" |
49    "macro" |
50    "between" |
51    "glob" |
52    "order" |
53    "group" |
54    "by" |
55    "having" |
56    "over" |
57    "partition" |
58    "using" |
59    "union" |
60    "all" |
61
62    "SELECT" |
63    "PERFETTO" |
64    "TABLE" |
65    "FROM" |
66    "WHERE" |
67    "AND" |
68    "OR" |
69    "JOIN" |
70    "ON" |
71    "AS" |
72    "CREATE" |
73    "REPLACE" |
74    "VIEW" |
75    "WITH" |
76    "LIMIT" |
77    "INCLUDE" |
78    "MODULE" |
79    "FUNCTION" |
80    "RETURNS" |
81    "VALUES" |
82    "MACRO" |
83    "BETWEEN" |
84    "GLOB" |
85    "ORDER" |
86    "GROUP" |
87    "BY" |
88    "HAVING" |
89    "OVER" |
90    "PARTITION" |
91    "USING" |
92    "UNION" |
93    "ALL"
94  >
95}
96
97Function {
98  @specialize<Identifier,
99    "sum" |
100    "min" |
101    "max" |
102    "count" |
103    "avg" |
104    "total" |
105    "group_concat" |
106    "first" |
107    "last" |
108    "row_number" |
109    "rank" |
110    "dense_rank" |
111    "percent_rank" |
112    "cume_dist" |
113    "ntile" |
114    "lag" |
115    "lead" |
116    "first_value" |
117    "last_value" |
118    "nth_value" |
119    "ifnull" |
120
121    "SUM" |
122    "MIN" |
123    "MAX" |
124    "COUNT" |
125    "AVG" |
126    "TOTAL" |
127    "GROUP_CONCAT" |
128    "FIRST" |
129    "LAST" |
130    "ROW_NUMBER" |
131    "RANK" |
132    "DENSE_RANK" |
133    "PERCENT_RANK" |
134    "CUME_DIST" |
135    "NTILE" |
136    "LAG" |
137    "LEAD" |
138    "FIRST_VALUE" |
139    "LAST_VALUE" |
140    "NTH_VALUE" |
141    "IFNULL"
142  >
143}
144
145Boolean {
146  @specialize<Identifier,
147    "TRUE" | "true" |
148    "FALSE" | "false"
149  >
150}
151
152@tokens {
153  String { "'" (![\'\\] | "\\" _)* "'" }
154  Number { $[0-9]+ }
155  MacroVariable { "$" $[$0-9a-zA-Z_]* }
156  LineComment { "--" ![\n]* }
157  Identifier { $[a-zA-Z_] $[$0-9a-zA-Z_.]* }
158  space { $[ \t\n\r]+ }
159  "(" ")"
160}
161
162@skip { space | LineComment }
163
164@detectDelim
165
166//! To build, run:
167//! lezer-generator ui/src/base/perfetto_sql_lang/perfetto_sql.grammar -o ui/src/base/perfetto_sql_lang/perfetto_sql.grammar.js