mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
Better square braces parsing (#15)
This commit is contained in:
parent
265ff8ac88
commit
e4fd7a505c
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -2,9 +2,9 @@
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.14"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d"
|
||||
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
@ -488,9 +488,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279"
|
||||
checksum = "fc4666154fd004af3fd6f1da2e81a96fd5a81927fe8ddb6ecc79e2aa6e138b54"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"csv-core",
|
||||
@ -1699,18 +1699,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.21"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "318234ffa22e0920fe9a40d7b8369b5f649d490980cf7aadcf1eb91594869b42"
|
||||
checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.21"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cae2447b6282786c3493999f40a9be2a6ad20cb8bd268b0a0dbf5a065535c0ab"
|
||||
checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -32,9 +32,8 @@ Scripts written in AIR look like this:
|
||||
<img alt="call structure" src="images/call_data.png" width="670"/>
|
||||
|
||||
- `call` commands the execution
|
||||
- takes network `location`, `service id`, `function name`, `list of function arguments`, and an `output name`
|
||||
- moves execution to a peer, specified by `location`
|
||||
- peer must have the specified WASM `service` running
|
||||
- peer is expected to have specified WASM `service`
|
||||
- the `service` must have specified `function` available to be called
|
||||
- `argument list` is given to the `function`
|
||||
- result of the `function` is saved and available under `output name`
|
||||
|
@ -15,8 +15,8 @@ pub Instr: Box<Instruction<'input>> = {
|
||||
"(" "par" <l:Instr> <r:Instr> ")" => Box::new(Instruction::Par(Par(l, r))),
|
||||
"(" "xor" <l:Instr> <r:Instr> ")" => Box::new(Instruction::Xor(Xor(l, r))),
|
||||
|
||||
"(" "call" <peer:PeerPart> <f:FPart> <args:Args> <output:Output> ")" =>
|
||||
Box::new(Instruction::Call(Call{peer, f, args, output})),
|
||||
"(" "call" <p:PeerPart> <f:FPart> <args:Args> <output:Output> ")" =>
|
||||
Box::new(Instruction::Call(Call{peer_part: p, function_part: f, args, output})),
|
||||
|
||||
"(" "fold" <iterable:Alphanumeric> <iterator:Alphanumeric> <i:Instr> ")" => {
|
||||
let instruction = Rc::new(*i);
|
||||
@ -75,7 +75,7 @@ Alphanumeric = ALPHANUMERIC;
|
||||
match {
|
||||
r"[\w_-]+" => ALPHANUMERIC,
|
||||
r"[\w_-]+\[\]" => ACCUMULATOR,
|
||||
r"[\w_-]+\.\$[^ ]+" => JSON_PATH,
|
||||
r#"[\w_-]+\.*\$([\w._-]*(\[[\w"]+\])*)+"# => JSON_PATH,
|
||||
"%current_peer_id%" => CURRENT_PEER_ID,
|
||||
"seq",
|
||||
"call",
|
||||
|
File diff suppressed because one or more lines are too long
@ -112,7 +112,7 @@ fn parse_json_path_complex() {
|
||||
let source_code = r#"
|
||||
(seq
|
||||
(call m.$.[1] "f" [] void)
|
||||
(call m.$.abc.cde[a][0].cde "f" [] void)
|
||||
(call m.$.abc["c"].cde[a][0].cde["bcd"] "f" [] void)
|
||||
)
|
||||
"#;
|
||||
let instruction = parse(source_code);
|
||||
@ -129,7 +129,7 @@ fn parse_json_path_complex() {
|
||||
Instruction::Call(Call {
|
||||
peer_part: PeerPk(JsonPath {
|
||||
variable: "m",
|
||||
path: "$.abc.cde[a][0].cde",
|
||||
path: r#"$.abc["c"].cde[a][0].cde["bcd"]"#,
|
||||
}),
|
||||
function_part: FuncName(Literal("f")),
|
||||
args: vec![],
|
||||
@ -139,6 +139,34 @@ fn parse_json_path_complex() {
|
||||
assert_eq!(instruction, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_path_square_braces() {
|
||||
let source_code = r#"
|
||||
(call u.$["peer_id"] ("return" "") [u.$["peer_id"].cde[0]["abc"].abc u.$["name"]] void[])
|
||||
"#;
|
||||
let instruction = parse(source_code);
|
||||
let expected = Instruction::Call(Call {
|
||||
peer_part: PeerPk(JsonPath {
|
||||
variable: "u",
|
||||
path: r#"$["peer_id"]"#,
|
||||
}),
|
||||
function_part: ServiceIdWithFuncName(Literal("return"), Literal("")),
|
||||
args: vec![
|
||||
JsonPath {
|
||||
variable: "u",
|
||||
path: r#"$["peer_id"].cde[0]["abc"].abc"#,
|
||||
},
|
||||
JsonPath {
|
||||
variable: "u",
|
||||
path: r#"$["name"]"#,
|
||||
},
|
||||
],
|
||||
output: Accumulator("void"),
|
||||
});
|
||||
|
||||
assert_eq!(instruction, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_null() {
|
||||
let source_code = r#"
|
||||
|
Loading…
Reference in New Issue
Block a user