Skip to content

Commit f7ac889

Browse files
authored
Merge pull request #32 from fastly/tyler/vars
Implement vars, choose/when, and expressions
2 parents ee34e76 + 38f60ee commit f7ac889

File tree

21 files changed

+2303
-50
lines changed

21 files changed

+2303
-50
lines changed

.cargo/config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
2-
target = "wasm32-wasi"
2+
target = "wasm32-wasip1"
33

4-
[target.wasm32-wasi]
4+
[target.wasm32-wasip1]
55
rustflags = ["-C", "debuginfo=2"]
66
runner = "viceroy run -- "

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
uses: actions/checkout@v2
99
- name: Install Rust
1010
uses: actions-rs/toolchain@v1
11-
- name: Add wasm32-wasi Rust target
12-
run: rustup target add wasm32-wasi
11+
- name: Add wasm32-wasip1 Rust target
12+
run: rustup target add wasm32-wasip1
1313
- name: Install rustfmt
1414
run: rustup component add rustfmt
1515
shell: bash

Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ members = [
55
"examples/esi_example_minimal",
66
"examples/esi_example_advanced_error_handling",
77
"examples/esi_try_example",
8+
"examples/esi_vars_example",
89
"examples/esi_example_variants",
910
]
1011

1112
[workspace.package]
1213
version = "0.5.0"
13-
authors = ["Kailan Blanks <[email protected]>"]
14+
authors = [
15+
"Kailan Blanks <[email protected]>",
16+
"Vadim Getmanshchuk <[email protected]>",
17+
"Tyler McMullen <[email protected]>",
18+
]
1419
license = "MIT"
1520
edition = "2018"

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ The implementation is a subset of the [ESI Language Specification 1.0](https://w
66

77
- `<esi:include>` (+ `alt`, `onerror="continue"`)
88
- `<esi:try>` | `<esi:attempt>` | `<esi:except>`
9+
- `<esi:vars>` | `<esi:assign>`
10+
- `<esi:choose>` | `<esi:when>` | `<esi:otherwise>`
911
- `<esi:comment>`
1012
- `<esi:remove>`
1113

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

16+
This implementation also includes an expression interpreter and library of functions that can be used. Current functions include:
17+
18+
- `$lower(string)`
19+
- `$html_encode(string)`
20+
- `$replace(haystack, needle, replacement [, count])`
21+
1422
## Example Usage
1523

1624
```rust,no_run

esi/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ repository = "https://github.com/fastly/esi"
99
readme = "./README.md"
1010

1111
[dependencies]
12-
quick-xml = "0.36.0"
13-
thiserror = "^1.0"
12+
quick-xml = "0.37.1"
13+
thiserror = "2.0.6"
1414
fastly = "^0.11"
1515
log = "^0.4"
16+
regex = "1.11.1"
17+
html-escape = "0.2.13"
1618

1719
[dev-dependencies]
1820
env_logger = "^0.11"

esi/src/error.rs

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ pub enum ExecutionError {
4141
/// Writer error
4242
#[error("writer error: {0}")]
4343
WriterError(#[from] std::io::Error),
44+
45+
/// Expression error
46+
#[error("expression failed to evaluate: `{0}`")]
47+
ExpressionError(String),
48+
49+
/// An error occurred while creating a regular expression in an eval context
50+
#[error("failed to create a regular expression")]
51+
RegexError(#[from] regex::Error),
52+
53+
/// An error occurred while executing a function in an eval context
54+
#[error("failed to execute a function: `{0}`")]
55+
FunctionError(String),
4456
}
4557

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

0 commit comments

Comments
 (0)