Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
Expr,
Expr_CreateStruct_Entry,
SourceInfo,
} from "./external/proto/dev/cel/expr/syntax_pb.ts";
} from "./external/cel/expr/syntax_pb.ts";

const encoder = new TextEncoder();

Expand Down Expand Up @@ -128,19 +128,20 @@ class Builder {
#prevId = 0n;

sourceInfo: SourceInfo = {
$typeName: "dev.cel.expr.SourceInfo",
$typeName: "cel.expr.SourceInfo",
syntaxVersion: "",
location: "",
lineOffsets: [],
positions: {},
macroCalls: {},
extensions: [],
};

nextExpr(offset: number, exprKind: Expr["exprKind"]): Expr {
this.sourceInfo.positions[(++this.#prevId).toString()] = offset;

return {
$typeName: "dev.cel.expr.Expr",
$typeName: "cel.expr.Expr",
id: this.#prevId,
exprKind,
};
Expand All @@ -154,7 +155,7 @@ class Builder {
this.sourceInfo.positions[(++this.#prevId).toString()] = offset;

return {
$typeName: "dev.cel.expr.Expr.CreateStruct.Entry",
$typeName: "cel.expr.Expr.CreateStruct.Entry",
id: this.#prevId,
keyKind,
value,
Expand All @@ -165,7 +166,7 @@ class Builder {
newConstExpr(offset: number, constantKind: Constant["constantKind"]): Expr {
return this.nextExpr(offset, {
case: "constExpr",
value: { $typeName: "dev.cel.expr.Constant", constantKind },
value: { $typeName: "cel.expr.Constant", constantKind },
});
}

Expand All @@ -180,7 +181,7 @@ class Builder {
return this.nextExpr(offset, {
case: "callExpr",
value: {
$typeName: "dev.cel.expr.Expr.Call",
$typeName: "cel.expr.Expr.Call",
function: functionName,
args,
},
Expand All @@ -199,7 +200,7 @@ class Builder {
this.nextExpr(offset, {
case: "callExpr",
value: {
$typeName: "dev.cel.expr.Expr.Call",
$typeName: "cel.expr.Expr.Call",
function: functionName,
target,
args,
Expand Down Expand Up @@ -280,7 +281,7 @@ class Builder {
newIdentExpr(offset: number, name: string): Expr {
const expr = this.nextExpr(offset, {
case: "identExpr",
value: { $typeName: "dev.cel.expr.Expr.Ident", name },
value: { $typeName: "cel.expr.Expr.Ident", name },
});
return expr;
}
Expand All @@ -293,7 +294,7 @@ class Builder {
return this.nextExpr(offset, {
case: "selectExpr",
value: {
$typeName: "dev.cel.expr.Expr.Select",
$typeName: "cel.expr.Expr.Select",
operand,
field,
testOnly: false,
Expand All @@ -318,7 +319,7 @@ class Builder {
return this.nextExpr(offset, {
case: "listExpr",
value: {
$typeName: "dev.cel.expr.Expr.CreateList",
$typeName: "cel.expr.Expr.CreateList",
elements,
optionalIndices: [],
},
Expand All @@ -336,13 +337,14 @@ class Builder {
return this.nextExpr(offset, {
case: "comprehensionExpr",
value: {
$typeName: "dev.cel.expr.Expr.Comprehension",
$typeName: "cel.expr.Expr.Comprehension",
accuVar: "__result__",
accuInit: this.newConstExpr(offset, {
case: "boolValue",
value: init,
}),
iterVar,
iterVar2: "", // not yet supported
iterRange,
loopStep,
loopCondition,
Expand All @@ -360,10 +362,11 @@ class Builder {
return this.nextExpr(offset, {
case: "comprehensionExpr",
value: {
$typeName: "dev.cel.expr.Expr.Comprehension",
$typeName: "cel.expr.Expr.Comprehension",
accuVar: "__result__",
accuInit: this.newListExpr(offset, []),
iterVar,
iterVar2: "", // not yet supported
iterRange,
loopCondition: this.newConstExpr(offset, {
case: "boolValue",
Expand Down Expand Up @@ -468,13 +471,14 @@ class Builder {
return this.nextExpr(offset, {
case: "comprehensionExpr",
value: {
$typeName: "dev.cel.expr.Expr.Comprehension",
$typeName: "cel.expr.Expr.Comprehension",
accuVar: "__result__",
accuInit: this.newConstExpr(offset, {
case: "int64Value",
value: BigInt(0),
}),
iterVar,
iterVar2: "", // not yet supported
iterRange,
loopCondition: this.newConstExpr(offset, {
case: "boolValue",
Expand Down Expand Up @@ -506,6 +510,7 @@ class Builder {
if (call.exprKind.case === "callExpr") {
const callExpr = call.exprKind.value;
const varName = callExpr.args[0];
const varIndex = callExpr.args.length > 1 ? callExpr.args[1] : "";
if (
varName !== undefined &&
call.exprKind.value.target !== undefined &&
Expand Down Expand Up @@ -582,7 +587,7 @@ class Builder {
return this.nextExpr(offset, {
case: "structExpr",
value: {
$typeName: "dev.cel.expr.Expr.CreateStruct",
$typeName: "cel.expr.Expr.CreateStruct",
entries,
messageName,
},
Expand Down
2 changes: 1 addition & 1 deletion cel.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

{{
import type { Expr, Expr_CreateStruct_Entry } from "./external/proto/dev/cel/expr/syntax_pb.ts";
import type { Expr, Expr_CreateStruct_Entry } from "./external/cel/expr/syntax_pb.ts";
import { LazyBuilder } from "./builder.ts";
import type { Eventual } from "./builder.ts";
const builder = new LazyBuilder();
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"clean": "rm -rf index.ts index.ast utility/extract-parser-tests/bin dist/ external/ node_modules/ &> /dev/null",
"generate-control-parser": "peggy cel.peggy --format es -o ./index.ts",
"generate-parser": "peggy cel.peggy --format bare --extra-options '{\"typescript\":true}' --plugin peggy-ts -o ./index.ts && prettier index.ts --write",
"generate-proto": "buf generate --include-imports buf.build/cel/spec",
"generate-proto": "buf generate --include-imports buf.build/google/cel-spec:v0.18.0",
"generate-parser-ast": "peggy cel.peggy --ast --plugin peggy-ts -o ./index.ast",
"bundle-init": "rm -rf dist/ &> /dev/null && mkdir dist",
"bundle-cjs": "esbuild index.ts --bundle --format=cjs --outfile=dist/index.cjs && prettier dist/index.cjs --write",
Expand Down Expand Up @@ -71,7 +71,7 @@
}
},
"utility": {
"celSpec": "https://github.com/google/cel-spec/archive/7bcc79c7cb9a101a66dbbe9c88838855dc4b821d.tar.gz",
"celGo": "https://github.com/google/cel-go/archive/3545aac7e6d484d3035b1833c4ade036c3f7bacb.tar.gz"
"celSpec": "https://github.com/google/cel-spec/archive/373994d7e20e582fce56767b01ac5039524cddab.tar.gz",
"celGo": "https://github.com/google/cel-go/archive/8ad600b649be1b9ef5a003e8c5632d89b9aaf790.tar.gz"
}
}
7 changes: 2 additions & 5 deletions test/conformance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import * as fs from "fs";

import { parse } from "../index.ts";
import { fromJson } from "@bufbuild/protobuf";
import { ExprSchema } from "../external/proto/dev/cel/expr/syntax_pb.ts";
import type {
Expr,
Expr_Call,
} from "../external/proto/dev/cel/expr/syntax_pb.ts";
import { ExprSchema } from "../external/cel/expr/syntax_pb.ts";
import type { Expr, Expr_Call } from "../external/cel/expr/syntax_pb.ts";

const files = JSON.parse(
fs.readFileSync(`${__dirname}/data/conformance.json`, "utf8"),
Expand Down
Loading