Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vars, choose/when, and expressions #32

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d8cc85a
Parse Assign tag
tyler Dec 4, 2024
96dfe51
Parse Vars tag
tyler Dec 4, 2024
b04ea81
Short form esi:vars processing works. Added an example for testing.
tyler Dec 4, 2024
50f7f68
Basic long form vars works
tyler Dec 4, 2024
2f9f247
Basic expression lexer/parser/interpreter which should be easy to expand
tyler Dec 4, 2024
2bfac00
Add some TODOs
tyler Dec 4, 2024
94c25ea
Clean up some type coercion and make Variables a real struct which ho…
tyler Dec 4, 2024
94efa58
Correctly parse choose/when/otherwise
tyler Dec 5, 2024
f303107
Execute choose/when/otherwise tags.
tyler Dec 5, 2024
6fff23c
Lex matches operators and setup for more
tyler Dec 5, 2024
b3eb152
Fix both a parsing bug I introduced as well as one that already existed.
tyler Dec 5, 2024
f74d817
Implement 'matches' operator (as well as ... operators at all)
tyler Dec 5, 2024
9530dee
Add regex examples
tyler Dec 5, 2024
8bbc600
Implement string escaping and triple-tick strings
tyler Dec 5, 2024
2518381
Function calls
tyler Dec 5, 2024
3b4ed98
Implement 'lower' function in library
tyler Dec 5, 2024
5dd1927
Implement html_encode and replace functions. Also integers.
tyler Dec 6, 2024
11926dc
Lex, parse, and scaffold the evaluation of metadata variables.
tyler Dec 6, 2024
bdf88c4
Parse subscripted variables
tyler Dec 6, 2024
88c4265
Changed my mind about meta variables. We'll build the intelligence in…
tyler Dec 6, 2024
54587af
Store and expose regex captures
tyler Dec 6, 2024
2bf3520
Allow custom match name for captures
tyler Dec 6, 2024
c510f3d
Make custom matches in ESI doc work and a demo.
tyler Dec 6, 2024
6e17ba6
Little tweak to interpolate text parsing to make variables work. Stil…
tyler Dec 6, 2024
bc0039b
Refactor EvalContext, adding Request data. Implement basic request me…
tyler Dec 6, 2024
bcf717f
Implement matches_i operator
tyler Dec 6, 2024
e510e86
Refactor error handling, remove Result from expression execution favo…
tyler Dec 7, 2024
e697141
Rename Event::XML to Event::Content and Event::VarsContent to Event::…
tyler Dec 7, 2024
0bb38f9
Empty string and 0 should coerce to False. Fix it and test it.
tyler Dec 7, 2024
c653504
Refactor lexer and parser to handle {<expr>} case. Makes the division…
tyler Dec 8, 2024
d9e9de9
Expose request metadata
tyler Dec 9, 2024
42b4a2a
More correctly identify interpolateable sections. Use logged evaluator.
tyler Dec 10, 2024
b1eaf56
'Correctly' identify function calls in raw text. Will circle back for…
tyler Dec 10, 2024
7f539b0
Fix bug where spaces between args in interpolated function calls woul…
tyler Dec 10, 2024
3e6aea7
ESI integers are 32 bits
tyler Dec 10, 2024
0d13671
Move esi functions into separate file in preparation for adding a bun…
tyler Dec 10, 2024
22fd90f
Clean up some warnings
tyler Dec 10, 2024
4a55af6
Update README.md with new functionality.
tyler Dec 10, 2024
ef9f478
Some cleanup and optimizations
vagetman Dec 11, 2024
2063f4c
Merge branch 'main' into tyler/vars
tyler Dec 11, 2024
6c2acb1
consolidated `lex_expr` and `lex_interpolated_expr`, other clean ups
vagetman Dec 12, 2024
d4ca54d
added tests for `lex_interpolated_expr()` fn
vagetman Dec 12, 2024
8bd404b
enhance error handling and refactor expression evaluation functions
vagetman Dec 15, 2024
66e6a66
Resolve compiler warnings in expression tests
kailan Dec 16, 2024
2f9e9b6
Update authors
kailan Jan 6, 2025
13d4282
Update error comment
kailan Jan 6, 2025
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"examples/esi_example_minimal",
"examples/esi_example_advanced_error_handling",
"examples/esi_try_example",
"examples/esi_vars_example",
"examples/esi_example_variants",
]

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ The implementation is a subset of the [ESI Language Specification 1.0](https://w

- `<esi:include>` (+ `alt`, `onerror="continue"`)
- `<esi:try>` | `<esi:attempt>` | `<esi:except>`
- `<esi:vars>` | `<esi:assign>`
- `<esi:choose>` | `<esi:when>` | `<esi:otherwise>`
- `<esi:comment>`
- `<esi:remove>`

Other tags will be ignored and served to the client as-is.

This implementation also includes an expression interpreter and library of functions that can be used. Current functions include:

- `$lower(string)`
- `$html_encode(string)`
- `$replace(haystack, needle, replacement [, count])`

## Example Usage

```rust,no_run
Expand Down
6 changes: 4 additions & 2 deletions esi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ repository = "https://github.com/fastly/esi"
readme = "./README.md"

[dependencies]
quick-xml = "0.36.0"
thiserror = "^1.0"
quick-xml = "0.37.1"
thiserror = "2.0.6"
fastly = "^0.11"
log = "^0.4"
regex = "1.11.1"
html-escape = "0.2.13"

[dev-dependencies]
env_logger = "^0.11"
12 changes: 12 additions & 0 deletions esi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ pub enum ExecutionError {
/// Writer error
#[error("writer error: {0}")]
WriterError(#[from] std::io::Error),

/// Expression error
#[error("expression failed to evaluate: `{0}`")]
ExpressionError(String),

/// An error occurred while creating a regular expression in an eval context
#[error("failed to create a regular expression")]
RegexError(#[from] regex::Error),

/// An error occurred while creating a regular expression in an eval context
#[error("failed to execute a function: `{0}`")]
FunctionError(String),
}

pub type Result<T> = std::result::Result<T, ExecutionError>;
Loading
Loading