Skip to content

Commit a6deff0

Browse files
dmitriplotnikovcopybara-github
authored andcommitted
[Pratt Parser] Add deep copy/replace functionality to AstFactoryInterface
PiperOrigin-RevId: 944578347
1 parent 05556a0 commit a6deff0

16 files changed

Lines changed: 4464 additions & 12 deletions

common/expr_factory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ namespace tools {
3838
class ProtoToPredicateBuilder;
3939
}
4040

41+
namespace parser_internal {
42+
template <typename ExprNode>
43+
class AstFactoryInterface;
44+
}
45+
4146
class ExprFactory {
4247
protected:
4348
// `IsExprLike` determines whether `T` is some `Expr`. Currently that means
@@ -385,6 +390,7 @@ class ExprFactory {
385390
friend class ParserMacroExprFactory;
386391
friend class OptimizerExprFactory;
387392
friend class tools::ProtoToPredicateBuilder;
393+
friend class parser_internal::AstFactoryInterface<Expr>;
388394

389395
ExprFactory() : accu_var_(kAccumulatorVariableName) {}
390396

parser/internal/BUILD

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@
1313
# limitations under the License.
1414

1515
load("@rules_cc//cc:cc_library.bzl", "cc_library")
16+
load("@rules_cc//cc:cc_test.bzl", "cc_test")
1617
load("//bazel:antlr.bzl", "antlr_cc_library")
1718

1819
package(default_visibility = ["//visibility:public"])
1920

2021
licenses(["notice"])
2122

23+
cc_library(
24+
name = "ast_factory_interface",
25+
hdrs = ["ast_factory_interface.h"],
26+
)
27+
28+
cc_library(
29+
name = "ast_factory",
30+
hdrs = ["ast_factory.h"],
31+
deps = [
32+
":ast_factory_interface",
33+
"//common:constant",
34+
"//common:expr",
35+
"//common:expr_factory",
36+
"@com_google_absl//absl/strings:string_view",
37+
],
38+
)
39+
2240
cc_library(
2341
name = "options",
2442
hdrs = ["options.h"],
@@ -29,3 +47,133 @@ antlr_cc_library(
2947
src = "Cel.g4",
3048
package = "cel_parser_internal",
3149
)
50+
51+
cc_library(
52+
name = "lexer",
53+
srcs = ["lexer.cc"],
54+
hdrs = ["lexer.h"],
55+
deps = [
56+
"@com_google_absl//absl/base:core_headers",
57+
"@com_google_absl//absl/base:no_destructor",
58+
"@com_google_absl//absl/base:nullability",
59+
"@com_google_absl//absl/container:flat_hash_map",
60+
"@com_google_absl//absl/functional:function_ref",
61+
"@com_google_absl//absl/log:absl_check",
62+
"@com_google_absl//absl/strings",
63+
"@com_google_absl//absl/strings:string_view",
64+
],
65+
)
66+
67+
cc_library(
68+
name = "pratt_parser_worker",
69+
srcs = ["pratt_parser_worker.cc"],
70+
hdrs = ["pratt_parser_worker.h"],
71+
deps = [
72+
":ast_factory_interface",
73+
":lexer",
74+
"//common:operators",
75+
"//common:source",
76+
"//internal:lexis",
77+
"//internal:strings",
78+
"//parser:options",
79+
"//parser:parser_interface",
80+
"@com_google_absl//absl/base:nullability",
81+
"@com_google_absl//absl/container:flat_hash_map",
82+
"@com_google_absl//absl/log:absl_check",
83+
"@com_google_absl//absl/status:statusor",
84+
"@com_google_absl//absl/strings",
85+
"@com_google_absl//absl/strings:str_format",
86+
"@com_google_absl//absl/types:optional",
87+
],
88+
)
89+
90+
cc_library(
91+
name = "pratt_parser",
92+
srcs = ["pratt_parser.cc"],
93+
hdrs = ["pratt_parser.h"],
94+
deps = [
95+
":ast_factory",
96+
":pratt_parser_worker",
97+
"//common:ast",
98+
"//common:expr",
99+
"//common:source",
100+
"//internal:status_macros",
101+
"//parser:macro",
102+
"//parser:macro_registry",
103+
"//parser:options",
104+
"//parser:parser_interface",
105+
"@com_google_absl//absl/base:nullability",
106+
"@com_google_absl//absl/cleanup",
107+
"@com_google_absl//absl/container:flat_hash_map",
108+
"@com_google_absl//absl/container:flat_hash_set",
109+
"@com_google_absl//absl/log:absl_check",
110+
"@com_google_absl//absl/status",
111+
"@com_google_absl//absl/status:statusor",
112+
"@com_google_absl//absl/strings",
113+
"@com_google_absl//absl/strings:str_format",
114+
"@com_google_absl//absl/types:span",
115+
],
116+
)
117+
118+
cc_test(
119+
name = "ast_factory_test",
120+
srcs = ["ast_factory_test.cc"],
121+
deps = [
122+
":ast_factory",
123+
"//common:constant",
124+
"//common:expr",
125+
"//internal:testing",
126+
"@com_google_absl//absl/strings:string_view",
127+
],
128+
)
129+
130+
cc_test(
131+
name = "lexer_test",
132+
srcs = ["lexer_test.cc"],
133+
deps = [
134+
":lexer",
135+
"//internal:testing",
136+
],
137+
)
138+
139+
cc_test(
140+
name = "pratt_parser_test",
141+
srcs = ["pratt_parser_test.cc"],
142+
deps = [
143+
":lexer",
144+
":pratt_parser",
145+
":pratt_parser_worker",
146+
"//common:ast",
147+
"//common:constant",
148+
"//common:expr",
149+
"//common:source",
150+
"//internal:status_macros",
151+
"//internal:testing",
152+
"//parser:options",
153+
"//parser:parser_interface",
154+
"//testutil:expr_printer",
155+
"@com_google_absl//absl/status",
156+
"@com_google_absl//absl/status:status_matchers",
157+
"@com_google_absl//absl/status:statusor",
158+
"@com_google_absl//absl/strings",
159+
"@com_google_absl//absl/strings:str_format",
160+
"@com_google_absl//absl/strings:string_view",
161+
],
162+
)
163+
164+
cc_test(
165+
name = "pratt_parser_benchmark",
166+
srcs = ["pratt_parser_benchmark.cc"],
167+
tags = ["benchmark"],
168+
deps = [
169+
":pratt_parser",
170+
"//common:source",
171+
"//internal:benchmark",
172+
"//internal:testing",
173+
"//parser",
174+
"//parser:options",
175+
"//parser:parser_interface",
176+
"@com_google_absl//absl/log:absl_check",
177+
"@com_google_absl//absl/strings",
178+
],
179+
)

0 commit comments

Comments
 (0)