diff --git a/Cargo.lock b/Cargo.lock index 65481eb5..b7a0f24a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ [[package]] name = "air-parser" -version = "0.2.0" +version = "0.3.0" dependencies = [ "codespan", "codespan-reporting", @@ -1668,7 +1668,7 @@ dependencies = [ [[package]] name = "stepper-lib" -version = "0.3.0" +version = "0.4.0" dependencies = [ "air-parser", "aqua-test-utils", diff --git a/crates/air-parser/Cargo.toml b/crates/air-parser/Cargo.toml index 24c7d42e..9830fbd1 100644 --- a/crates/air-parser/Cargo.toml +++ b/crates/air-parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "air-parser" -version = "0.2.0" +version = "0.3.0" authors = ["Fluence Labs"] edition = "2018" license = "Apache-2.0" diff --git a/crates/air-parser/src/parser/air.lalrpop b/crates/air-parser/src/parser/air.lalrpop index c5cad8c6..2d64a1d4 100644 --- a/crates/air-parser/src/parser/air.lalrpop +++ b/crates/air-parser/src/parser/air.lalrpop @@ -13,7 +13,7 @@ pub AIR = Instr; Instr: Box> = { "(" call ")" => { - let output = output.unwrap_or(CallOutput::None); + let output = output.unwrap_or(CallOutputValue::None); let args = Rc::new(args); Box::new(Instruction::Call(Call{peer_part: p, function_part: f, args, output})) }, @@ -31,10 +31,12 @@ Instr: Box> = { "(" xor ")" => Box::new(Instruction::Xor(Xor(l, r))), + "(" match_ ")" => Box::new(Instruction::Match(Match(l, r, i))), + ! => { errors.push(<>); Box::new(Instruction::Error) }, } -Args: Vec> = { +Args: Vec> = { "[" )*> "]" => args } @@ -48,11 +50,26 @@ PeerPart: PeerPart<'input> = { "(" ")" => PeerPart::PeerPkWithServiceId(pid, sid), } -Output: CallOutput<'input> = { - => CallOutput::Scalar(s), - => CallOutput::Accumulator(a), +Output: CallOutputValue<'input> = { + => CallOutputValue::Scalar(s), + => CallOutputValue::Accumulator(a), }; +Function = CallArgValue; +PeerId = CallArgValue; +ServiceId = CallArgValue; +Arg = CallArgValue; + +CallArgValue: CallArgValue<'input> = { + => CallArgValue::Literal(s), + => CallArgValue::Variable(s), + => { + let (variable, path) = into_variable_and_path(v.0, v.1); + CallArgValue::JsonPath { variable, path } + }, + InitPeerId => CallArgValue::InitPeerId, +} + Iterable: IterableValue<'input> = { => IterableValue::Variable(s), => { @@ -61,19 +78,13 @@ Iterable: IterableValue<'input> = { }, } -Function = CallInstructionValue; -PeerId = CallInstructionValue; -ServiceId = CallInstructionValue; -Arg = CallInstructionValue; - -CallInstructionValue: CallInstructionValue<'input> = { - => CallInstructionValue::Literal(s), - => CallInstructionValue::Variable(s), +Matchable: MatchableValue<'input> = { + => MatchableValue::Variable(s), + => MatchableValue::Literal(s), => { let (variable, path) = into_variable_and_path(v.0, v.1); - CallInstructionValue::JsonPath { variable, path } + MatchableValue::JsonPath { variable, path } }, - InitPeerId => CallInstructionValue::InitPeerId, } extern { @@ -100,5 +111,6 @@ extern { fold => Token::Fold, xor => Token::Xor, next => Token::Next, + match_ => Token::Match, } } diff --git a/crates/air-parser/src/parser/air.rs b/crates/air-parser/src/parser/air.rs index b6c8d85d..d67e7029 100644 --- a/crates/air-parser/src/parser/air.rs +++ b/crates/air-parser/src/parser/air.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.19.1" -// sha256: 45fb65d0326932706c3c3c28499ccc962d6da228323f4d1b87f866b6d294fc7e +// sha256: bb2efa4b9cde2613385df98e0d4cbff3b9851ed43c3eaa46d3a6773f1b0913b use crate::parser::ast::*; use crate::parser::into_variable_and_path; use crate::parser::lexer::LexerError; @@ -33,144 +33,161 @@ mod __parse__AIR { Variant1(&'input str), Variant2((&'input str, usize)), Variant3(__lalrpop_util::ErrorRecovery, LexerError>), - Variant4(CallInstructionValue<'input>), - Variant5(::std::vec::Vec>), + Variant4(CallArgValue<'input>), + Variant5(::std::vec::Vec>), Variant6(Box>), - Variant7(Vec>), + Variant7(Vec>), Variant8(FunctionPart<'input>), Variant9(IterableValue<'input>), - Variant10(CallOutput<'input>), - Variant11(::std::option::Option>), - Variant12(PeerPart<'input>), + Variant10(MatchableValue<'input>), + Variant11(CallOutputValue<'input>), + Variant12(::std::option::Option>), + Variant13(PeerPart<'input>), } const __ACTION: &[i8] = &[ // State 0 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 1 - 8, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 9, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 2 - 0, 0, 0, 0, 0, 33, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 3 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 0, 0, 0, 0, 0, 38, 0, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 4 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 5 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 6 - 13, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 7 - 0, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 8 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 0, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 9 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 0, 0, 0, 0, 0, 38, 0, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 10 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 11 - 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 12 - 0, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 13 - 0, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 14 - 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, + 0, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 15 - 0, 50, 0, 0, 51, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 16 - 0, 0, 0, 55, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 17 - 0, 0, 0, 0, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, // State 18 - 0, 0, 0, 61, 0, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 57, 0, 0, 58, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 19 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 62, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 20 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 21 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 24, 25, 4, 5, 6, 0, + 0, 0, 0, 69, 0, 31, 32, 33, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 22 - -25, -25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -25, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 23 - 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 24 - 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 27, 28, 5, 6, 7, 0, // State 25 - -32, 0, 0, 0, 0, -32, -32, -32, -32, 0, 0, 0, 0, 0, 0, 0, 0, + -26, -26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -26, // State 26 - -33, 0, 0, 0, 0, -33, -33, -33, -33, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 27 - -11, -11, -11, -11, 0, -11, -11, -11, -11, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 28 - -13, -13, -13, -13, 0, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, + -36, 0, 0, 0, 0, -36, -36, -36, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 29 - -12, -12, -12, -12, 0, -12, -12, -12, -12, 0, 0, 0, 0, 0, 0, 0, 0, + -37, 0, 0, 0, 0, -37, -37, -37, -37, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 30 - -10, -10, -10, -10, 0, -10, -10, -10, -10, 0, 0, 0, 0, 0, 0, 0, 0, + -11, -11, -11, -11, 0, -11, -11, -11, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 31 - 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -13, -13, -13, -13, 0, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 32 - 0, 0, 0, 0, 0, -26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -12, -12, -12, -12, 0, -12, -12, -12, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 33 - 0, 0, 0, 0, 0, -27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -10, -10, -10, -10, 0, -10, -10, -10, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 35 - -21, -21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -21, + 0, 0, 0, 0, 0, -27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 36 - 0, -16, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 37 - 0, 0, -14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -29, 0, 0, 0, 0, -29, 0, -29, -29, 0, 0, 0, 0, 0, 0, 0, 0, -29, // State 38 - -23, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -23, + -31, 0, 0, 0, 0, -31, 0, -31, -31, 0, 0, 0, 0, 0, 0, 0, 0, -31, // State 39 - 0, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -30, 0, 0, 0, 0, -30, 0, -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, -30, // State 40 - 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 41 - 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -21, -21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -21, // State 42 - 0, -35, 0, 0, 0, -35, -35, -35, -35, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -16, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 43 - 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 44 - 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -23, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -23, // State 45 - -20, -20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -20, + 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 46 - -19, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -19, + 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 47 - -24, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -24, + 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 48 - 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -39, 0, 0, 0, -39, -39, -39, -39, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 49 - -18, -18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, + 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 50 - 0, -29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 51 - 0, -28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 52 - 0, 0, 0, -4, 0, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, + -20, -20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -20, // State 53 - 0, 0, 0, -7, 0, -7, -7, -7, -7, 0, 0, 0, 0, 0, 0, 0, 0, + -19, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -19, // State 54 - 0, -8, 0, 0, -8, -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -24, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -24, // State 55 - 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 56 - -34, 0, 0, 0, 0, -34, -34, -34, -34, 0, 0, 0, 0, 0, 0, 0, 0, + -18, -18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, // State 57 - -22, -22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -22, + 0, -33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 58 - -17, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -17, + 0, -32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 59 - 0, 0, 0, -5, 0, -5, -5, -5, -5, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -4, 0, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 60 - 0, -9, 0, 0, -9, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -7, 0, -7, -7, -7, -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 61 - 0, 0, -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -8, 0, 0, -8, -8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 62 + 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 63 + -38, 0, 0, 0, 0, -38, -38, -38, -38, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 64 + -22, -22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -22, + // State 65 + -25, -25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -25, + // State 66 + -17, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -17, + // State 67 + 0, 0, 0, -5, 0, -5, -5, -5, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 68 + 0, -9, 0, 0, -9, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 69 + 0, 0, -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; fn __action(state: i8, integer: usize) -> i8 { - __ACTION[(state as usize) * 17 + integer] + __ACTION[(state as usize) * 18 + integer] } const __EOF_ACTION: &[i8] = &[ // State 0 @@ -212,19 +229,19 @@ mod __parse__AIR { // State 18 0, // State 19 - -36, + 0, // State 20 - -6, + 0, // State 21 0, // State 22 - -25, + -40, // State 23 - 0, + -6, // State 24 0, // State 25 - 0, + -26, // State 26 0, // State 27 @@ -244,100 +261,121 @@ mod __parse__AIR { // State 34 0, // State 35 - -21, + 0, // State 36 0, // State 37 0, // State 38 - -23, + 0, // State 39 0, // State 40 0, // State 41 - 0, + -21, // State 42 0, // State 43 0, // State 44 - 0, + -23, // State 45 - -20, + 0, // State 46 - -19, + 0, // State 47 - -24, + 0, // State 48 0, // State 49 - -18, + 0, // State 50 0, // State 51 0, // State 52 - 0, + -20, // State 53 - 0, + -19, // State 54 - 0, + -24, // State 55 0, // State 56 - 0, + -18, // State 57 - -22, + 0, // State 58 - -17, + 0, // State 59 0, // State 60 0, // State 61 0, + // State 62 + 0, + // State 63 + 0, + // State 64 + -22, + // State 65 + -25, + // State 66 + -17, + // State 67 + 0, + // State 68 + 0, + // State 69 + 0, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { - 2 => 18, - 3 => 19, + 2 => 21, + 3 => 22, 4 => match state { - 18 => 59, - _ => 52, + 21 => 67, + _ => 59, }, - 5 => 15, + 5 => 18, 6 => match state { - 6 | 17 => 36, - 12..=13 => 42, - 16 | 18 => 53, - _ => 25, + 7 | 20 => 42, + 14..=15 => 48, + 19 | 21 => 60, + _ => 28, }, - 7 => 11, + 7 => 13, 8 => match state { - 17 => 55, - _ => 37, + 20 => 62, + _ => 43, }, 9 => match state { - 4 => 9, - 5 => 10, - 0 => 20, - 8 => 39, - 9 => 40, - 10 => 41, - 14 => 44, - _ => 8, + 5 => 11, + 6 => 12, + 0 => 23, + 10 => 45, + 11 => 46, + 12 => 47, + 16 => 50, + 17 => 51, + _ => 10, }, - 10 => 31, - 11 => 48, - 13 => match state { - 1 => 26, - _ => 13, + 10 => 34, + 11 => match state { + 9 => 17, + _ => 9, }, - 14 => 6, - 15 => match state { - 13 => 43, - _ => 17, + 12 => 55, + 14 => match state { + 1 => 29, + _ => 15, + }, + 15 => 7, + 16 => match state { + 15 => 49, + _ => 20, }, _ => 0, } @@ -355,6 +393,7 @@ mod __parse__AIR { r###"Literal"###, r###"call"###, r###"fold"###, + r###"match_"###, r###"next"###, r###"null"###, r###"par"###, @@ -413,7 +452,7 @@ mod __parse__AIR { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 17 - 1) + __action(state, 18 - 1) } #[inline] @@ -489,11 +528,12 @@ mod __parse__AIR { Token::StringLiteral(_) if true => Some(8), Token::Call if true => Some(9), Token::Fold if true => Some(10), - Token::Next if true => Some(11), - Token::Null if true => Some(12), - Token::Par if true => Some(13), - Token::Seq if true => Some(14), - Token::Xor if true => Some(15), + Token::Match if true => Some(11), + Token::Next if true => Some(12), + Token::Null if true => Some(13), + Token::Par if true => Some(14), + Token::Seq if true => Some(15), + Token::Xor if true => Some(16), _ => None, } } @@ -507,7 +547,7 @@ mod __parse__AIR { ) -> __Symbol<'input> { match __token_index { - 0 | 1 | 2 | 3 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 => __Symbol::Variant0(__token), + 0 | 1 | 2 | 3 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => __Symbol::Variant0(__token), 4 | 5 | 8 => match __token { Token::Accumulator(__tok0) | Token::Alphanumeric(__tok0) | Token::StringLiteral(__tok0) if true => __Symbol::Variant1(__tok0), _ => unreachable!(), @@ -676,14 +716,14 @@ mod __parse__AIR { } 24 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 1, + states_to_pop: 6, nonterminal_produced: 9, } } 25 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 10, + nonterminal_produced: 9, } } 26 => { @@ -695,7 +735,7 @@ mod __parse__AIR { 27 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 11, + nonterminal_produced: 10, } } 28 => { @@ -707,40 +747,64 @@ mod __parse__AIR { 29 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 12, + nonterminal_produced: 11, } } 30 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 0, - nonterminal_produced: 12, + states_to_pop: 1, + nonterminal_produced: 11, } } 31 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 13, + nonterminal_produced: 12, } } 32 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 14, + nonterminal_produced: 12, } } 33 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 4, - nonterminal_produced: 14, + states_to_pop: 1, + nonterminal_produced: 13, } } 34 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 0, + nonterminal_produced: 13, + } + } + 35 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 1, + nonterminal_produced: 14, + } + } + 36 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, nonterminal_produced: 15, } } - 35 => __state_machine::SimulatedReduce::Accept, + 37 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 4, + nonterminal_produced: 15, + } + } + 38 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 1, + nonterminal_produced: 16, + } + } + 39 => __state_machine::SimulatedReduce::Accept, _ => panic!("invalid reduction index {}", __reduce_index) } } @@ -937,6 +1001,18 @@ mod __parse__AIR { __reduce34(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) } 35 => { + __reduce35(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 36 => { + __reduce36(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 37 => { + __reduce37(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 38 => { + __reduce38(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 39 => { // __AIR = AIR => ActionFn(0); let __sym0 = __pop_Variant6(__symbols); let __start = __sym0.0.clone(); @@ -983,21 +1059,21 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, CallInstructionValue<'input>, usize) + ) -> (usize, CallArgValue<'input>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant4(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant10< + fn __pop_Variant11< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, CallOutput<'input>, usize) + ) -> (usize, CallOutputValue<'input>, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1023,14 +1099,25 @@ mod __parse__AIR { _ => __symbol_type_mismatch() } } - fn __pop_Variant12< + fn __pop_Variant10< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, MatchableValue<'input>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant13< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, PeerPart<'input>, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant13(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1049,7 +1136,7 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Vec>, usize) + ) -> (usize, Vec>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant7(__v), __r)) => (__l, __v, __r), @@ -1067,14 +1154,14 @@ mod __parse__AIR { _ => __symbol_type_mismatch() } } - fn __pop_Variant11< + fn __pop_Variant12< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, ::std::option::Option>, usize) + ) -> (usize, ::std::option::Option>, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1082,7 +1169,7 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, ::std::vec::Vec>, usize) + ) -> (usize, ::std::vec::Vec>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant5(__v), __r)) => (__l, __v, __r), @@ -1111,11 +1198,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // () = Arg => ActionFn(29); + // () = Arg => ActionFn(33); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action29::<>(input, errors, __sym0); + let __nt = super::__action33::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 0) } @@ -1130,10 +1217,10 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()* = => ActionFn(27); + // ()* = => ActionFn(31); let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); let __end = __start.clone(); - let __nt = super::__action27::<>(input, errors, &__start, &__end); + let __nt = super::__action31::<>(input, errors, &__start, &__end); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (0, 1) } @@ -1148,11 +1235,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()* = ()+ => ActionFn(28); + // ()* = ()+ => ActionFn(32); let __sym0 = __pop_Variant5(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action28::<>(input, errors, __sym0); + let __nt = super::__action32::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (1, 1) } @@ -1167,11 +1254,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()+ = Arg => ActionFn(34); + // ()+ = Arg => ActionFn(38); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action34::<>(input, errors, __sym0); + let __nt = super::__action38::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (1, 2) } @@ -1186,13 +1273,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()+ = ()+, Arg => ActionFn(35); + // ()+ = ()+, Arg => ActionFn(39); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant4(__symbols); let __sym0 = __pop_Variant5(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action35::<>(input, errors, __sym0, __sym1); + let __nt = super::__action39::<>(input, errors, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant5(__nt), __end)); (2, 2) } @@ -1226,11 +1313,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Arg = CallInstructionValue => ActionFn(22); + // Arg = CallArgValue => ActionFn(21); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action22::<>(input, errors, __sym0); + let __nt = super::__action21::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 4) } @@ -1245,13 +1332,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Args = "[", "]" => ActionFn(36); + // Args = "[", "]" => ActionFn(40); assert!(__symbols.len() >= 2); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action36::<>(input, errors, __sym0, __sym1); + let __nt = super::__action40::<>(input, errors, __sym0, __sym1); __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (2, 5) } @@ -1266,14 +1353,14 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Args = "[", ()+, "]" => ActionFn(37); + // Args = "[", ()+, "]" => ActionFn(41); assert!(__symbols.len() >= 3); let __sym2 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant5(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); - let __nt = super::__action37::<>(input, errors, __sym0, __sym1, __sym2); + let __nt = super::__action41::<>(input, errors, __sym0, __sym1, __sym2); __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (3, 5) } @@ -1288,11 +1375,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstructionValue = Literal => ActionFn(23); + // CallArgValue = Literal => ActionFn(22); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action23::<>(input, errors, __sym0); + let __nt = super::__action22::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 6) } @@ -1307,11 +1394,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstructionValue = Alphanumeric => ActionFn(24); + // CallArgValue = Alphanumeric => ActionFn(23); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action24::<>(input, errors, __sym0); + let __nt = super::__action23::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 6) } @@ -1326,11 +1413,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstructionValue = JsonPath => ActionFn(25); + // CallArgValue = JsonPath => ActionFn(24); let __sym0 = __pop_Variant2(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action25::<>(input, errors, __sym0); + let __nt = super::__action24::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 6) } @@ -1345,11 +1432,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstructionValue = InitPeerId => ActionFn(26); + // CallArgValue = InitPeerId => ActionFn(25); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action26::<>(input, errors, __sym0); + let __nt = super::__action25::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 6) } @@ -1364,11 +1451,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // FPart = Function => ActionFn(11); + // FPart = Function => ActionFn(12); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action11::<>(input, errors, __sym0); + let __nt = super::__action12::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (1, 7) } @@ -1383,7 +1470,7 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // FPart = "(", ServiceId, Function, ")" => ActionFn(12); + // FPart = "(", ServiceId, Function, ")" => ActionFn(13); assert!(__symbols.len() >= 4); let __sym3 = __pop_Variant0(__symbols); let __sym2 = __pop_Variant4(__symbols); @@ -1391,7 +1478,7 @@ mod __parse__AIR { let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym3.2.clone(); - let __nt = super::__action12::<>(input, errors, __sym0, __sym1, __sym2, __sym3); + let __nt = super::__action13::<>(input, errors, __sym0, __sym1, __sym2, __sym3); __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (4, 7) } @@ -1406,11 +1493,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Function = CallInstructionValue => ActionFn(19); + // Function = CallArgValue => ActionFn(18); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action19::<>(input, errors, __sym0); + let __nt = super::__action18::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); (1, 8) } @@ -1425,18 +1512,18 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Instr = "(", call, PeerPart, FPart, Args, Output, ")" => ActionFn(38); + // Instr = "(", call, PeerPart, FPart, Args, Output, ")" => ActionFn(42); assert!(__symbols.len() >= 7); let __sym6 = __pop_Variant0(__symbols); - let __sym5 = __pop_Variant10(__symbols); + let __sym5 = __pop_Variant11(__symbols); let __sym4 = __pop_Variant7(__symbols); let __sym3 = __pop_Variant8(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym2 = __pop_Variant13(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym6.2.clone(); - let __nt = super::__action38::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + let __nt = super::__action42::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (7, 9) } @@ -1451,17 +1538,17 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Instr = "(", call, PeerPart, FPart, Args, ")" => ActionFn(39); + // Instr = "(", call, PeerPart, FPart, Args, ")" => ActionFn(43); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); let __sym4 = __pop_Variant7(__symbols); let __sym3 = __pop_Variant8(__symbols); - let __sym2 = __pop_Variant12(__symbols); + let __sym2 = __pop_Variant13(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action39::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + let __nt = super::__action43::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (6, 9) } @@ -1618,13 +1705,19 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Instr = error => ActionFn(9); - let __sym0 = __pop_Variant3(__symbols); + // Instr = "(", match_, Matchable, Matchable, Instr, ")" => ActionFn(9); + assert!(__symbols.len() >= 6); + let __sym5 = __pop_Variant0(__symbols); + let __sym4 = __pop_Variant6(__symbols); + let __sym3 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant10(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action9::<>(input, errors, __sym0); + let __end = __sym5.2.clone(); + let __nt = super::__action9::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); __symbols.push((__start, __Symbol::Variant6(__nt), __end)); - (1, 9) + (6, 9) } pub(crate) fn __reduce25< 'err, @@ -1637,13 +1730,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Iterable = Alphanumeric => ActionFn(17); - let __sym0 = __pop_Variant1(__symbols); + // Instr = error => ActionFn(10); + let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action17::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant9(__nt), __end)); - (1, 10) + let __nt = super::__action10::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + (1, 9) } pub(crate) fn __reduce26< 'err, @@ -1656,11 +1749,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Iterable = JsonPath => ActionFn(18); - let __sym0 = __pop_Variant2(__symbols); + // Iterable = Alphanumeric => ActionFn(26); + let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action18::<>(input, errors, __sym0); + let __nt = super::__action26::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (1, 10) } @@ -1675,13 +1768,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Output = Alphanumeric => ActionFn(15); - let __sym0 = __pop_Variant1(__symbols); + // Iterable = JsonPath => ActionFn(27); + let __sym0 = __pop_Variant2(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action15::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) + let __nt = super::__action27::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + (1, 10) } pub(crate) fn __reduce28< 'err, @@ -1694,11 +1787,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Output = Accumulator => ActionFn(16); + // Matchable = Alphanumeric => ActionFn(28); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action16::<>(input, errors, __sym0); + let __nt = super::__action28::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 11) } @@ -1713,13 +1806,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Output? = Output => ActionFn(30); - let __sym0 = __pop_Variant10(__symbols); + // Matchable = Literal => ActionFn(29); + let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action30::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) + let __nt = super::__action29::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 11) } pub(crate) fn __reduce30< 'err, @@ -1732,12 +1825,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Output? = => ActionFn(31); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action31::<>(input, errors, &__start, &__end); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (0, 12) + // Matchable = JsonPath => ActionFn(30); + let __sym0 = __pop_Variant2(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action30::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 11) } pub(crate) fn __reduce31< 'err, @@ -1750,13 +1844,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // PeerId = CallInstructionValue => ActionFn(20); - let __sym0 = __pop_Variant4(__symbols); + // Output = Alphanumeric => ActionFn(16); + let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action20::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); - (1, 13) + let __nt = super::__action16::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant11(__nt), __end)); + (1, 12) } pub(crate) fn __reduce32< 'err, @@ -1769,13 +1863,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // PeerPart = PeerId => ActionFn(13); - let __sym0 = __pop_Variant4(__symbols); + // Output = Accumulator => ActionFn(17); + let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action13::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (1, 14) + let __nt = super::__action17::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant11(__nt), __end)); + (1, 12) } pub(crate) fn __reduce33< 'err, @@ -1788,17 +1882,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // PeerPart = "(", PeerId, ServiceId, ")" => ActionFn(14); - assert!(__symbols.len() >= 4); - let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant4(__symbols); - let __sym1 = __pop_Variant4(__symbols); - let __sym0 = __pop_Variant0(__symbols); + // Output? = Output => ActionFn(34); + let __sym0 = __pop_Variant11(__symbols); let __start = __sym0.0.clone(); - let __end = __sym3.2.clone(); - let __nt = super::__action14::<>(input, errors, __sym0, __sym1, __sym2, __sym3); + let __end = __sym0.2.clone(); + let __nt = super::__action34::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant12(__nt), __end)); - (4, 14) + (1, 13) } pub(crate) fn __reduce34< 'err, @@ -1811,14 +1901,93 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ServiceId = CallInstructionValue => ActionFn(21); + // Output? = => ActionFn(35); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action35::<>(input, errors, &__start, &__end); + __symbols.push((__start, __Symbol::Variant12(__nt), __end)); + (0, 13) + } + pub(crate) fn __reduce35< + 'err, + 'input, + >( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __lookahead_start: Option<&usize>, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<(&'err (), &'input ())>, + ) -> (usize, usize) + { + // PeerId = CallArgValue => ActionFn(19); let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action21::<>(input, errors, __sym0); + let __nt = super::__action19::<>(input, errors, __sym0); __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + (1, 14) + } + pub(crate) fn __reduce36< + 'err, + 'input, + >( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __lookahead_start: Option<&usize>, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<(&'err (), &'input ())>, + ) -> (usize, usize) + { + // PeerPart = PeerId => ActionFn(14); + let __sym0 = __pop_Variant4(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action14::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); (1, 15) } + pub(crate) fn __reduce37< + 'err, + 'input, + >( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __lookahead_start: Option<&usize>, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<(&'err (), &'input ())>, + ) -> (usize, usize) + { + // PeerPart = "(", PeerId, ServiceId, ")" => ActionFn(15); + assert!(__symbols.len() >= 4); + let __sym3 = __pop_Variant0(__symbols); + let __sym2 = __pop_Variant4(__symbols); + let __sym1 = __pop_Variant4(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym3.2.clone(); + let __nt = super::__action15::<>(input, errors, __sym0, __sym1, __sym2, __sym3); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); + (4, 15) + } + pub(crate) fn __reduce38< + 'err, + 'input, + >( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __lookahead_start: Option<&usize>, + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, + _: ::std::marker::PhantomData<(&'err (), &'input ())>, + ) -> (usize, usize) + { + // ServiceId = CallArgValue => ActionFn(20); + let __sym0 = __pop_Variant4(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action20::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + (1, 16) + } } pub use self::__parse__AIR::AIRParser; @@ -1859,13 +2028,13 @@ fn __action2< (_, _, _): (usize, Token<'input>, usize), (_, p, _): (usize, PeerPart<'input>, usize), (_, f, _): (usize, FunctionPart<'input>, usize), - (_, args, _): (usize, Vec>, usize), - (_, output, _): (usize, ::std::option::Option>, usize), + (_, args, _): (usize, Vec>, usize), + (_, output, _): (usize, ::std::option::Option>, usize), (_, _, _): (usize, Token<'input>, usize), ) -> Box> { { - let output = output.unwrap_or(CallOutput::None); + let output = output.unwrap_or(CallOutputValue::None); let args = Rc::new(args); Box::new(Instruction::Call(Call{peer_part: p, function_part: f, args, output})) } @@ -1981,10 +2150,15 @@ fn __action9< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, __lalrpop_util::ErrorRecovery, LexerError>, usize), + (_, _, _): (usize, Token<'input>, usize), + (_, _, _): (usize, Token<'input>, usize), + (_, l, _): (usize, MatchableValue<'input>, usize), + (_, r, _): (usize, MatchableValue<'input>, usize), + (_, i, _): (usize, Box>, usize), + (_, _, _): (usize, Token<'input>, usize), ) -> Box> { - { errors.push(__0); Box::new(Instruction::Error) } + Box::new(Instruction::Match(Match(l, r, i))) } #[allow(unused_variables)] @@ -1994,12 +2168,10 @@ fn __action10< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, _, _): (usize, Token<'input>, usize), - (_, args, _): (usize, ::std::vec::Vec>, usize), - (_, _, _): (usize, Token<'input>, usize), -) -> Vec> + (_, __0, _): (usize, __lalrpop_util::ErrorRecovery, LexerError>, usize), +) -> Box> { - args + { errors.push(__0); Box::new(Instruction::Error) } } #[allow(unused_variables)] @@ -2009,10 +2181,12 @@ fn __action11< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, f, _): (usize, CallInstructionValue<'input>, usize), -) -> FunctionPart<'input> + (_, _, _): (usize, Token<'input>, usize), + (_, args, _): (usize, ::std::vec::Vec>, usize), + (_, _, _): (usize, Token<'input>, usize), +) -> Vec> { - FunctionPart::FuncName(f) + args } #[allow(unused_variables)] @@ -2022,13 +2196,10 @@ fn __action12< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, _, _): (usize, Token<'input>, usize), - (_, sid, _): (usize, CallInstructionValue<'input>, usize), - (_, f, _): (usize, CallInstructionValue<'input>, usize), - (_, _, _): (usize, Token<'input>, usize), + (_, f, _): (usize, CallArgValue<'input>, usize), ) -> FunctionPart<'input> { - FunctionPart::ServiceIdWithFuncName(sid, f) + FunctionPart::FuncName(f) } #[allow(unused_variables)] @@ -2038,10 +2209,13 @@ fn __action13< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, pid, _): (usize, CallInstructionValue<'input>, usize), -) -> PeerPart<'input> + (_, _, _): (usize, Token<'input>, usize), + (_, sid, _): (usize, CallArgValue<'input>, usize), + (_, f, _): (usize, CallArgValue<'input>, usize), + (_, _, _): (usize, Token<'input>, usize), +) -> FunctionPart<'input> { - PeerPart::PeerPk(pid) + FunctionPart::ServiceIdWithFuncName(sid, f) } #[allow(unused_variables)] @@ -2051,13 +2225,10 @@ fn __action14< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, _, _): (usize, Token<'input>, usize), - (_, pid, _): (usize, CallInstructionValue<'input>, usize), - (_, sid, _): (usize, CallInstructionValue<'input>, usize), - (_, _, _): (usize, Token<'input>, usize), + (_, pid, _): (usize, CallArgValue<'input>, usize), ) -> PeerPart<'input> { - PeerPart::PeerPkWithServiceId(pid, sid) + PeerPart::PeerPk(pid) } #[allow(unused_variables)] @@ -2067,10 +2238,13 @@ fn __action15< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, s, _): (usize, &'input str, usize), -) -> CallOutput<'input> + (_, _, _): (usize, Token<'input>, usize), + (_, pid, _): (usize, CallArgValue<'input>, usize), + (_, sid, _): (usize, CallArgValue<'input>, usize), + (_, _, _): (usize, Token<'input>, usize), +) -> PeerPart<'input> { - CallOutput::Scalar(s) + PeerPart::PeerPkWithServiceId(pid, sid) } #[allow(unused_variables)] @@ -2080,16 +2254,136 @@ fn __action16< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, a, _): (usize, &'input str, usize), -) -> CallOutput<'input> + (_, s, _): (usize, &'input str, usize), +) -> CallOutputValue<'input> { - CallOutput::Accumulator(a) + CallOutputValue::Scalar(s) } #[allow(unused_variables)] fn __action17< 'err, 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, a, _): (usize, &'input str, usize), +) -> CallOutputValue<'input> +{ + CallOutputValue::Accumulator(a) +} + +#[allow(unused_variables)] +fn __action18< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> CallArgValue<'input> +{ + __0 +} + +#[allow(unused_variables)] +fn __action19< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> CallArgValue<'input> +{ + __0 +} + +#[allow(unused_variables)] +fn __action20< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> CallArgValue<'input> +{ + __0 +} + +#[allow(unused_variables)] +fn __action21< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> CallArgValue<'input> +{ + __0 +} + +#[allow(unused_variables)] +fn __action22< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, s, _): (usize, &'input str, usize), +) -> CallArgValue<'input> +{ + CallArgValue::Literal(s) +} + +#[allow(unused_variables)] +fn __action23< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, s, _): (usize, &'input str, usize), +) -> CallArgValue<'input> +{ + CallArgValue::Variable(s) +} + +#[allow(unused_variables)] +fn __action24< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, v, _): (usize, (&'input str, usize), usize), +) -> CallArgValue<'input> +{ + { + let (variable, path) = into_variable_and_path(v.0, v.1); + CallArgValue::JsonPath { variable, path } + } +} + +#[allow(unused_variables)] +fn __action25< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, __0, _): (usize, Token<'input>, usize), +) -> CallArgValue<'input> +{ + CallArgValue::InitPeerId +} + +#[allow(unused_variables)] +fn __action26< + 'err, + 'input, >( input: &'input str, errors: &'err mut Vec, LexerError>>, @@ -2100,7 +2394,7 @@ fn __action17< } #[allow(unused_variables)] -fn __action18< +fn __action27< 'err, 'input, >( @@ -2115,127 +2409,6 @@ fn __action18< } } -#[allow(unused_variables)] -fn __action19< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> CallInstructionValue<'input> -{ - __0 -} - -#[allow(unused_variables)] -fn __action20< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> CallInstructionValue<'input> -{ - __0 -} - -#[allow(unused_variables)] -fn __action21< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> CallInstructionValue<'input> -{ - __0 -} - -#[allow(unused_variables)] -fn __action22< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> CallInstructionValue<'input> -{ - __0 -} - -#[allow(unused_variables)] -fn __action23< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, s, _): (usize, &'input str, usize), -) -> CallInstructionValue<'input> -{ - CallInstructionValue::Literal(s) -} - -#[allow(unused_variables)] -fn __action24< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, s, _): (usize, &'input str, usize), -) -> CallInstructionValue<'input> -{ - CallInstructionValue::Variable(s) -} - -#[allow(unused_variables)] -fn __action25< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, v, _): (usize, (&'input str, usize), usize), -) -> CallInstructionValue<'input> -{ - { - let (variable, path) = into_variable_and_path(v.0, v.1); - CallInstructionValue::JsonPath { variable, path } - } -} - -#[allow(unused_variables)] -fn __action26< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, Token<'input>, usize), -) -> CallInstructionValue<'input> -{ - CallInstructionValue::InitPeerId -} - -#[allow(unused_variables)] -fn __action27< - 'err, - 'input, ->( - input: &'input str, - errors: &'err mut Vec, LexerError>>, - __lookbehind: &usize, - __lookahead: &usize, -) -> ::std::vec::Vec> -{ - vec![] -} - #[allow(unused_variables)] fn __action28< 'err, @@ -2243,10 +2416,10 @@ fn __action28< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, v, _): (usize, ::std::vec::Vec>, usize), -) -> ::std::vec::Vec> + (_, s, _): (usize, &'input str, usize), +) -> MatchableValue<'input> { - v + MatchableValue::Variable(s) } #[allow(unused_variables)] @@ -2256,10 +2429,10 @@ fn __action29< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> CallInstructionValue<'input> + (_, s, _): (usize, &'input str, usize), +) -> MatchableValue<'input> { - __0 + MatchableValue::Literal(s) } #[allow(unused_variables)] @@ -2269,10 +2442,13 @@ fn __action30< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallOutput<'input>, usize), -) -> ::std::option::Option> + (_, v, _): (usize, (&'input str, usize), usize), +) -> MatchableValue<'input> { - Some(__0) + { + let (variable, path) = into_variable_and_path(v.0, v.1); + MatchableValue::JsonPath { variable, path } + } } #[allow(unused_variables)] @@ -2284,9 +2460,9 @@ fn __action31< errors: &'err mut Vec, LexerError>>, __lookbehind: &usize, __lookahead: &usize, -) -> ::std::option::Option> +) -> ::std::vec::Vec> { - None + vec![] } #[allow(unused_variables)] @@ -2296,10 +2472,10 @@ fn __action32< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, __0, _): (usize, CallInstructionValue<'input>, usize), -) -> ::std::vec::Vec> + (_, v, _): (usize, ::std::vec::Vec>, usize), +) -> ::std::vec::Vec> { - vec![__0] + v } #[allow(unused_variables)] @@ -2309,11 +2485,10 @@ fn __action33< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - (_, v, _): (usize, ::std::vec::Vec>, usize), - (_, e, _): (usize, CallInstructionValue<'input>, usize), -) -> ::std::vec::Vec> + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> CallArgValue<'input> { - { let mut v = v; v.push(e); v } + __0 } #[allow(unused_variables)] @@ -2323,22 +2498,10 @@ fn __action34< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - __0: (usize, CallInstructionValue<'input>, usize), -) -> ::std::vec::Vec> + (_, __0, _): (usize, CallOutputValue<'input>, usize), +) -> ::std::option::Option> { - let __start0 = __0.0.clone(); - let __end0 = __0.2.clone(); - let __temp0 = __action29( - input, - errors, - __0, - ); - let __temp0 = (__start0, __temp0, __end0); - __action32( - input, - errors, - __temp0, - ) + Some(__0) } #[allow(unused_variables)] @@ -2348,24 +2511,11 @@ fn __action35< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - __0: (usize, ::std::vec::Vec>, usize), - __1: (usize, CallInstructionValue<'input>, usize), -) -> ::std::vec::Vec> + __lookbehind: &usize, + __lookahead: &usize, +) -> ::std::option::Option> { - let __start0 = __1.0.clone(); - let __end0 = __1.2.clone(); - let __temp0 = __action29( - input, - errors, - __1, - ); - let __temp0 = (__start0, __temp0, __end0); - __action33( - input, - errors, - __0, - __temp0, - ) + None } #[allow(unused_variables)] @@ -2375,26 +2525,10 @@ fn __action36< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - __0: (usize, Token<'input>, usize), - __1: (usize, Token<'input>, usize), -) -> Vec> + (_, __0, _): (usize, CallArgValue<'input>, usize), +) -> ::std::vec::Vec> { - let __start0 = __0.2.clone(); - let __end0 = __1.0.clone(); - let __temp0 = __action27( - input, - errors, - &__start0, - &__end0, - ); - let __temp0 = (__start0, __temp0, __end0); - __action10( - input, - errors, - __0, - __temp0, - __1, - ) + vec![__0] } #[allow(unused_variables)] @@ -2404,32 +2538,127 @@ fn __action37< >( input: &'input str, errors: &'err mut Vec, LexerError>>, - __0: (usize, Token<'input>, usize), - __1: (usize, ::std::vec::Vec>, usize), - __2: (usize, Token<'input>, usize), -) -> Vec> + (_, v, _): (usize, ::std::vec::Vec>, usize), + (_, e, _): (usize, CallArgValue<'input>, usize), +) -> ::std::vec::Vec> { - let __start0 = __1.0.clone(); - let __end0 = __1.2.clone(); - let __temp0 = __action28( - input, - errors, - __1, - ); - let __temp0 = (__start0, __temp0, __end0); - __action10( - input, - errors, - __0, - __temp0, - __2, - ) + { let mut v = v; v.push(e); v } } #[allow(unused_variables)] fn __action38< 'err, 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __0: (usize, CallArgValue<'input>, usize), +) -> ::std::vec::Vec> +{ + let __start0 = __0.0.clone(); + let __end0 = __0.2.clone(); + let __temp0 = __action33( + input, + errors, + __0, + ); + let __temp0 = (__start0, __temp0, __end0); + __action36( + input, + errors, + __temp0, + ) +} + +#[allow(unused_variables)] +fn __action39< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __0: (usize, ::std::vec::Vec>, usize), + __1: (usize, CallArgValue<'input>, usize), +) -> ::std::vec::Vec> +{ + let __start0 = __1.0.clone(); + let __end0 = __1.2.clone(); + let __temp0 = __action33( + input, + errors, + __1, + ); + let __temp0 = (__start0, __temp0, __end0); + __action37( + input, + errors, + __0, + __temp0, + ) +} + +#[allow(unused_variables)] +fn __action40< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __0: (usize, Token<'input>, usize), + __1: (usize, Token<'input>, usize), +) -> Vec> +{ + let __start0 = __0.2.clone(); + let __end0 = __1.0.clone(); + let __temp0 = __action31( + input, + errors, + &__start0, + &__end0, + ); + let __temp0 = (__start0, __temp0, __end0); + __action11( + input, + errors, + __0, + __temp0, + __1, + ) +} + +#[allow(unused_variables)] +fn __action41< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + __0: (usize, Token<'input>, usize), + __1: (usize, ::std::vec::Vec>, usize), + __2: (usize, Token<'input>, usize), +) -> Vec> +{ + let __start0 = __1.0.clone(); + let __end0 = __1.2.clone(); + let __temp0 = __action32( + input, + errors, + __1, + ); + let __temp0 = (__start0, __temp0, __end0); + __action11( + input, + errors, + __0, + __temp0, + __2, + ) +} + +#[allow(unused_variables)] +fn __action42< + 'err, + 'input, >( input: &'input str, errors: &'err mut Vec, LexerError>>, @@ -2437,14 +2666,14 @@ fn __action38< __1: (usize, Token<'input>, usize), __2: (usize, PeerPart<'input>, usize), __3: (usize, FunctionPart<'input>, usize), - __4: (usize, Vec>, usize), - __5: (usize, CallOutput<'input>, usize), + __4: (usize, Vec>, usize), + __5: (usize, CallOutputValue<'input>, usize), __6: (usize, Token<'input>, usize), ) -> Box> { let __start0 = __5.0.clone(); let __end0 = __5.2.clone(); - let __temp0 = __action30( + let __temp0 = __action34( input, errors, __5, @@ -2464,7 +2693,7 @@ fn __action38< } #[allow(unused_variables)] -fn __action39< +fn __action43< 'err, 'input, >( @@ -2474,13 +2703,13 @@ fn __action39< __1: (usize, Token<'input>, usize), __2: (usize, PeerPart<'input>, usize), __3: (usize, FunctionPart<'input>, usize), - __4: (usize, Vec>, usize), + __4: (usize, Vec>, usize), __5: (usize, Token<'input>, usize), ) -> Box> { let __start0 = __4.2.clone(); let __end0 = __5.0.clone(); - let __temp0 = __action31( + let __temp0 = __action35( input, errors, &__start0, diff --git a/crates/air-parser/src/parser/ast.rs b/crates/air-parser/src/parser/ast.rs index 3395497b..ffb29da3 100644 --- a/crates/air-parser/src/parser/ast.rs +++ b/crates/air-parser/src/parser/ast.rs @@ -27,6 +27,7 @@ pub enum Instruction<'i> { Seq(Seq<'i>), Par(Par<'i>), Xor(Xor<'i>), + Match(Match<'i>), Fold(Fold<'i>), Next(Next<'i>), Error, @@ -34,30 +35,30 @@ pub enum Instruction<'i> { #[derive(Serialize, Debug, PartialEq, Eq)] pub enum PeerPart<'i> { - PeerPk(CallInstructionValue<'i>), - PeerPkWithServiceId(CallInstructionValue<'i>, CallInstructionValue<'i>), + PeerPk(CallArgValue<'i>), + PeerPkWithServiceId(CallArgValue<'i>, CallArgValue<'i>), } #[derive(Serialize, Debug, PartialEq, Eq)] pub enum FunctionPart<'i> { - FuncName(CallInstructionValue<'i>), - ServiceIdWithFuncName(CallInstructionValue<'i>, CallInstructionValue<'i>), + FuncName(CallArgValue<'i>), + ServiceIdWithFuncName(CallArgValue<'i>, CallArgValue<'i>), } #[derive(Serialize, Debug, PartialEq, Eq)] pub struct Call<'i> { pub peer_part: PeerPart<'i>, pub function_part: FunctionPart<'i>, - pub args: Rc>>, - pub output: CallOutput<'i>, + pub args: Rc>>, + pub output: CallOutputValue<'i>, } #[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] -pub enum CallInstructionValue<'i> { - Variable(&'i str), - Literal(&'i str), - JsonPath { variable: &'i str, path: &'i str }, +pub enum CallArgValue<'i> { InitPeerId, + Literal(&'i str), + Variable(&'i str), + JsonPath { variable: &'i str, path: &'i str }, } #[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] @@ -66,8 +67,15 @@ pub enum IterableValue<'i> { JsonPath { variable: &'i str, path: &'i str }, } +#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +pub enum MatchableValue<'i> { + Literal(&'i str), + Variable(&'i str), + JsonPath { variable: &'i str, path: &'i str }, +} + #[derive(Serialize, Debug, Hash, PartialEq, Eq, Clone)] -pub enum CallOutput<'i> { +pub enum CallOutputValue<'i> { Scalar(&'i str), Accumulator(&'i str), None, @@ -82,6 +90,13 @@ pub struct Par<'i>(pub Box>, pub Box>); #[derive(Serialize, Debug, PartialEq, Eq)] pub struct Xor<'i>(pub Box>, pub Box>); +#[derive(Serialize, Debug, PartialEq, Eq)] +pub struct Match<'i>( + pub MatchableValue<'i>, + pub MatchableValue<'i>, + pub Box>, +); + #[derive(Serialize, Debug, PartialEq, Eq)] pub struct Fold<'i> { pub iterable: IterableValue<'i>, diff --git a/crates/air-parser/src/parser/lexer/air_lexer.rs b/crates/air-parser/src/parser/lexer/air_lexer.rs index eb35b46b..aee3ced7 100644 --- a/crates/air-parser/src/parser/lexer/air_lexer.rs +++ b/crates/air-parser/src/parser/lexer/air_lexer.rs @@ -180,6 +180,7 @@ fn string_to_token(input: &str, start_pos: usize) -> Result { FOLD_INSTR => Ok(Token::Fold), XOR_INSTR => Ok(Token::Xor), NEXT_INSTR => Ok(Token::Next), + MATCH_INSTR => Ok(Token::Match), INIT_PEER_ID => Ok(Token::InitPeerId), @@ -234,6 +235,7 @@ const NULL_INSTR: &str = "null"; const FOLD_INSTR: &str = "fold"; const XOR_INSTR: &str = "xor"; const NEXT_INSTR: &str = "next"; +const MATCH_INSTR: &str = "match"; const INIT_PEER_ID: &str = "%init_peer_id%"; diff --git a/crates/air-parser/src/parser/lexer/token.rs b/crates/air-parser/src/parser/lexer/token.rs index 62095090..e31e9193 100644 --- a/crates/air-parser/src/parser/lexer/token.rs +++ b/crates/air-parser/src/parser/lexer/token.rs @@ -35,4 +35,5 @@ pub enum Token<'input> { Fold, Xor, Next, + Match, } diff --git a/crates/air-parser/src/parser/tests.rs b/crates/air-parser/src/parser/tests.rs index fbba369a..1877eb3b 100644 --- a/crates/air-parser/src/parser/tests.rs +++ b/crates/air-parser/src/parser/tests.rs @@ -27,8 +27,8 @@ fn parse(source_code: &str) -> Instruction { #[test] fn parse_seq() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -59,8 +59,8 @@ fn parse_seq() { #[test] fn parse_seq_seq() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -102,8 +102,8 @@ fn parse_seq_seq() { #[test] fn parse_json_path() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -126,8 +126,8 @@ fn parse_json_path() { #[test] fn parse_json_path_complex() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -164,8 +164,8 @@ fn parse_json_path_complex() { #[test] fn json_path_square_braces() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -267,8 +267,8 @@ fn parse_fold_with_xor_par_seq() { #[test] fn parse_init_peer_id() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -307,8 +307,8 @@ fn parse_init_peer_id() { #[test] fn seq_par_call() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -361,8 +361,8 @@ fn seq_par_call() { #[test] fn seq_with_empty_and_dash() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; @@ -449,8 +449,8 @@ fn seq_with_empty_and_dash() { #[test] fn no_output() { use ast::Call; - use ast::CallInstructionValue::*; - use ast::CallOutput::*; + use ast::CallArgValue::*; + use ast::CallOutputValue::*; use ast::FunctionPart::*; use ast::PeerPart::*; diff --git a/stepper-lib/Cargo.toml b/stepper-lib/Cargo.toml index 0e9607a1..b2a37336 100644 --- a/stepper-lib/Cargo.toml +++ b/stepper-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stepper-lib" -version = "0.3.0" +version = "0.4.0" authors = ["Fluence Labs"] edition = "2018" diff --git a/stepper-lib/src/execution/air/call/resolved_call.rs b/stepper-lib/src/execution/air/call/resolved_call.rs index 032a6730..c4fe3b93 100644 --- a/stepper-lib/src/execution/air/call/resolved_call.rs +++ b/stepper-lib/src/execution/air/call/resolved_call.rs @@ -29,7 +29,7 @@ use crate::JValue; use crate::ResolvedTriplet; use crate::SecurityTetraplet; -use air_parser::ast::{CallInstructionValue, CallOutput}; +use air_parser::ast::{CallArgValue, CallOutputValue}; use std::rc::Rc; @@ -37,8 +37,8 @@ use std::rc::Rc; #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub(super) struct ResolvedCall<'i> { triplet: Rc, - function_arg_paths: Rc>>, - output: CallOutput<'i>, + function_arg_paths: Rc>>, + output: CallOutputValue<'i>, } #[derive(Debug, Clone, Eq, PartialEq, Hash)] diff --git a/stepper-lib/src/execution/air/call/triplet.rs b/stepper-lib/src/execution/air/call/triplet.rs index 50ed3d76..0067286a 100644 --- a/stepper-lib/src/execution/air/call/triplet.rs +++ b/stepper-lib/src/execution/air/call/triplet.rs @@ -19,15 +19,15 @@ use super::ExecutionError; use super::ExecutionResult; use crate::JValue; -use air_parser::ast::{CallInstructionValue, FunctionPart, PeerPart}; +use air_parser::ast::{CallArgValue, FunctionPart, PeerPart}; use polyplets::ResolvedTriplet; /// Triplet represents a location of the executable code in the network. /// It is build from `PeerPart` and `FunctionPart` of a `Call` instruction. pub(super) struct Triplet<'a, 'i> { - pub(super) peer_pk: &'a CallInstructionValue<'i>, - pub(super) service_id: &'a CallInstructionValue<'i>, - pub(super) function_name: &'a CallInstructionValue<'i>, + pub(super) peer_pk: &'a CallArgValue<'i>, + pub(super) service_id: &'a CallArgValue<'i>, + pub(super) function_name: &'a CallArgValue<'i>, } impl<'a, 'i> Triplet<'a, 'i> { @@ -77,18 +77,18 @@ impl<'a, 'i> Triplet<'a, 'i> { /// Resolve value to string by either resolving variable from `ExecutionCtx`, taking literal value, or etc. // TODO: return Rc to avoid excess cloning -fn resolve_to_string<'i>(value: &CallInstructionValue<'i>, ctx: &ExecutionCtx<'i>) -> ExecutionResult { +fn resolve_to_string<'i>(value: &CallArgValue<'i>, ctx: &ExecutionCtx<'i>) -> ExecutionResult { use crate::execution::utils::resolve_to_jvaluable; let resolved = match value { - CallInstructionValue::InitPeerId => ctx.init_peer_id.clone(), - CallInstructionValue::Literal(value) => value.to_string(), - CallInstructionValue::Variable(name) => { + CallArgValue::InitPeerId => ctx.init_peer_id.clone(), + CallArgValue::Literal(value) => value.to_string(), + CallArgValue::Variable(name) => { let resolved = resolve_to_jvaluable(name, ctx)?; let jvalue = resolved.into_jvalue(); jvalue_to_string(jvalue)? } - CallInstructionValue::JsonPath { variable, path } => { + CallArgValue::JsonPath { variable, path } => { let resolved = resolve_to_jvaluable(variable, ctx)?; let resolved = resolved.apply_json_path(path)?; vec_to_string(resolved, path)? diff --git a/stepper-lib/src/execution/air/call/utils.rs b/stepper-lib/src/execution/air/call/utils.rs index b0f08ff2..bd81c0dd 100644 --- a/stepper-lib/src/execution/air/call/utils.rs +++ b/stepper-lib/src/execution/air/call/utils.rs @@ -22,7 +22,7 @@ use crate::contexts::execution_trace::*; use crate::log_targets::EXECUTED_STATE_CHANGING; use crate::JValue; -use air_parser::ast::CallOutput; +use air_parser::ast::CallOutputValue; use polyplets::ResolvedTriplet; use std::rc::Rc; @@ -31,7 +31,7 @@ use std::rc::Rc; pub(super) fn set_local_call_result<'i>( result: Rc, triplet: Rc, - output: &CallOutput<'i>, + output: &CallOutputValue<'i>, exec_ctx: &mut ExecutionCtx<'i>, ) -> ExecutionResult<()> { use crate::contexts::execution::AValue; @@ -42,7 +42,7 @@ pub(super) fn set_local_call_result<'i>( let executed_result = ResolvedCallResult { result, triplet }; match output { - CallOutput::Scalar(name) => { + CallOutputValue::Scalar(name) => { if let Some(fold_block_name) = exec_ctx.met_folds.back() { let fold_state = match exec_ctx.data_cache.get_mut(*fold_block_name) { Some(AValue::JValueFoldCursor(fold_state)) => fold_state, @@ -73,7 +73,7 @@ pub(super) fn set_local_call_result<'i>( } }; } - CallOutput::Accumulator(name) => { + CallOutputValue::Accumulator(name) => { match exec_ctx.data_cache.entry(name.to_string()) { Occupied(mut entry) => match entry.get_mut() { // if result is an array, insert result to the end of the array @@ -85,7 +85,7 @@ pub(super) fn set_local_call_result<'i>( } }; } - CallOutput::None => {} + CallOutputValue::None => {} } Ok(()) @@ -113,7 +113,7 @@ pub(super) fn set_remote_call_result<'i>( /// and returns Ok(true) if the call should be executed further. pub(super) fn handle_prev_state<'i>( triplet: &Rc, - output: &CallOutput<'i>, + output: &CallOutputValue<'i>, prev_state: ExecutedState, exec_ctx: &mut ExecutionCtx<'i>, trace_ctx: &mut ExecutionTraceCtx, diff --git a/stepper-lib/src/execution/air/match_.rs b/stepper-lib/src/execution/air/match_.rs new file mode 100644 index 00000000..4a7e49cd --- /dev/null +++ b/stepper-lib/src/execution/air/match_.rs @@ -0,0 +1,192 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * 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 + * + * http://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. + */ + +use super::ExecutionCtx; +use super::ExecutionError; +use super::ExecutionResult; +use super::ExecutionTraceCtx; +use crate::log_instruction; + +use air_parser::ast::Match; +use air_parser::ast::MatchableValue; + +impl<'i> super::ExecutableInstruction<'i> for Match<'i> { + fn execute(&self, exec_ctx: &mut ExecutionCtx<'i>, trace_ctx: &mut ExecutionTraceCtx) -> ExecutionResult<()> { + log_instruction!(match_, exec_ctx, trace_ctx); + + let left_value = &self.0; + let right_value = &self.1; + let is_equal_values = compare_matchable(left_value, right_value, exec_ctx)?; + + if !is_equal_values { + return Err(ExecutionError::MatchWithoutXorError); + } + + self.2.execute(exec_ctx, trace_ctx) + } +} + +fn compare_matchable<'ctx>( + left: &MatchableValue<'_>, + right: &MatchableValue<'_>, + exec_ctx: &'ctx ExecutionCtx<'_>, +) -> ExecutionResult { + use crate::execution::utils::resolve_to_jvaluable; + use MatchableValue::*; + + match (left, right) { + (Literal(left_name), Literal(right_name)) => Ok(left_name == right_name), + (Variable(left_name), Variable(right_name)) => { + let left_jvaluable = resolve_to_jvaluable(left_name, exec_ctx)?; + let left_value = left_jvaluable.as_jvalue(); + + let right_jvaluable = resolve_to_jvaluable(right_name, exec_ctx)?; + let right_value = right_jvaluable.as_jvalue(); + + Ok(left_value == right_value) + } + (JsonPath { variable: lv, path: lp }, JsonPath { variable: rv, path: rp }) => { + let left_jvaluable = resolve_to_jvaluable(lv, exec_ctx)?; + let left_value = left_jvaluable.apply_json_path(lp)?; + + let right_jvaluable = resolve_to_jvaluable(rv, exec_ctx)?; + let right_value = right_jvaluable.apply_json_path(rp)?; + + Ok(left_value == right_value) + } + _ => Ok(false), + } +} + +#[cfg(test)] +mod tests { + use crate::contexts::execution_trace::ExecutionTrace; + use crate::JValue; + + use aqua_test_utils::call_vm; + use aqua_test_utils::create_aqua_vm; + use aqua_test_utils::echo_string_call_service; + + use std::rc::Rc; + + #[test] + fn match_equal() { + use crate::contexts::execution_trace::CallResult::*; + use crate::contexts::execution_trace::ExecutedState::*; + + let set_variable_peer_id = "set_variable_peer_id"; + let mut set_variable_vm = create_aqua_vm(echo_string_call_service(), set_variable_peer_id); + + let local_peer_id = "local_peer_id"; + let mut vm = create_aqua_vm(echo_string_call_service(), local_peer_id); + + let script = format!( + r#" + (seq + (seq + (call "{0}" ("" "") ["value_1"] value_1) + (call "{0}" ("" "") ["value_1"] value_2) + ) + (xor + (match value_1 value_2 + (call "{1}" ("service_id_2" "local_fn_name") ["result_1"] result_1) + ) + (call "{1}" ("service_id_2" "local_fn_name") ["result_2"] result_2) + ) + )"#, + set_variable_peer_id, local_peer_id + ); + + let res = call_vm!(set_variable_vm, "asd", script.clone(), "", ""); + let res = call_vm!(vm, "asd", script, "", res.data); + + let actual_trace: ExecutionTrace = serde_json::from_slice(&res.data).expect("should be valid json"); + let expected_executed_call_result = Call(Executed(Rc::new(JValue::String(String::from("result_1"))))); + + assert_eq!(actual_trace.len(), 3); + assert_eq!(actual_trace[2], expected_executed_call_result); + } + + #[test] + fn match_not_equal() { + use crate::contexts::execution_trace::CallResult::*; + use crate::contexts::execution_trace::ExecutedState::*; + + let set_variable_peer_id = "set_variable_peer_id"; + let mut set_variable_vm = create_aqua_vm(echo_string_call_service(), set_variable_peer_id); + + let local_peer_id = "local_peer_id"; + let mut vm = create_aqua_vm(echo_string_call_service(), local_peer_id); + + let script = format!( + r#" + (seq + (seq + (call "{0}" ("" "") ["value_1"] value_1) + (call "{0}" ("" "") ["value_2"] value_2) + ) + (xor + (match value_1 value_2 + (call "{1}" ("service_id_2" "local_fn_name") ["result_1"] result_1) + ) + (call "{1}" ("service_id_2" "local_fn_name") ["result_2"] result_2) + ) + )"#, + set_variable_peer_id, local_peer_id + ); + + let res = call_vm!(set_variable_vm, "asd", script.clone(), "", ""); + let res = call_vm!(vm, "asd", script, "", res.data); + + let actual_trace: ExecutionTrace = serde_json::from_slice(&res.data).expect("should be valid json"); + let expected_executed_call_result = Call(Executed(Rc::new(JValue::String(String::from("result_2"))))); + + assert_eq!(actual_trace.len(), 3); + assert_eq!(actual_trace[2], expected_executed_call_result); + } + + #[test] + fn match_without_xor() { + let set_variable_peer_id = "set_variable_peer_id"; + let mut set_variable_vm = create_aqua_vm(echo_string_call_service(), set_variable_peer_id); + + let local_peer_id = "local_peer_id"; + let mut vm = create_aqua_vm(echo_string_call_service(), local_peer_id); + + let script = format!( + r#" + (seq + (seq + (call "{0}" ("" "") ["value_1"] value_1) + (call "{0}" ("" "") ["value_2"] value_2) + ) + (match value_1 value_2 + (call "{1}" ("service_id_2" "local_fn_name") ["result_1"] result_1) + ) + )"#, + set_variable_peer_id, local_peer_id + ); + + let res = call_vm!(set_variable_vm, "asd", script.clone(), "", ""); + let res = call_vm!(vm, "asd", script.clone(), "", res.data); + + assert_eq!(res.ret_code, 1015); + + let res = call_vm!(vm, "asd", script, "", res.data); + + assert_eq!(res.ret_code, 1015); + } +} diff --git a/stepper-lib/src/execution/air/mod.rs b/stepper-lib/src/execution/air/mod.rs index 70ee94a5..43d20d71 100644 --- a/stepper-lib/src/execution/air/mod.rs +++ b/stepper-lib/src/execution/air/mod.rs @@ -16,6 +16,7 @@ mod call; mod fold; +mod match_; mod null; mod par; mod seq; @@ -44,7 +45,8 @@ impl<'i> ExecutableInstruction<'i> for Instruction<'i> { Instruction::Par(par) => par.execute(exec_ctx, trace_ctx), Instruction::Seq(seq) => seq.execute(exec_ctx, trace_ctx), Instruction::Xor(xor) => xor.execute(exec_ctx, trace_ctx), - Instruction::Error => unreachable!("should not execute if parsing failed. QED."), + Instruction::Match(match_) => match_.execute(exec_ctx, trace_ctx), + Instruction::Error => unreachable!("should not execute if parsing succeeded. QED."), } } } diff --git a/stepper-lib/src/execution/errors.rs b/stepper-lib/src/execution/errors.rs index 6e875b59..a10850b4 100644 --- a/stepper-lib/src/execution/errors.rs +++ b/stepper-lib/src/execution/errors.rs @@ -81,6 +81,10 @@ pub(crate) enum ExecutionError { /// Errors encountered while shadowing non-scalar values. #[error("variable with name '{0}' can't be shadowed, shadowing is supported only for scalar values")] ShadowingError(String), + + /// This error type is produced by a match to notify xor that compared values aren't equal. + #[error("match is used without corresponding xor")] + MatchWithoutXorError, } impl ExecutionError { @@ -102,6 +106,7 @@ impl ExecutionError { MultipleFoldStates(_) => 12, InvalidExecutedState(..) => 13, ShadowingError(_) => 14, + MatchWithoutXorError => 15, } } } diff --git a/stepper-lib/src/execution/utils/resolve.rs b/stepper-lib/src/execution/utils/resolve.rs index 2bf86958..3d068f43 100644 --- a/stepper-lib/src/execution/utils/resolve.rs +++ b/stepper-lib/src/execution/utils/resolve.rs @@ -22,11 +22,11 @@ use crate::execution::ExecutionResult; use crate::JValue; use crate::SecurityTetraplet; -use air_parser::ast::CallInstructionValue; +use air_parser::ast::CallArgValue; /// Resolve value to called function arguments. pub(crate) fn resolve_to_args<'i>( - value: &CallInstructionValue<'i>, + value: &CallArgValue<'i>, ctx: &ExecutionCtx<'i>, ) -> ExecutionResult<(JValue, Vec)> { fn handle_string_arg<'i>(arg: &str, ctx: &ExecutionCtx<'i>) -> ExecutionResult<(JValue, Vec)> { @@ -37,16 +37,16 @@ pub(crate) fn resolve_to_args<'i>( } match value { - CallInstructionValue::InitPeerId => handle_string_arg(ctx.init_peer_id.as_str(), ctx), - CallInstructionValue::Literal(value) => handle_string_arg(value, ctx), - CallInstructionValue::Variable(name) => { + CallArgValue::InitPeerId => handle_string_arg(ctx.init_peer_id.as_str(), ctx), + CallArgValue::Literal(value) => handle_string_arg(value, ctx), + CallArgValue::Variable(name) => { let resolved = resolve_to_jvaluable(name, ctx)?; let tetraplets = resolved.as_tetraplets(); let jvalue = resolved.into_jvalue(); Ok((jvalue, tetraplets)) } - CallInstructionValue::JsonPath { variable, path } => { + CallArgValue::JsonPath { variable, path } => { let resolved = resolve_to_jvaluable(variable, ctx)?; let (jvalue, tetraplets) = resolved.apply_json_path_with_tetraplets(path)?; let jvalue = jvalue.into_iter().cloned().collect::>();