-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cel.block as an extension library
PiperOrigin-RevId: 602536654
- Loading branch information
1 parent
9ae535c
commit c4e43ff
Showing
7 changed files
with
376 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
extensions/src/main/java/dev/cel/extensions/CelBlockExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package dev.cel.extensions; | ||
|
||
import dev.cel.checker.CelCheckerBuilder; | ||
import dev.cel.common.CelFunctionDecl; | ||
import dev.cel.common.CelOverloadDecl; | ||
import dev.cel.common.types.ListType; | ||
import dev.cel.common.types.SimpleType; | ||
import dev.cel.compiler.CelCompilerLibrary; | ||
|
||
/** | ||
* Internal implementation of cel.@block extension function. | ||
* | ||
* <p>Note the extensions only contain function declarations. This requires special support from | ||
* interpreters. | ||
*/ | ||
final class CelBlockExtensions implements CelCompilerLibrary { | ||
private static final String CEL_BLOCK_FUNCTION = "cel.@block"; | ||
private static final String CEL_BLOCK_INDEX_FUNCTION = "cel.@index"; | ||
|
||
@Override | ||
public void setCheckerOptions(CelCheckerBuilder checkerBuilder) { | ||
checkerBuilder.addFunctionDeclarations( | ||
CelFunctionDecl.newFunctionDeclaration( | ||
CEL_BLOCK_FUNCTION, | ||
CelOverloadDecl.newGlobalOverload( | ||
"cel_block_list", SimpleType.DYN, ListType.create(SimpleType.DYN), SimpleType.DYN)), | ||
CelFunctionDecl.newFunctionDeclaration( | ||
CEL_BLOCK_INDEX_FUNCTION, | ||
CelOverloadDecl.newGlobalOverload("cel_index_int", SimpleType.DYN, SimpleType.INT))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.