From c6d8a458da5e21a86f6391c9a6184ce5101706fe Mon Sep 17 00:00:00 2001 From: vms Date: Tue, 16 Feb 2021 09:45:33 +0300 Subject: [PATCH] Support numbers and booleans (#64) --- Cargo.lock | 7 +- crates/air-parser/Cargo.toml | 3 +- crates/air-parser/src/parser/air.lalrpop | 5 + crates/air-parser/src/parser/air.rs | 1170 +++++++++-------- crates/air-parser/src/parser/air_parser.rs | 18 + crates/air-parser/src/parser/ast.rs | 54 +- .../air-parser/src/parser/lexer/air_lexer.rs | 69 +- .../src/parser/lexer/call_variable_parser.rs | 262 ++++ crates/air-parser/src/parser/lexer/errors.rs | 25 +- crates/air-parser/src/parser/lexer/mod.rs | 8 + crates/air-parser/src/parser/lexer/tests.rs | 349 +++-- crates/air-parser/src/parser/lexer/token.rs | 77 +- crates/air-parser/src/parser/lexer/utils.rs | 43 + stepper-lib/Cargo.toml | 2 +- .../src/execution/air/call/resolved_call.rs | 4 +- .../compare_matchable/compare_matchable.rs | 79 +- stepper-lib/src/execution/mod.rs | 7 + stepper-lib/src/execution/utils/resolve.rs | 13 +- stepper-lib/src/lib.rs | 7 - .../auth_module/Cargo.lock | 3 +- .../log_storage/Cargo.lock | 3 +- stepper/Cargo.toml | 2 +- 22 files changed, 1462 insertions(+), 748 deletions(-) create mode 100644 crates/air-parser/src/parser/lexer/call_variable_parser.rs create mode 100644 crates/air-parser/src/parser/lexer/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 6df85f38..06a6951c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ [[package]] name = "air-parser" -version = "0.3.0" +version = "0.4.0" dependencies = [ "codespan", "codespan-reporting", @@ -21,6 +21,7 @@ dependencies = [ "lalrpop-util", "regex", "serde", + "serde_json", "thiserror", ] @@ -57,7 +58,7 @@ dependencies = [ [[package]] name = "aquamarine" -version = "0.4.1" +version = "0.5.0" dependencies = [ "fluence", "log", @@ -1693,7 +1694,7 @@ dependencies = [ [[package]] name = "stepper-lib" -version = "0.4.1" +version = "0.5.0" dependencies = [ "air-parser", "aqua-test-utils", diff --git a/crates/air-parser/Cargo.toml b/crates/air-parser/Cargo.toml index 9830fbd1..136ce362 100644 --- a/crates/air-parser/Cargo.toml +++ b/crates/air-parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "air-parser" -version = "0.3.0" +version = "0.4.0" authors = ["Fluence Labs"] edition = "2018" license = "Apache-2.0" @@ -16,6 +16,7 @@ codespan-reporting = "0.9.5" # TODO: hide serde behind a feature serde = { version = "=1.0.118", features = ["rc"] } +serde_json = "=1.0.61" thiserror = "1.0.23" diff --git a/crates/air-parser/src/parser/air.lalrpop b/crates/air-parser/src/parser/air.lalrpop index 8ac21974..d2cac464 100644 --- a/crates/air-parser/src/parser/air.lalrpop +++ b/crates/air-parser/src/parser/air.lalrpop @@ -2,6 +2,7 @@ use crate::parser::ast::*; use crate::parser::into_variable_and_path; use crate::parser::lexer::LexerError; use crate::parser::lexer::Token; +use crate::parser::lexer::Number; use lalrpop_util::ErrorRecovery; use std::rc::Rc; @@ -86,6 +87,8 @@ CallInstrArgValue: CallInstrArgValue<'input> = { let (variable, path) = into_variable_and_path(v.0, v.1); CallInstrArgValue::JsonPath { variable, path } }, + => CallInstrArgValue::Number(n), + => CallInstrArgValue::Boolean(b), InitPeerId => CallInstrArgValue::InitPeerId, LastError => CallInstrArgValue::LastError, } @@ -121,6 +124,8 @@ extern { Literal => Token::StringLiteral(<&'input str>), JsonPath => Token::JsonPath(<&'input str>, ), Accumulator => Token::Accumulator(<&'input str>), + Number => Token::Number(), + Boolean => Token::Boolean(), InitPeerId => Token::InitPeerId, LastError => Token::LastError, diff --git a/crates/air-parser/src/parser/air.rs b/crates/air-parser/src/parser/air.rs index 63b386c1..239d98d7 100644 --- a/crates/air-parser/src/parser/air.rs +++ b/crates/air-parser/src/parser/air.rs @@ -1,9 +1,10 @@ // auto-generated: "lalrpop 0.19.1" -// sha256: 82e6bc2eb60eaa83255bba1bf3ff823bf57f3325b2ece26fa11c2ab144b3 +// sha256: 9acb4e3c4d44725be0dbab976a8a638baa8eab91f1c9cd533f2469fe8e6e9fbb use crate::parser::ast::*; use crate::parser::into_variable_and_path; use crate::parser::lexer::LexerError; use crate::parser::lexer::Token; +use crate::parser::lexer::Number; use lalrpop_util::ErrorRecovery; use std::rc::Rc; #[allow(unused_extern_crates)] @@ -19,6 +20,7 @@ mod __parse__AIR { use crate::parser::into_variable_and_path; use crate::parser::lexer::LexerError; use crate::parser::lexer::Token; + use crate::parser::lexer::Number; use lalrpop_util::ErrorRecovery; use std::rc::Rc; #[allow(unused_extern_crates)] @@ -31,184 +33,190 @@ mod __parse__AIR { { Variant0(Token<'input>), Variant1(&'input str), - Variant2((&'input str, usize)), - Variant3(__lalrpop_util::ErrorRecovery, LexerError>), - Variant4(CallInstrArgValue<'input>), - Variant5(::std::vec::Vec>), - Variant6(Box>), - Variant7(Vec>), - Variant8(CallInstrValue<'input>), - Variant9(FunctionPart<'input>), - Variant10(IterableValue<'input>), - Variant11(MatchableValue<'input>), - Variant12(CallOutputValue<'input>), - Variant13(::std::option::Option>), - Variant14(PeerPart<'input>), + Variant2(bool), + Variant3((&'input str, usize)), + Variant4(Number), + Variant5(__lalrpop_util::ErrorRecovery, LexerError>), + Variant6(CallInstrArgValue<'input>), + Variant7(::std::vec::Vec>), + Variant8(Box>), + Variant9(Vec>), + Variant10(CallInstrValue<'input>), + Variant11(FunctionPart<'input>), + Variant12(IterableValue<'input>), + Variant13(MatchableValue<'input>), + Variant14(CallOutputValue<'input>), + Variant15(::std::option::Option>), + Variant16(PeerPart<'input>), } const __ACTION: &[i8] = &[ // State 0 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 1 - 10, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 10, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 2 - 0, 0, 0, 0, 0, 39, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 39, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 3 - 0, 0, 0, 0, 0, 41, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 41, 0, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 4 - 0, 0, 0, 0, 0, 41, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 41, 0, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 5 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 6 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 7 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 8 - 17, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 17, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 9 - 0, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 10 - 0, 0, 0, 0, 0, 41, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 41, 0, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 11 - 0, 0, 0, 0, 0, 41, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 41, 0, 0, 42, 0, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 12 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 13 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 14 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 15 - 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 16 - 0, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 17 - 0, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 18 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 19 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 20 - 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, + 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, // State 21 - 0, 61, 0, 0, 62, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 61, 0, 0, 62, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 22 - 0, 0, 0, 66, 0, 67, 68, 69, 70, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 66, 0, 67, 68, 69, 70, 71, 72, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 23 - 0, 0, 0, 0, 0, 34, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 34, 0, 35, 36, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 24 - 0, 0, 0, 79, 0, 67, 68, 69, 70, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 81, 0, 67, 68, 69, 70, 71, 72, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 25 - 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 26 - 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 27 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 30, 31, 6, 7, 8, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 30, 31, 6, 7, 8, 0, // State 28 - -32, -32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -32, + -34, -34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -34, // State 29 - 0, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 30 - 0, 45, 0, 0, 0, 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, 0, 0, 0, 0, // State 31 - -42, 0, 0, 0, 0, -42, -42, -42, 0, -42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -44, 0, 0, 0, 0, -44, 0, -44, -44, 0, -44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 32 - -43, 0, 0, 0, 0, -43, -43, -43, 0, -43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -45, 0, 0, 0, 0, -45, 0, -45, -45, 0, -45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 33 - -16, -16, -16, 0, 0, -16, -16, -16, 0, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -18, -18, -18, 0, 0, -18, 0, -18, -18, 0, -18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 34 - -18, -18, -18, 0, 0, -18, -18, -18, 0, -18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -20, -20, -20, 0, 0, -20, 0, -20, -20, 0, -20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 35 - -17, -17, -17, 0, 0, -17, -17, -17, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -19, -19, -19, 0, 0, -19, 0, -19, -19, 0, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 36 - -15, -15, -15, 0, 0, -15, -15, -15, 0, -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -17, -17, -17, 0, 0, -17, 0, -17, -17, 0, -17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 37 - 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 38 - 0, 0, 0, 0, 0, -33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 39 - 0, 0, 0, 0, 0, -34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 40 - -35, 0, 0, 0, 0, -35, 0, -35, 0, -35, 0, 0, 0, 0, 0, 0, 0, 0, 0, -35, + -37, 0, 0, 0, 0, -37, 0, 0, -37, 0, -37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -37, // State 41 - -37, 0, 0, 0, 0, -37, 0, -37, 0, -37, 0, 0, 0, 0, 0, 0, 0, 0, 0, -37, + -39, 0, 0, 0, 0, -39, 0, 0, -39, 0, -39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -39, // State 42 - -36, 0, 0, 0, 0, -36, 0, -36, 0, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, -36, + -38, 0, 0, 0, 0, -38, 0, 0, -38, 0, -38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -38, // State 43 - 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 44 - -26, -26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -26, + -28, -28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -28, // State 45 - 0, -21, -21, 0, 0, 0, 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, 0, 0, 0, 0, // State 46 - 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 47 - -28, -28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -28, + -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -30, // State 48 - 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 49 - 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 50 - 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 51 - 0, -45, 0, 0, 0, -45, -45, -45, 0, -45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -47, 0, 0, 0, -47, 0, -47, -47, 0, -47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 52 - 0, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 53 - 0, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 54 - 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 55 - 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 56 - -25, -25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -25, + -27, -27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -27, // State 57 - -24, -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -24, + -26, -26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -26, // State 58 - -29, -29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -29, + -31, -31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -31, // State 59 - 0, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 60 - -23, -23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -23, + -25, -25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -25, // State 61 - 0, -39, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, // State 62 - 0, -38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 63 - 0, 0, 0, -4, 0, -4, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -4, 0, -4, -4, -4, -4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 64 - 0, 0, 0, -7, 0, -7, -7, -7, -7, -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -7, 0, -7, -7, -7, -7, -7, -7, -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 65 - 0, -8, 0, 0, -8, -8, 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, 0, 0, 0, 0, // State 66 - 0, 0, 0, -11, 0, -11, -11, -11, -11, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -11, 0, -11, -11, -11, -11, -11, -11, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 67 - 0, 0, 0, -13, 0, -13, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -14, 0, -14, -14, -14, -14, -14, -14, -14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 68 - 0, 0, 0, -12, 0, -12, -12, -12, -12, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -15, 0, -15, -15, -15, -15, -15, -15, -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 69 - 0, 0, 0, -14, 0, -14, -14, -14, -14, -14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -12, 0, -12, -12, -12, -12, -12, -12, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 70 - 0, 0, 0, -10, 0, -10, -10, -10, -10, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -16, 0, -16, -16, -16, -16, -16, -16, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 71 - 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -10, 0, -10, -10, -10, -10, -10, -10, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 72 - -44, 0, 0, 0, 0, -44, -44, -44, 0, -44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -13, 0, -13, -13, -13, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 73 - -27, -27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -27, + 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 74 - -30, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -30, + -46, 0, 0, 0, 0, -46, 0, -46, -46, 0, -46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 75 - -31, -31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -31, + -29, -29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -29, // State 76 - -22, -22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -22, + -32, -32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -32, // State 77 - 0, 0, 0, -5, 0, -5, -5, -5, -5, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -33, -33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33, // State 78 - 0, -9, 0, 0, -9, -9, 0, 0, 0, 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, 0, 0, 0, 0, -24, // State 79 - 0, 0, -20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, -5, 0, -5, -5, -5, -5, -5, -5, -5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 80 + 0, -9, 0, 0, -9, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 81 + 0, 0, -22, 0, 0, 0, 0, 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) * 20 + integer] + __ACTION[(state as usize) * 22 + integer] } const __EOF_ACTION: &[i8] = &[ // State 0 @@ -262,13 +270,13 @@ mod __parse__AIR { // State 24 0, // State 25 - -46, + -48, // State 26 -6, // State 27 0, // State 28 - -32, + -34, // State 29 0, // State 30 @@ -300,13 +308,13 @@ mod __parse__AIR { // State 43 0, // State 44 - -26, + -28, // State 45 0, // State 46 0, // State 47 - -28, + -30, // State 48 0, // State 49 @@ -324,15 +332,15 @@ mod __parse__AIR { // State 55 0, // State 56 - -25, + -27, // State 57 - -24, + -26, // State 58 - -29, + -31, // State 59 0, // State 60 - -23, + -25, // State 61 0, // State 62 @@ -358,26 +366,30 @@ mod __parse__AIR { // State 72 0, // State 73 - -27, + 0, // State 74 - -30, + 0, // State 75 - -31, + -29, // State 76 - -22, + -32, // State 77 - 0, + -33, // State 78 - 0, + -24, // State 79 0, + // State 80 + 0, + // State 81 + 0, ]; fn __goto(state: i8, nt: usize) -> i8 { match nt { 2 => 24, 3 => 25, 4 => match state { - 24 => 77, + 24 => 79, _ => 63, }, 5 => 21, @@ -389,7 +401,7 @@ mod __parse__AIR { }, 8 => 15, 9 => match state { - 23 => 71, + 23 => 73, _ => 46, }, 10 => match state { @@ -432,10 +444,12 @@ mod __parse__AIR { r###""]""###, r###"Accumulator"###, r###"Alphanumeric"###, + r###"Boolean"###, r###"InitPeerId"###, r###"JsonPath"###, r###"LastError"###, r###"Literal"###, + r###"Number"###, r###"call"###, r###"fold"###, r###"match_"###, @@ -498,7 +512,7 @@ mod __parse__AIR { #[inline] fn error_action(&self, state: i8) -> i8 { - __action(state, 20 - 1) + __action(state, 22 - 1) } #[inline] @@ -529,7 +543,7 @@ mod __parse__AIR { &self, recovery: __state_machine::ErrorRecovery, ) -> Self::Symbol { - __Symbol::Variant3(recovery) + __Symbol::Variant5(recovery) } fn reduce( @@ -569,19 +583,21 @@ mod __parse__AIR { Token::CloseSquareBracket if true => Some(3), Token::Accumulator(_) if true => Some(4), Token::Alphanumeric(_) if true => Some(5), - Token::InitPeerId if true => Some(6), - Token::JsonPath(_, _) if true => Some(7), - Token::LastError if true => Some(8), - Token::StringLiteral(_) if true => Some(9), - Token::Call if true => Some(10), - Token::Fold if true => Some(11), - Token::Match if true => Some(12), - Token::MisMatch if true => Some(13), - Token::Next if true => Some(14), - Token::Null if true => Some(15), - Token::Par if true => Some(16), - Token::Seq if true => Some(17), - Token::Xor if true => Some(18), + Token::Boolean(_) if true => Some(6), + Token::InitPeerId if true => Some(7), + Token::JsonPath(_, _) if true => Some(8), + Token::LastError if true => Some(9), + Token::StringLiteral(_) if true => Some(10), + Token::Number(_) if true => Some(11), + Token::Call if true => Some(12), + Token::Fold if true => Some(13), + Token::Match if true => Some(14), + Token::MisMatch if true => Some(15), + Token::Next if true => Some(16), + Token::Null if true => Some(17), + Token::Par if true => Some(18), + Token::Seq if true => Some(19), + Token::Xor if true => Some(20), _ => None, } } @@ -595,13 +611,21 @@ mod __parse__AIR { ) -> __Symbol<'input> { match __token_index { - 0 | 1 | 2 | 3 | 6 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 => __Symbol::Variant0(__token), - 4 | 5 | 9 => match __token { + 0 | 1 | 2 | 3 | 7 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 => __Symbol::Variant0(__token), + 4 | 5 | 10 => match __token { Token::Accumulator(__tok0) | Token::Alphanumeric(__tok0) | Token::StringLiteral(__tok0) if true => __Symbol::Variant1(__tok0), _ => unreachable!(), }, - 7 => match __token { - Token::JsonPath(__tok0, __tok1) if true => __Symbol::Variant2((__tok0, __tok1)), + 6 => match __token { + Token::Boolean(__tok0) if true => __Symbol::Variant2(__tok0), + _ => unreachable!(), + }, + 8 => match __token { + Token::JsonPath(__tok0, __tok1) if true => __Symbol::Variant3((__tok0, __tok1)), + _ => unreachable!(), + }, + 11 => match __token { + Token::Number(__tok0) if true => __Symbol::Variant4(__tok0), _ => unreachable!(), }, _ => unreachable!(), @@ -705,13 +729,13 @@ mod __parse__AIR { 14 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 7, + nonterminal_produced: 6, } } 15 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 7, + nonterminal_produced: 6, } } 16 => { @@ -729,109 +753,109 @@ mod __parse__AIR { 18 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 8, + nonterminal_produced: 7, } } 19 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 4, - nonterminal_produced: 8, + states_to_pop: 1, + nonterminal_produced: 7, } } 20 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 9, + nonterminal_produced: 8, } } 21 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 4, + nonterminal_produced: 8, + } + } + 22 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 1, + nonterminal_produced: 9, + } + } + 23 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 7, nonterminal_produced: 10, } } - 22 => { - __state_machine::SimulatedReduce::Reduce { - states_to_pop: 6, - nonterminal_produced: 10, - } - } - 23 => { - __state_machine::SimulatedReduce::Reduce { - states_to_pop: 5, - nonterminal_produced: 10, - } - } 24 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 5, + states_to_pop: 6, nonterminal_produced: 10, } } 25 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 3, + states_to_pop: 5, nonterminal_produced: 10, } } 26 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 6, + states_to_pop: 5, nonterminal_produced: 10, } } 27 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 4, + states_to_pop: 3, nonterminal_produced: 10, } } 28 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 5, + states_to_pop: 6, nonterminal_produced: 10, } } 29 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 6, + states_to_pop: 4, nonterminal_produced: 10, } } 30 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 6, + states_to_pop: 5, nonterminal_produced: 10, } } 31 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 1, + states_to_pop: 6, nonterminal_produced: 10, } } 32 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 1, - nonterminal_produced: 11, + states_to_pop: 6, + nonterminal_produced: 10, } } 33 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 11, + nonterminal_produced: 10, } } 34 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 12, + nonterminal_produced: 11, } } 35 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 12, + nonterminal_produced: 11, } } 36 => { @@ -843,52 +867,64 @@ mod __parse__AIR { 37 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 13, + nonterminal_produced: 12, } } 38 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 13, + nonterminal_produced: 12, } } 39 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 14, + nonterminal_produced: 13, } } 40 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 0, - nonterminal_produced: 14, + states_to_pop: 1, + nonterminal_produced: 13, } } 41 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, - nonterminal_produced: 15, + nonterminal_produced: 14, } } 42 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 1, - nonterminal_produced: 16, + states_to_pop: 0, + nonterminal_produced: 14, } } 43 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 4, - nonterminal_produced: 16, + states_to_pop: 1, + nonterminal_produced: 15, } } 44 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 1, + nonterminal_produced: 16, + } + } + 45 => { + __state_machine::SimulatedReduce::Reduce { + states_to_pop: 4, + nonterminal_produced: 16, + } + } + 46 => { __state_machine::SimulatedReduce::Reduce { states_to_pop: 1, nonterminal_produced: 17, } } - 45 => __state_machine::SimulatedReduce::Accept, + 47 => __state_machine::SimulatedReduce::Accept, _ => panic!("invalid reduction index {}", __reduce_index) } } @@ -1115,8 +1151,14 @@ mod __parse__AIR { __reduce44(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) } 45 => { + __reduce45(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 46 => { + __reduce46(input, errors, __lookahead_start, __symbols, ::std::marker::PhantomData::<(&(), &())>) + } + 47 => { // __AIR = AIR => ActionFn(0); - let __sym0 = __pop_Variant6(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action0::<>(input, errors, __sym0); @@ -1135,36 +1177,14 @@ mod __parse__AIR { fn __symbol_type_mismatch() -> ! { panic!("symbol type mismatch") } - fn __pop_Variant2< + fn __pop_Variant3< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, (&'input str, usize), usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant2(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant6< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, Box>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant6(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant4< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, CallInstrArgValue<'input>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant4(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant3(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1172,32 +1192,21 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, CallInstrValue<'input>, usize) + ) -> (usize, Box>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant8(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant12< + fn __pop_Variant6< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, CallOutputValue<'input>, usize) + ) -> (usize, CallInstrArgValue<'input>, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant9< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, FunctionPart<'input>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant6(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1205,35 +1214,79 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, IterableValue<'input>, usize) + ) -> (usize, CallInstrValue<'input>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant10(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } - fn __pop_Variant11< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, MatchableValue<'input>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } fn __pop_Variant14< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, PeerPart<'input>, usize) + ) -> (usize, CallOutputValue<'input>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant14(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } + fn __pop_Variant11< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, FunctionPart<'input>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant11(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant12< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, IterableValue<'input>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant12(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant13< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, MatchableValue<'input>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant13(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant4< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, Number, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant4(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant16< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, PeerPart<'input>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant16(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } fn __pop_Variant0< 'input, >( @@ -1245,36 +1298,14 @@ mod __parse__AIR { _ => __symbol_type_mismatch() } } - fn __pop_Variant7< + fn __pop_Variant9< 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> ) -> (usize, Vec>, usize) { match __symbols.pop() { - Some((__l, __Symbol::Variant7(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant3< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, __lalrpop_util::ErrorRecovery, LexerError>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant3(__v), __r)) => (__l, __v, __r), - _ => __symbol_type_mismatch() - } - } - fn __pop_Variant13< - 'input, - >( - __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, ::std::option::Option>, usize) - { - match __symbols.pop() { - Some((__l, __Symbol::Variant13(__v), __r)) => (__l, __v, __r), + Some((__l, __Symbol::Variant9(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } @@ -1282,13 +1313,46 @@ mod __parse__AIR { 'input, >( __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> - ) -> (usize, ::std::vec::Vec>, usize) + ) -> (usize, __lalrpop_util::ErrorRecovery, LexerError>, usize) { match __symbols.pop() { Some((__l, __Symbol::Variant5(__v), __r)) => (__l, __v, __r), _ => __symbol_type_mismatch() } } + fn __pop_Variant2< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, bool, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant2(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant15< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, ::std::option::Option>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant15(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } + fn __pop_Variant7< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, ::std::vec::Vec>, usize) + { + match __symbols.pop() { + Some((__l, __Symbol::Variant7(__v), __r)) => (__l, __v, __r), + _ => __symbol_type_mismatch() + } + } fn __pop_Variant1< 'input, >( @@ -1311,12 +1375,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // () = Arg => ActionFn(39); - let __sym0 = __pop_Variant4(__symbols); + // () = Arg => ActionFn(41); + let __sym0 = __pop_Variant6(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action39::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + let __nt = super::__action41::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 0) } pub(crate) fn __reduce1< @@ -1330,11 +1394,11 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()* = => ActionFn(37); + // ()* = => ActionFn(39); let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); let __end = __start.clone(); - let __nt = super::__action37::<>(input, errors, &__start, &__end); - __symbols.push((__start, __Symbol::Variant5(__nt), __end)); + let __nt = super::__action39::<>(input, errors, &__start, &__end); + __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (0, 1) } pub(crate) fn __reduce2< @@ -1348,12 +1412,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()* = ()+ => ActionFn(38); - let __sym0 = __pop_Variant5(__symbols); + // ()* = ()+ => ActionFn(40); + let __sym0 = __pop_Variant7(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action38::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant5(__nt), __end)); + let __nt = super::__action40::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (1, 1) } pub(crate) fn __reduce3< @@ -1367,12 +1431,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()+ = Arg => ActionFn(44); - let __sym0 = __pop_Variant4(__symbols); + // ()+ = Arg => ActionFn(46); + let __sym0 = __pop_Variant6(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action44::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant5(__nt), __end)); + let __nt = super::__action46::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (1, 2) } pub(crate) fn __reduce4< @@ -1386,14 +1450,14 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // ()+ = ()+, Arg => ActionFn(45); + // ()+ = ()+, Arg => ActionFn(47); assert!(__symbols.len() >= 2); - let __sym1 = __pop_Variant4(__symbols); - let __sym0 = __pop_Variant5(__symbols); + let __sym1 = __pop_Variant6(__symbols); + let __sym0 = __pop_Variant7(__symbols); let __start = __sym0.0.clone(); let __end = __sym1.2.clone(); - let __nt = super::__action45::<>(input, errors, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant5(__nt), __end)); + let __nt = super::__action47::<>(input, errors, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant7(__nt), __end)); (2, 2) } pub(crate) fn __reduce5< @@ -1408,11 +1472,11 @@ mod __parse__AIR { ) -> (usize, usize) { // AIR = Instr => ActionFn(1); - let __sym0 = __pop_Variant6(__symbols); + let __sym0 = __pop_Variant8(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action1::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (1, 3) } pub(crate) fn __reduce6< @@ -1427,11 +1491,11 @@ mod __parse__AIR { ) -> (usize, usize) { // Arg = CallInstrArgValue => ActionFn(26); - let __sym0 = __pop_Variant4(__symbols); + let __sym0 = __pop_Variant6(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action26::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 4) } pub(crate) fn __reduce7< @@ -1445,14 +1509,14 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Args = "[", "]" => ActionFn(46); + // Args = "[", "]" => ActionFn(48); 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::__action46::<>(input, errors, __sym0, __sym1); - __symbols.push((__start, __Symbol::Variant7(__nt), __end)); + let __nt = super::__action48::<>(input, errors, __sym0, __sym1); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (2, 5) } pub(crate) fn __reduce8< @@ -1466,15 +1530,15 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Args = "[", ()+, "]" => ActionFn(47); + // Args = "[", ()+, "]" => ActionFn(49); assert!(__symbols.len() >= 3); let __sym2 = __pop_Variant0(__symbols); - let __sym1 = __pop_Variant5(__symbols); + let __sym1 = __pop_Variant7(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); - let __nt = super::__action47::<>(input, errors, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant7(__nt), __end)); + let __nt = super::__action49::<>(input, errors, __sym0, __sym1, __sym2); + __symbols.push((__start, __Symbol::Variant9(__nt), __end)); (3, 5) } pub(crate) fn __reduce9< @@ -1493,7 +1557,7 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action27::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 6) } pub(crate) fn __reduce10< @@ -1512,7 +1576,7 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action28::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 6) } pub(crate) fn __reduce11< @@ -1527,11 +1591,11 @@ mod __parse__AIR { ) -> (usize, usize) { // CallInstrArgValue = JsonPath => ActionFn(29); - let __sym0 = __pop_Variant2(__symbols); + let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action29::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 6) } pub(crate) fn __reduce12< @@ -1545,12 +1609,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstrArgValue = InitPeerId => ActionFn(30); - let __sym0 = __pop_Variant0(__symbols); + // CallInstrArgValue = Number => ActionFn(30); + let __sym0 = __pop_Variant4(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action30::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 6) } pub(crate) fn __reduce13< @@ -1564,12 +1628,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // CallInstrArgValue = LastError => ActionFn(31); - let __sym0 = __pop_Variant0(__symbols); + // CallInstrArgValue = Boolean => ActionFn(31); + let __sym0 = __pop_Variant2(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action31::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant4(__nt), __end)); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); (1, 6) } pub(crate) fn __reduce14< @@ -1582,16 +1646,54 @@ mod __parse__AIR { __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) + { + // CallInstrArgValue = InitPeerId => ActionFn(32); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action32::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + (1, 6) + } + pub(crate) fn __reduce15< + '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) + { + // CallInstrArgValue = LastError => ActionFn(33); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action33::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + (1, 6) + } + pub(crate) fn __reduce16< + '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) { // CallInstrValue = Literal => ActionFn(22); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action22::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 7) } - pub(crate) fn __reduce15< + pub(crate) fn __reduce17< 'err, 'input, >( @@ -1607,10 +1709,10 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action23::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 7) } - pub(crate) fn __reduce16< + pub(crate) fn __reduce18< 'err, 'input, >( @@ -1622,14 +1724,14 @@ mod __parse__AIR { ) -> (usize, usize) { // CallInstrValue = JsonPath => ActionFn(24); - let __sym0 = __pop_Variant2(__symbols); + let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action24::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 7) } - pub(crate) fn __reduce17< + pub(crate) fn __reduce19< 'err, 'input, >( @@ -1645,10 +1747,10 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action25::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 7) } - pub(crate) fn __reduce18< + pub(crate) fn __reduce20< 'err, 'input, >( @@ -1660,14 +1762,14 @@ mod __parse__AIR { ) -> (usize, usize) { // FPart = Function => ActionFn(13); - let __sym0 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action13::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + __symbols.push((__start, __Symbol::Variant11(__nt), __end)); (1, 8) } - pub(crate) fn __reduce19< + pub(crate) fn __reduce21< 'err, 'input, >( @@ -1681,60 +1783,15 @@ mod __parse__AIR { // FPart = "(", ServiceId, Function, ")" => ActionFn(14); assert!(__symbols.len() >= 4); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); - let __sym1 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant10(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym3.2.clone(); let __nt = super::__action14::<>(input, errors, __sym0, __sym1, __sym2, __sym3); - __symbols.push((__start, __Symbol::Variant9(__nt), __end)); + __symbols.push((__start, __Symbol::Variant11(__nt), __end)); (4, 8) } - pub(crate) fn __reduce20< - '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) - { - // Function = CallInstrValue => ActionFn(19); - let __sym0 = __pop_Variant8(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action19::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 9) - } - pub(crate) fn __reduce21< - '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) - { - // Instr = "(", call, PeerPart, FPart, Args, Output, ")" => ActionFn(48); - assert!(__symbols.len() >= 7); - let __sym6 = __pop_Variant0(__symbols); - let __sym5 = __pop_Variant12(__symbols); - let __sym4 = __pop_Variant7(__symbols); - let __sym3 = __pop_Variant9(__symbols); - let __sym2 = __pop_Variant14(__symbols); - let __sym1 = __pop_Variant0(__symbols); - let __sym0 = __pop_Variant0(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym6.2.clone(); - let __nt = super::__action48::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); - (7, 10) - } pub(crate) fn __reduce22< 'err, 'input, @@ -1746,21 +1803,66 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Instr = "(", call, PeerPart, FPart, Args, ")" => ActionFn(49); + // Function = CallInstrValue => ActionFn(19); + let __sym0 = __pop_Variant10(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action19::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 9) + } + pub(crate) fn __reduce23< + '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) + { + // Instr = "(", call, PeerPart, FPart, Args, Output, ")" => ActionFn(50); + assert!(__symbols.len() >= 7); + let __sym6 = __pop_Variant0(__symbols); + let __sym5 = __pop_Variant14(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant11(__symbols); + let __sym2 = __pop_Variant16(__symbols); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant0(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym6.2.clone(); + let __nt = super::__action50::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5, __sym6); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + (7, 10) + } + pub(crate) fn __reduce24< + '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) + { + // Instr = "(", call, PeerPart, FPart, Args, ")" => ActionFn(51); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant7(__symbols); - let __sym3 = __pop_Variant9(__symbols); - let __sym2 = __pop_Variant14(__symbols); + let __sym4 = __pop_Variant9(__symbols); + let __sym3 = __pop_Variant11(__symbols); + let __sym2 = __pop_Variant16(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); - let __nt = super::__action49::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + let __nt = super::__action51::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (6, 10) } - pub(crate) fn __reduce23< + pub(crate) fn __reduce25< 'err, 'input, >( @@ -1774,17 +1876,17 @@ mod __parse__AIR { // Instr = "(", seq, Instr, Instr, ")" => ActionFn(3); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); - let __sym3 = __pop_Variant6(__symbols); - let __sym2 = __pop_Variant6(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action3::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (5, 10) } - pub(crate) fn __reduce24< + pub(crate) fn __reduce26< 'err, 'input, >( @@ -1798,17 +1900,17 @@ mod __parse__AIR { // Instr = "(", par, Instr, Instr, ")" => ActionFn(4); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); - let __sym3 = __pop_Variant6(__symbols); - let __sym2 = __pop_Variant6(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action4::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (5, 10) } - pub(crate) fn __reduce25< + pub(crate) fn __reduce27< 'err, 'input, >( @@ -1827,10 +1929,10 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym2.2.clone(); let __nt = super::__action5::<>(input, errors, __sym0, __sym1, __sym2); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (3, 10) } - pub(crate) fn __reduce26< + pub(crate) fn __reduce28< 'err, 'input, >( @@ -1844,18 +1946,18 @@ mod __parse__AIR { // Instr = "(", fold, Iterable, Alphanumeric, Instr, ")" => ActionFn(6); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant6(__symbols); + let __sym4 = __pop_Variant8(__symbols); let __sym3 = __pop_Variant1(__symbols); - let __sym2 = __pop_Variant10(__symbols); + let __sym2 = __pop_Variant12(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym5.2.clone(); let __nt = super::__action6::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (6, 10) } - pub(crate) fn __reduce27< + pub(crate) fn __reduce29< 'err, 'input, >( @@ -1875,10 +1977,10 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym3.2.clone(); let __nt = super::__action7::<>(input, errors, __sym0, __sym1, __sym2, __sym3); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (4, 10) } - pub(crate) fn __reduce28< + pub(crate) fn __reduce30< 'err, 'input, >( @@ -1892,17 +1994,17 @@ mod __parse__AIR { // Instr = "(", xor, Instr, Instr, ")" => ActionFn(8); assert!(__symbols.len() >= 5); let __sym4 = __pop_Variant0(__symbols); - let __sym3 = __pop_Variant6(__symbols); - let __sym2 = __pop_Variant6(__symbols); + let __sym3 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant8(__symbols); let __sym1 = __pop_Variant0(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym4.2.clone(); let __nt = super::__action8::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (5, 10) } - pub(crate) fn __reduce29< + pub(crate) fn __reduce31< 'err, 'input, >( @@ -1916,18 +2018,18 @@ mod __parse__AIR { // Instr = "(", match_, Matchable, Matchable, Instr, ")" => ActionFn(9); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant6(__symbols); - let __sym3 = __pop_Variant11(__symbols); - let __sym2 = __pop_Variant11(__symbols); + let __sym4 = __pop_Variant8(__symbols); + let __sym3 = __pop_Variant13(__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::__action9::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (6, 10) } - pub(crate) fn __reduce30< + pub(crate) fn __reduce32< 'err, 'input, >( @@ -1941,55 +2043,17 @@ mod __parse__AIR { // Instr = "(", mismatch, Matchable, Matchable, Instr, ")" => ActionFn(10); assert!(__symbols.len() >= 6); let __sym5 = __pop_Variant0(__symbols); - let __sym4 = __pop_Variant6(__symbols); - let __sym3 = __pop_Variant11(__symbols); - let __sym2 = __pop_Variant11(__symbols); + let __sym4 = __pop_Variant8(__symbols); + let __sym3 = __pop_Variant13(__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::__action10::<>(input, errors, __sym0, __sym1, __sym2, __sym3, __sym4, __sym5); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); (6, 10) } - pub(crate) fn __reduce31< - '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) - { - // Instr = error => ActionFn(11); - let __sym0 = __pop_Variant3(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action11::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant6(__nt), __end)); - (1, 10) - } - pub(crate) fn __reduce32< - '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) - { - // Iterable = Alphanumeric => ActionFn(32); - let __sym0 = __pop_Variant1(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action32::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) - } pub(crate) fn __reduce33< 'err, 'input, @@ -2001,13 +2065,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Iterable = JsonPath => ActionFn(33); - let __sym0 = __pop_Variant2(__symbols); + // Instr = error => ActionFn(11); + let __sym0 = __pop_Variant5(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action33::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 11) + let __nt = super::__action11::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + (1, 10) } pub(crate) fn __reduce34< 'err, @@ -2020,13 +2084,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Matchable = Alphanumeric => ActionFn(34); + // Iterable = Alphanumeric => ActionFn(34); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action34::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) + __symbols.push((__start, __Symbol::Variant12(__nt), __end)); + (1, 11) } pub(crate) fn __reduce35< 'err, @@ -2039,13 +2103,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Matchable = Literal => ActionFn(35); - let __sym0 = __pop_Variant1(__symbols); + // Iterable = JsonPath => ActionFn(35); + let __sym0 = __pop_Variant3(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action35::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); - (1, 12) + __symbols.push((__start, __Symbol::Variant12(__nt), __end)); + (1, 11) } pub(crate) fn __reduce36< 'err, @@ -2058,12 +2122,12 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // Matchable = JsonPath => ActionFn(36); - let __sym0 = __pop_Variant2(__symbols); + // Matchable = Alphanumeric => ActionFn(36); + let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action36::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant11(__nt), __end)); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); (1, 12) } pub(crate) fn __reduce37< @@ -2076,16 +2140,54 @@ mod __parse__AIR { __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) + { + // Matchable = Literal => ActionFn(37); + let __sym0 = __pop_Variant1(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action37::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); + (1, 12) + } + 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) + { + // Matchable = JsonPath => ActionFn(38); + let __sym0 = __pop_Variant3(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action38::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); + (1, 12) + } + pub(crate) fn __reduce39< + '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) { // Output = Alphanumeric => ActionFn(17); let __sym0 = __pop_Variant1(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action17::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); + __symbols.push((__start, __Symbol::Variant14(__nt), __end)); (1, 13) } - pub(crate) fn __reduce38< + pub(crate) fn __reduce40< 'err, 'input, >( @@ -2101,46 +2203,9 @@ mod __parse__AIR { let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action18::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant12(__nt), __end)); + __symbols.push((__start, __Symbol::Variant14(__nt), __end)); (1, 13) } - pub(crate) fn __reduce39< - '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) - { - // Output? = Output => ActionFn(40); - let __sym0 = __pop_Variant12(__symbols); - let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action40::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant13(__nt), __end)); - (1, 14) - } - pub(crate) fn __reduce40< - '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) - { - // Output? = => ActionFn(41); - let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); - let __end = __start.clone(); - let __nt = super::__action41::<>(input, errors, &__start, &__end); - __symbols.push((__start, __Symbol::Variant13(__nt), __end)); - (0, 14) - } pub(crate) fn __reduce41< 'err, 'input, @@ -2152,13 +2217,13 @@ mod __parse__AIR { _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) { - // PeerId = CallInstrValue => ActionFn(20); - let __sym0 = __pop_Variant8(__symbols); + // Output? = Output => ActionFn(42); + let __sym0 = __pop_Variant14(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); - let __nt = super::__action20::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); - (1, 15) + let __nt = super::__action42::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant15(__nt), __end)); + (1, 14) } pub(crate) fn __reduce42< 'err, @@ -2170,16 +2235,53 @@ mod __parse__AIR { __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)>, _: ::std::marker::PhantomData<(&'err (), &'input ())>, ) -> (usize, usize) + { + // Output? = => ActionFn(43); + let __start = __lookahead_start.cloned().or_else(|| __symbols.last().map(|s| s.2.clone())).unwrap_or_default(); + let __end = __start.clone(); + let __nt = super::__action43::<>(input, errors, &__start, &__end); + __symbols.push((__start, __Symbol::Variant15(__nt), __end)); + (0, 14) + } + pub(crate) fn __reduce43< + '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 = CallInstrValue => ActionFn(20); + let __sym0 = __pop_Variant10(__symbols); + let __start = __sym0.0.clone(); + let __end = __sym0.2.clone(); + let __nt = super::__action20::<>(input, errors, __sym0); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); + (1, 15) + } + pub(crate) fn __reduce44< + '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(15); - let __sym0 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action15::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant14(__nt), __end)); + __symbols.push((__start, __Symbol::Variant16(__nt), __end)); (1, 16) } - pub(crate) fn __reduce43< + pub(crate) fn __reduce45< 'err, 'input, >( @@ -2193,16 +2295,16 @@ mod __parse__AIR { // PeerPart = "(", PeerId, ServiceId, ")" => ActionFn(16); assert!(__symbols.len() >= 4); let __sym3 = __pop_Variant0(__symbols); - let __sym2 = __pop_Variant8(__symbols); - let __sym1 = __pop_Variant8(__symbols); + let __sym2 = __pop_Variant10(__symbols); + let __sym1 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant0(__symbols); let __start = __sym0.0.clone(); let __end = __sym3.2.clone(); let __nt = super::__action16::<>(input, errors, __sym0, __sym1, __sym2, __sym3); - __symbols.push((__start, __Symbol::Variant14(__nt), __end)); + __symbols.push((__start, __Symbol::Variant16(__nt), __end)); (4, 16) } - pub(crate) fn __reduce44< + pub(crate) fn __reduce46< 'err, 'input, >( @@ -2214,11 +2316,11 @@ mod __parse__AIR { ) -> (usize, usize) { // ServiceId = CallInstrValue => ActionFn(21); - let __sym0 = __pop_Variant8(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action21::<>(input, errors, __sym0); - __symbols.push((__start, __Symbol::Variant8(__nt), __end)); + __symbols.push((__start, __Symbol::Variant10(__nt), __end)); (1, 17) } } @@ -2683,6 +2785,32 @@ fn __action29< fn __action30< 'err, 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, n, _): (usize, Number, usize), +) -> CallInstrArgValue<'input> +{ + CallInstrArgValue::Number(n) +} + +#[allow(unused_variables)] +fn __action31< + 'err, + 'input, +>( + input: &'input str, + errors: &'err mut Vec, LexerError>>, + (_, b, _): (usize, bool, usize), +) -> CallInstrArgValue<'input> +{ + CallInstrArgValue::Boolean(b) +} + +#[allow(unused_variables)] +fn __action32< + 'err, + 'input, >( input: &'input str, errors: &'err mut Vec, LexerError>>, @@ -2693,7 +2821,7 @@ fn __action30< } #[allow(unused_variables)] -fn __action31< +fn __action33< 'err, 'input, >( @@ -2706,7 +2834,7 @@ fn __action31< } #[allow(unused_variables)] -fn __action32< +fn __action34< 'err, 'input, >( @@ -2719,7 +2847,7 @@ fn __action32< } #[allow(unused_variables)] -fn __action33< +fn __action35< 'err, 'input, >( @@ -2735,7 +2863,7 @@ fn __action33< } #[allow(unused_variables)] -fn __action34< +fn __action36< 'err, 'input, >( @@ -2748,7 +2876,7 @@ fn __action34< } #[allow(unused_variables)] -fn __action35< +fn __action37< 'err, 'input, >( @@ -2761,7 +2889,7 @@ fn __action35< } #[allow(unused_variables)] -fn __action36< +fn __action38< 'err, 'input, >( @@ -2777,7 +2905,7 @@ fn __action36< } #[allow(unused_variables)] -fn __action37< +fn __action39< 'err, 'input, >( @@ -2791,7 +2919,7 @@ fn __action37< } #[allow(unused_variables)] -fn __action38< +fn __action40< 'err, 'input, >( @@ -2804,7 +2932,7 @@ fn __action38< } #[allow(unused_variables)] -fn __action39< +fn __action41< 'err, 'input, >( @@ -2817,7 +2945,7 @@ fn __action39< } #[allow(unused_variables)] -fn __action40< +fn __action42< 'err, 'input, >( @@ -2830,7 +2958,7 @@ fn __action40< } #[allow(unused_variables)] -fn __action41< +fn __action43< 'err, 'input, >( @@ -2844,7 +2972,7 @@ fn __action41< } #[allow(unused_variables)] -fn __action42< +fn __action44< 'err, 'input, >( @@ -2857,7 +2985,7 @@ fn __action42< } #[allow(unused_variables)] -fn __action43< +fn __action45< 'err, 'input, >( @@ -2871,7 +2999,7 @@ fn __action43< } #[allow(unused_variables)] -fn __action44< +fn __action46< 'err, 'input, >( @@ -2882,13 +3010,13 @@ fn __action44< { let __start0 = __0.0.clone(); let __end0 = __0.2.clone(); - let __temp0 = __action39( + let __temp0 = __action41( input, errors, __0, ); let __temp0 = (__start0, __temp0, __end0); - __action42( + __action44( input, errors, __temp0, @@ -2896,7 +3024,7 @@ fn __action44< } #[allow(unused_variables)] -fn __action45< +fn __action47< 'err, 'input, >( @@ -2908,13 +3036,13 @@ fn __action45< { let __start0 = __1.0.clone(); let __end0 = __1.2.clone(); - let __temp0 = __action39( + let __temp0 = __action41( input, errors, __1, ); let __temp0 = (__start0, __temp0, __end0); - __action43( + __action45( input, errors, __0, @@ -2923,7 +3051,7 @@ fn __action45< } #[allow(unused_variables)] -fn __action46< +fn __action48< 'err, 'input, >( @@ -2935,7 +3063,7 @@ fn __action46< { let __start0 = __0.2.clone(); let __end0 = __1.0.clone(); - let __temp0 = __action37( + let __temp0 = __action39( input, errors, &__start0, @@ -2952,7 +3080,7 @@ fn __action46< } #[allow(unused_variables)] -fn __action47< +fn __action49< 'err, 'input, >( @@ -2965,7 +3093,7 @@ fn __action47< { let __start0 = __1.0.clone(); let __end0 = __1.2.clone(); - let __temp0 = __action38( + let __temp0 = __action40( input, errors, __1, @@ -2981,7 +3109,7 @@ fn __action47< } #[allow(unused_variables)] -fn __action48< +fn __action50< 'err, 'input, >( @@ -2998,7 +3126,7 @@ fn __action48< { let __start0 = __5.0.clone(); let __end0 = __5.2.clone(); - let __temp0 = __action40( + let __temp0 = __action42( input, errors, __5, @@ -3018,7 +3146,7 @@ fn __action48< } #[allow(unused_variables)] -fn __action49< +fn __action51< 'err, 'input, >( @@ -3034,7 +3162,7 @@ fn __action49< { let __start0 = __4.2.clone(); let __end0 = __5.0.clone(); - let __temp0 = __action41( + let __temp0 = __action43( input, errors, &__start0, diff --git a/crates/air-parser/src/parser/air_parser.rs b/crates/air-parser/src/parser/air_parser.rs index 3b8fa181..b3911b70 100644 --- a/crates/air-parser/src/parser/air_parser.rs +++ b/crates/air-parser/src/parser/air_parser.rs @@ -126,8 +126,26 @@ fn lexical_error_to_label(file_id: usize, error: LexerError) -> Label { EmptyAccName(start, end) => { Label::primary(file_id, start..end).with_message(error.to_string()) } + EmptyVariableOrConst(start, end) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } InvalidJsonPath(start, end) => { Label::primary(file_id, start..end).with_message(error.to_string()) } + UnallowedCharInNumber(start, end) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } + ParseIntError(start, end, _) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } + ParseFloatError(start, end, _) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } + TooBigFloat(start, end) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } + LeadingDot(start, end) => { + Label::primary(file_id, start..end).with_message(error.to_string()) + } } } diff --git a/crates/air-parser/src/parser/ast.rs b/crates/air-parser/src/parser/ast.rs index 373a17fb..573188b4 100644 --- a/crates/air-parser/src/parser/ast.rs +++ b/crates/air-parser/src/parser/ast.rs @@ -1,18 +1,4 @@ -/* - * 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. - */ +pub use crate::parser::lexer::Number; use serde::Deserialize; use serde::Serialize; @@ -20,7 +6,7 @@ use serde::Serialize; use std::rc::Rc; #[allow(clippy::large_enum_variant)] // for Null and Error variants -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub enum Instruction<'i> { Null(Null), Call(Call<'i>), @@ -34,19 +20,19 @@ pub enum Instruction<'i> { Error, } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub enum PeerPart<'i> { PeerPk(CallInstrValue<'i>), PeerPkWithServiceId(CallInstrValue<'i>, CallInstrValue<'i>), } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub enum FunctionPart<'i> { FuncName(CallInstrValue<'i>), ServiceIdWithFuncName(CallInstrValue<'i>, CallInstrValue<'i>), } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Call<'i> { pub peer_part: PeerPart<'i>, pub function_part: FunctionPart<'i>, @@ -54,7 +40,7 @@ pub struct Call<'i> { pub output: CallOutputValue<'i>, } -#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum CallInstrValue<'i> { InitPeerId, Literal(&'i str), @@ -62,67 +48,71 @@ pub enum CallInstrValue<'i> { JsonPath { variable: &'i str, path: &'i str }, } -#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum CallInstrArgValue<'i> { InitPeerId, LastError, Literal(&'i str), + Number(Number), + Boolean(bool), Variable(&'i str), JsonPath { variable: &'i str, path: &'i str }, } -#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum IterableValue<'i> { Variable(&'i str), JsonPath { variable: &'i str, path: &'i str }, } -#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum MatchableValue<'i> { Literal(&'i str), + Number(Number), + Boolean(bool), Variable(&'i str), JsonPath { variable: &'i str, path: &'i str }, } -#[derive(Serialize, Debug, Hash, PartialEq, Eq, Clone)] +#[derive(Serialize, Debug, PartialEq, Clone)] pub enum CallOutputValue<'i> { Scalar(&'i str), Accumulator(&'i str), None, } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Seq<'i>(pub Box>, pub Box>); -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Par<'i>(pub Box>, pub Box>); -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Xor<'i>(pub Box>, pub Box>); -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Match<'i> { pub left_value: MatchableValue<'i>, pub right_value: MatchableValue<'i>, pub instruction: Box>, } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct MisMatch<'i> { pub left_value: MatchableValue<'i>, pub right_value: MatchableValue<'i>, pub instruction: Box>, } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Fold<'i> { pub iterable: IterableValue<'i>, pub iterator: &'i str, pub instruction: Rc>, } -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Next<'i>(pub &'i str); -#[derive(Serialize, Debug, PartialEq, Eq)] +#[derive(Serialize, Debug, PartialEq)] pub struct Null; diff --git a/crates/air-parser/src/parser/lexer/air_lexer.rs b/crates/air-parser/src/parser/lexer/air_lexer.rs index 3af53f84..f20a070a 100644 --- a/crates/air-parser/src/parser/lexer/air_lexer.rs +++ b/crates/air-parser/src/parser/lexer/air_lexer.rs @@ -15,7 +15,9 @@ */ use super::errors::LexerError; +use super::is_aqua_alphanumeric; use super::token::Token; +use super::LexerResult; use std::iter::Peekable; use std::str::CharIndices; @@ -169,7 +171,7 @@ fn should_stop(ch: char, round_brackets_balance: i64, open_square_brackets_balan ch.is_whitespace() || round_brackets_balance < 0 || open_square_brackets_balance < 0 } -fn string_to_token(input: &str, start_pos: usize) -> Result { +fn string_to_token(input: &str, start_pos: usize) -> LexerResult { match input { "" => Err(LexerError::EmptyString(start_pos, start_pos)), @@ -186,12 +188,15 @@ fn string_to_token(input: &str, start_pos: usize) -> Result { INIT_PEER_ID => Ok(Token::InitPeerId), LAST_ERROR => Ok(Token::LastError), + TRUE_VALUE => Ok(Token::Boolean(true)), + FALSE_VALUE => Ok(Token::Boolean(false)), + str if str.ends_with(ACC_END_TAG) => try_parse_accumulator(str, start_pos), - str => try_parse_call_variable(str, start_pos), + str => super::call_variable_parser::try_parse_call_variable(str, start_pos), } } -fn try_parse_accumulator(maybe_acc: &str, start: usize) -> Result { +fn try_parse_accumulator(maybe_acc: &str, start: usize) -> LexerResult { const ACC_END_TAG_SIZE: usize = 2; let str_len = maybe_acc.len(); @@ -211,25 +216,6 @@ fn try_parse_accumulator(maybe_acc: &str, start: usize) -> Result Result { - let mut json_path_start_pos = None; - - for (pos, ch) in maybe_var.chars().enumerate() { - if !json_path_started(json_path_start_pos) && is_json_path_start_point(ch) { - json_path_start_pos = Some(pos); - } else if !json_path_started(json_path_start_pos) && !is_aqua_alphanumeric(ch) { - return Err(LexerError::IsNotAlphanumeric(start + pos, start + pos)); - } else if json_path_started(json_path_start_pos) & !json_path_allowed_char(ch) { - return Err(LexerError::InvalidJsonPath(start + pos, start + pos)); - } - } - - match json_path_start_pos { - Some(pos) => Ok(Token::JsonPath(maybe_var, pos)), - None => Ok(Token::Alphanumeric(maybe_var)), - } -} - const CALL_INSTR: &str = "call"; const SEQ_INSTR: &str = "seq"; const PAR_INSTR: &str = "par"; @@ -243,40 +229,7 @@ const MISMATCH_INSTR: &str = "mismatch"; const INIT_PEER_ID: &str = "%init_peer_id%"; const LAST_ERROR: &str = "%last_error%"; +const TRUE_VALUE: &str = "true"; +const FALSE_VALUE: &str = "false"; + const ACC_END_TAG: &str = "[]"; - -fn is_json_path_start_point(ch: char) -> bool { - ch == '.' -} - -fn json_path_started(first_dot_pos: Option) -> bool { - first_dot_pos.is_some() -} - -fn json_path_allowed_char(ch: char) -> bool { - // we don't have spec for json path now, but some possible example could be found here - // https://packagist.org/packages/softcreatr/jsonpath - - // good old switch faster here than hash set - match ch { - '$' => true, - '@' => true, - '[' => true, - ']' => true, - '(' => true, - ')' => true, - ':' => true, - '?' => true, - '.' => true, - '*' => true, - ',' => true, - '"' => true, - '\'' => true, - '!' => true, - ch => is_aqua_alphanumeric(ch), - } -} - -fn is_aqua_alphanumeric(ch: char) -> bool { - ch.is_alphanumeric() || ch == '_' || ch == '-' -} diff --git a/crates/air-parser/src/parser/lexer/call_variable_parser.rs b/crates/air-parser/src/parser/lexer/call_variable_parser.rs new file mode 100644 index 00000000..59e5520b --- /dev/null +++ b/crates/air-parser/src/parser/lexer/call_variable_parser.rs @@ -0,0 +1,262 @@ +/* + * 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::LexerError; +use super::LexerResult; +use super::Token; + +use std::convert::TryInto; +use std::iter::Peekable; +use std::str::CharIndices; + +pub(super) fn try_parse_call_variable( + string_to_parse: &str, + start_pos: usize, +) -> LexerResult> { + CallVariableParser::try_parse(string_to_parse, start_pos) +} + +#[derive(Debug)] +struct ParserState { + pub(self) first_dot_met_pos: Option, + pub(self) non_numeric_met: bool, + pub(self) digit_met: bool, + pub(self) is_first_char: bool, + pub(self) current_char: char, + pub(self) current_pos: usize, +} + +struct CallVariableParser<'input> { + string_to_parse_iter: Peekable>, + string_to_parse: &'input str, + start_pos: usize, + state: ParserState, +} + +impl<'input> CallVariableParser<'input> { + fn new(string_to_parse: &'input str, start_pos: usize) -> LexerResult { + let mut string_to_parse_iter = string_to_parse.char_indices().peekable(); + let (current_pos, current_char) = match string_to_parse_iter.next() { + Some(pos_and_ch) => pos_and_ch, + None => return Err(LexerError::EmptyVariableOrConst(start_pos, start_pos)), + }; + + let state = ParserState { + first_dot_met_pos: None, + non_numeric_met: false, + digit_met: false, + is_first_char: true, + current_char, + current_pos, + }; + + let parser = Self { + string_to_parse_iter, + string_to_parse, + start_pos, + state, + }; + + Ok(parser) + } + + pub(self) fn try_parse( + string_to_parse: &'input str, + start_pos: usize, + ) -> LexerResult> { + let mut parser = Self::new(string_to_parse, start_pos)?; + + loop { + if parser.is_possible_to_parse_as_number() { + parser.try_parse_as_number()?; + } else { + parser.try_parse_as_variable()?; + } + + if !parser.next_char() { + break; + } + } + + parser.to_token() + } + + fn next_char(&mut self) -> bool { + let (pos, ch) = match self.string_to_parse_iter.next() { + Some(pos_and_ch) => pos_and_ch, + None => return false, + }; + + self.state.current_char = ch; + self.state.current_pos = pos; + self.state.is_first_char = false; + + true + } + + fn is_possible_to_parse_as_number(&self) -> bool { + !self.state.non_numeric_met + } + + fn try_parse_as_number(&mut self) -> LexerResult<()> { + if self.try_parse_as_sign() || self.try_parse_as_digit() || self.try_parse_as_float_dot()? { + return Ok(()); + } + + self.handle_non_digit() + } + + fn try_parse_as_sign(&self) -> bool { + let ch = self.current_char(); + self.state.is_first_char && (ch == '-' || ch == '+') + } + + fn try_parse_as_digit(&mut self) -> bool { + if self.current_char().is_numeric() { + self.state.digit_met = true; + return true; + } + + false + } + + fn try_parse_as_float_dot(&mut self) -> LexerResult { + let is_first_dot = self.try_parse_first_met_dot()?; + + // filter out +.12 -.2315 variants + if is_first_dot && !self.state.digit_met { + let error_pos = self.pos_in_string_to_parse(); + return Err(LexerError::LeadingDot(error_pos, error_pos)); + } + + Ok(is_first_dot) + } + + fn handle_non_digit(&mut self) -> LexerResult<()> { + self.check_fallback_to_variable()?; + + self.state.non_numeric_met = true; + self.try_parse_as_variable() + } + + fn check_fallback_to_variable(&self) -> LexerResult<()> { + if self.dot_met() { + let error_pos = self.pos_in_string_to_parse(); + return Err(LexerError::UnallowedCharInNumber(error_pos, error_pos)); + } + + Ok(()) + } + + fn try_parse_as_variable(&mut self) -> LexerResult<()> { + if self.try_parse_as_json_path_start()? { + return Ok(()); + } else if self.is_json_path_started() { + self.try_parse_as_json_path()?; + } else { + self.try_parse_as_alphanumeric()?; + } + + Ok(()) + } + + fn try_parse_as_json_path_start(&mut self) -> LexerResult { + self.try_parse_first_met_dot() + } + + fn try_parse_as_alphanumeric(&self) -> LexerResult<()> { + if !self.aqua_alphanumeric() { + let error_pos = self.pos_in_string_to_parse(); + return Err(LexerError::IsNotAlphanumeric(error_pos, error_pos)); + } + + Ok(()) + } + + fn try_parse_as_json_path(&self) -> LexerResult<()> { + if !self.json_path_allowed_char() { + let error_pos = self.pos_in_string_to_parse(); + return Err(LexerError::InvalidJsonPath(error_pos, error_pos)); + } + + Ok(()) + } + + fn try_parse_first_met_dot(&mut self) -> LexerResult { + if !self.dot_met() && self.current_char() == '.' { + if self.current_pos() == 0 { + return Err(LexerError::LeadingDot( + self.start_pos, + self.pos_in_string_to_parse(), + )); + } + self.state.first_dot_met_pos = Some(self.current_pos()); + return Ok(true); + } + + Ok(false) + } + + fn is_json_path_started(&self) -> bool { + self.dot_met() + } + + fn dot_met(&self) -> bool { + self.state.first_dot_met_pos.is_some() + } + + fn aqua_alphanumeric(&self) -> bool { + super::is_aqua_alphanumeric(self.current_char()) + } + + fn json_path_allowed_char(&self) -> bool { + super::is_json_path_allowed_char(self.current_char()) + } + + fn pos_in_string_to_parse(&self) -> usize { + self.start_pos + self.current_pos() + } + + fn current_pos(&self) -> usize { + self.state.current_pos + } + + fn current_char(&self) -> char { + self.state.current_char + } + + fn to_token(&self) -> LexerResult> { + use super::token::UnparsedNumber; + + match (self.is_possible_to_parse_as_number(), self.dot_met()) { + (true, false) => { + let number = UnparsedNumber::Int(self.string_to_parse, self.start_pos); + let number: super::Number = number.try_into()?; + Ok(number.into()) + } + (true, true) => { + let number = UnparsedNumber::Float(self.string_to_parse, self.start_pos); + let number: super::Number = number.try_into()?; + Ok(number.into()) + } + (false, false) => Ok(Token::Alphanumeric(self.string_to_parse)), + (false, true) => Ok(Token::JsonPath( + self.string_to_parse, + self.state.first_dot_met_pos.unwrap(), + )), + } + } +} diff --git a/crates/air-parser/src/parser/lexer/errors.rs b/crates/air-parser/src/parser/lexer/errors.rs index fc317d61..12b8dd16 100644 --- a/crates/air-parser/src/parser/lexer/errors.rs +++ b/crates/air-parser/src/parser/lexer/errors.rs @@ -16,7 +16,10 @@ use thiserror::Error as ThisError; -#[derive(ThisError, Debug, Clone, PartialEq, Eq, Hash)] +use std::num::ParseFloatError; +use std::num::ParseIntError; + +#[derive(ThisError, Debug, Clone, PartialEq, Eq)] pub enum LexerError { #[error("this string literal has unclosed quote")] UnclosedQuote(usize, usize), @@ -24,14 +27,32 @@ pub enum LexerError { #[error("empty string aren't allowed in this position")] EmptyString(usize, usize), - #[error("only alphanumeric and _, - characters are allowed in this position")] + #[error("only alphanumeric, '_', and '-' characters are allowed in this position")] IsNotAlphanumeric(usize, usize), #[error("an accumulator name should be non empty")] EmptyAccName(usize, usize), + #[error("this variable or constant shouldn't have empty name")] + EmptyVariableOrConst(usize, usize), + #[error("invalid character in json path")] InvalidJsonPath(usize, usize), + + #[error("a digit could contain only digits or one dot")] + UnallowedCharInNumber(usize, usize), + + #[error("{2}")] + ParseIntError(usize, usize, #[source] ParseIntError), + + #[error("{2}")] + ParseFloatError(usize, usize, #[source] ParseFloatError), + + #[error("this float is too big, a float could contain less than 12 digits")] + TooBigFloat(usize, usize), + + #[error("leading dot without any symbols before - please write 0 if it's float or variable name if it's json path")] + LeadingDot(usize, usize), } impl From for LexerError { diff --git a/crates/air-parser/src/parser/lexer/mod.rs b/crates/air-parser/src/parser/lexer/mod.rs index 218f3a8f..7b1fcbd4 100644 --- a/crates/air-parser/src/parser/lexer/mod.rs +++ b/crates/air-parser/src/parser/lexer/mod.rs @@ -15,12 +15,20 @@ */ mod air_lexer; +mod call_variable_parser; mod errors; mod token; +mod utils; #[cfg(test)] pub mod tests; pub use air_lexer::AIRLexer; pub use errors::LexerError; +pub use token::Number; pub use token::Token; + +pub(super) type LexerResult = std::result::Result; + +pub(self) use utils::is_aqua_alphanumeric; +pub(self) use utils::is_json_path_allowed_char; diff --git a/crates/air-parser/src/parser/lexer/tests.rs b/crates/air-parser/src/parser/lexer/tests.rs index 45fcc88e..0403a453 100644 --- a/crates/air-parser/src/parser/lexer/tests.rs +++ b/crates/air-parser/src/parser/lexer/tests.rs @@ -17,6 +17,7 @@ use super::air_lexer::Spanned; use super::AIRLexer; use super::LexerError; +use super::Number; use super::Token; fn run_lexer(input: &str) -> Vec, usize, LexerError>> { @@ -24,110 +25,119 @@ fn run_lexer(input: &str) -> Vec, usize, LexerError>> { lexer.collect() } +#[allow(dead_code)] +enum TokenCompareStrategy<'token> { + All(Vec, usize, LexerError>>), + Some(Vec, Vec, usize, LexerError>>), + One(usize, Spanned, usize, LexerError>), + Single(Spanned, usize, LexerError>), +} + +use TokenCompareStrategy::*; + +fn lexer_test(input: &str, expected_tokens: TokenCompareStrategy) { + let actual_tokens = run_lexer(input); + + match expected_tokens { + All(expected_tokens) => assert_eq!(actual_tokens, expected_tokens), + Some(token_ids, expected_tokens) => { + for (&id, token) in token_ids.iter().zip(expected_tokens) { + assert_eq!(actual_tokens[id], token); + } + } + One(id, token) => assert_eq!(actual_tokens[id], token), + Single(token) => assert_eq!(actual_tokens, vec![token]), + } +} + #[test] fn air_instructions() { - let call_tokens = run_lexer("call"); - assert_eq!(call_tokens, vec![Ok((0, Token::Call, 4))]); + lexer_test("call", Single(Ok((0, Token::Call, 4)))); - let call_tokens = run_lexer("(call)"); - assert_eq!( - call_tokens, - vec![ + lexer_test( + "(call)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Call, 5)), - Ok((5, Token::CloseRoundBracket, 6)) - ] + Ok((5, Token::CloseRoundBracket, 6)), + ]), ); - let par_tokens = run_lexer("par"); - assert_eq!(par_tokens, vec![Ok((0, Token::Par, 3))]); + lexer_test("par", Single(Ok((0, Token::Par, 3)))); - let par_tokens = run_lexer("(par)"); - assert_eq!( - par_tokens, - vec![ + lexer_test( + "(par)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Par, 4)), - Ok((4, Token::CloseRoundBracket, 5)) - ] + Ok((4, Token::CloseRoundBracket, 5)), + ]), ); - let seq_tokens = run_lexer("seq"); - assert_eq!(seq_tokens, vec![Ok((0, Token::Seq, 3))]); + lexer_test("seq", Single(Ok((0, Token::Seq, 3)))); - let seq_tokens = run_lexer("(seq)"); - assert_eq!( - seq_tokens, - vec![ + lexer_test( + "(seq)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Seq, 4)), - Ok((4, Token::CloseRoundBracket, 5)) - ] + Ok((4, Token::CloseRoundBracket, 5)), + ]), ); - let null_tokens = run_lexer("null"); - assert_eq!(null_tokens, vec![Ok((0, Token::Null, 4))]); + lexer_test("null", Single(Ok((0, Token::Null, 4)))); - let null_tokens = run_lexer("(null)"); - assert_eq!( - null_tokens, - vec![ + lexer_test( + "(null)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Null, 5)), - Ok((5, Token::CloseRoundBracket, 6)) - ] + Ok((5, Token::CloseRoundBracket, 6)), + ]), ); - let fold_tokens = run_lexer("fold"); - assert_eq!(fold_tokens, vec![Ok((0, Token::Fold, 4))]); + lexer_test("fold", Single(Ok((0, Token::Fold, 4)))); - let fold_tokens = run_lexer("(fold)"); - assert_eq!( - fold_tokens, - vec![ + lexer_test( + "(fold)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Fold, 5)), - Ok((5, Token::CloseRoundBracket, 6)) - ] + Ok((5, Token::CloseRoundBracket, 6)), + ]), ); - let next_tokens = run_lexer("next"); - assert_eq!(next_tokens, vec![Ok((0, Token::Next, 4))]); + lexer_test("next", Single(Ok((0, Token::Next, 4)))); - let next_tokens = run_lexer("(next)"); - assert_eq!( - next_tokens, - vec![ + lexer_test( + "(next)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Next, 5)), - Ok((5, Token::CloseRoundBracket, 6)) - ] + Ok((5, Token::CloseRoundBracket, 6)), + ]), ); - let match_tokens = run_lexer("match"); - assert_eq!(match_tokens, vec![Ok((0, Token::Match, 5))]); + lexer_test("match", Single(Ok((0, Token::Match, 5)))); - let match_tokens = run_lexer("(match)"); - assert_eq!( - match_tokens, - vec![ + lexer_test( + "(match)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::Match, 6)), - Ok((6, Token::CloseRoundBracket, 7)) - ] + Ok((6, Token::CloseRoundBracket, 7)), + ]), ); - let mismatch_tokens = run_lexer("mismatch"); - assert_eq!(mismatch_tokens, vec![Ok((0, Token::MisMatch, 8))]); + lexer_test("mismatch", Single(Ok((0, Token::MisMatch, 8)))); - let mismatch_tokens = run_lexer("(mismatch)"); - assert_eq!( - mismatch_tokens, - vec![ + lexer_test( + "(mismatch)", + All(vec![ Ok((0, Token::OpenRoundBracket, 1)), Ok((1, Token::MisMatch, 9)), - Ok((9, Token::CloseRoundBracket, 10)) - ] + Ok((9, Token::CloseRoundBracket, 10)), + ]), ); } @@ -135,10 +145,9 @@ fn air_instructions() { fn init_peer_id() { const INIT_PEER_ID: &str = "%init_peer_id%"; - let init_peer_id_tokens = run_lexer(INIT_PEER_ID); - assert_eq!( - init_peer_id_tokens, - vec![Ok((0, Token::InitPeerId, INIT_PEER_ID.len()))] + lexer_test( + INIT_PEER_ID, + Single(Ok((0, Token::InitPeerId, INIT_PEER_ID.len()))), ); } @@ -146,14 +155,13 @@ fn init_peer_id() { fn accumulator() { const ACC: &str = "accumulator____asdasd[]"; - let init_peer_id_tokens = run_lexer(ACC); - assert_eq!( - init_peer_id_tokens, - vec![Ok(( + lexer_test( + ACC, + Single(Ok(( 0, Token::Accumulator(&ACC[0..ACC.len() - 2]), - ACC.len() - ))] + ACC.len(), + ))), ); } @@ -161,14 +169,100 @@ fn accumulator() { fn string_literal() { const STRING_LITERAL: &str = r#""some_string""#; - let string_literal_tokens = run_lexer(STRING_LITERAL); - assert_eq!( - string_literal_tokens, - vec![Ok(( + lexer_test( + STRING_LITERAL, + Single(Ok(( 0, Token::StringLiteral(&STRING_LITERAL[1..STRING_LITERAL.len() - 1]), - STRING_LITERAL.len() - ))] + STRING_LITERAL.len(), + ))), + ); +} + +#[test] +fn integer_numbers() { + const NUMBER_WITH_PLUS_SIGN: &str = "+123"; + let number = Number::Int(123); + + lexer_test( + NUMBER_WITH_PLUS_SIGN, + Single(Ok(( + 0, + Token::Number(number.clone()), + NUMBER_WITH_PLUS_SIGN.len(), + ))), + ); + + const NUMBER: &str = "123"; + + lexer_test( + NUMBER, + Single(Ok((0, Token::Number(number.clone()), NUMBER.len()))), + ); + + const NUMBER_WITH_MINUS_SIGN: &str = "-123"; + let number = Number::Int(-123); + + lexer_test( + NUMBER_WITH_MINUS_SIGN, + Single(Ok((0, Token::Number(number), NUMBER_WITH_MINUS_SIGN.len()))), + ); +} + +#[test] +fn float_number() { + const FNUMBER_WITH_PLUS_SIGN: &str = "+123.123"; + let number = Number::Float(123.123); + + lexer_test( + FNUMBER_WITH_PLUS_SIGN, + Single(Ok(( + 0, + Token::Number(number.clone()), + FNUMBER_WITH_PLUS_SIGN.len(), + ))), + ); + + const FNUMBER: &str = "123.123"; + + lexer_test( + FNUMBER, + Single(Ok((0, Token::Number(number), FNUMBER.len()))), + ); + + const FNUMBER_WITH_MINUS_SIGN: &str = "-123.123"; + let number = Number::Float(-123.123); + + lexer_test( + FNUMBER_WITH_MINUS_SIGN, + Single(Ok(( + 0, + Token::Number(number), + FNUMBER_WITH_MINUS_SIGN.len(), + ))), + ); +} + +#[test] +fn too_big_number() { + const NUMBER: &str = "1231231564564545684564646515313546547682131"; + + let number_tokens = run_lexer(NUMBER); + + assert!(matches!( + number_tokens[0], + Err(LexerError::ParseIntError(..)) + )); +} + +#[test] +fn too_big_float_number() { + const FNUMBER: &str = + "10000000000000000000000000000001.1231564564545684564646515313546547682131"; + + lexer_test( + FNUMBER, + Single(Err(LexerError::TooBigFloat(0, FNUMBER.len()))), ); } @@ -177,10 +271,40 @@ fn json_path() { // this json path contains all allowed in json path charactes const JSON_PATH: &str = r#"value.$[$@[]():?.*,"!]"#; - let json_path_tokens = run_lexer(JSON_PATH); - assert_eq!( - json_path_tokens, - vec![Ok((0, Token::JsonPath(JSON_PATH, 5), JSON_PATH.len()))] + lexer_test( + JSON_PATH, + Single(Ok((0, Token::JsonPath(JSON_PATH, 5), JSON_PATH.len()))), + ); +} + +#[test] +fn json_path_numbers() { + const JSON_PATH: &str = r#"12345.$[$@[]():?.*,"!]"#; + + lexer_test( + JSON_PATH, + Single(Err(LexerError::UnallowedCharInNumber(6, 6))), + ); + + const JSON_PATH1: &str = r#"+12345.$[$@[]():?.*,"!]"#; + + lexer_test( + JSON_PATH1, + Single(Err(LexerError::UnallowedCharInNumber(7, 7))), + ); +} + +#[test] +fn leading_dot() { + const LEADING_DOT: &str = ".111"; + + lexer_test(LEADING_DOT, Single(Err(LexerError::LeadingDot(0, 0)))); + + const LEADING_DOT_AFTER_SIGN: &str = "+.1111"; + + lexer_test( + LEADING_DOT_AFTER_SIGN, + Single(Err(LexerError::LeadingDot(1, 1))), ); } @@ -188,10 +312,9 @@ fn json_path() { fn unclosed_quote() { const UNCLOSED_QUOTE_AIR: &str = r#"(call ("peer_name) ("service_name" "function_name") [])"#; - let unclosed_quote_air_tokens = run_lexer(UNCLOSED_QUOTE_AIR); - assert_eq!( - unclosed_quote_air_tokens[4], - Err(LexerError::IsNotAlphanumeric(33, 33)) + lexer_test( + UNCLOSED_QUOTE_AIR, + One(4, Err(LexerError::IsNotAlphanumeric(33, 33))), ); } @@ -200,10 +323,9 @@ fn bad_value() { // value contains ! that only allowed in json path const INVALID_VALUE: &str = r#"val!ue.$[$@[]():?.*,"\!]"#; - let invalid_value_tokens = run_lexer(INVALID_VALUE); - assert_eq!( - invalid_value_tokens, - vec![Err(LexerError::IsNotAlphanumeric(3, 3))] + lexer_test( + INVALID_VALUE, + Single(Err(LexerError::IsNotAlphanumeric(3, 3))), ); } @@ -211,9 +333,44 @@ fn bad_value() { fn invalid_json_path() { const INVALID_JSON_PATH: &str = r#"value.$%"#; - let invalid_json_path_tokens = run_lexer(INVALID_JSON_PATH); - assert_eq!( - invalid_json_path_tokens, - vec![Err(LexerError::InvalidJsonPath(7, 7))] + lexer_test( + INVALID_JSON_PATH, + Single(Err(LexerError::InvalidJsonPath(7, 7))), + ); +} + +#[test] +fn invalid_json_path_numbers() { + // this json path contains all allowed in json path charactes + const JSON_PATH: &str = r#"+12345$[$@[]():?.*,"!]"#; + + lexer_test(JSON_PATH, Single(Err(LexerError::IsNotAlphanumeric(6, 6)))); +} + +#[test] +fn booleans() { + const TRUE_BOOL_CONST: &str = "true"; + + lexer_test( + TRUE_BOOL_CONST, + Single(Ok((0, Token::Boolean(true), TRUE_BOOL_CONST.len()))), + ); + + const FALSE_BOOL_CONST: &str = "false"; + + lexer_test( + FALSE_BOOL_CONST, + Single(Ok((0, Token::Boolean(false), FALSE_BOOL_CONST.len()))), + ); + + const NON_BOOL_CONST: &str = "true1"; + + lexer_test( + NON_BOOL_CONST, + Single(Ok(( + 0, + Token::Alphanumeric(NON_BOOL_CONST), + NON_BOOL_CONST.len(), + ))), ); } diff --git a/crates/air-parser/src/parser/lexer/token.rs b/crates/air-parser/src/parser/lexer/token.rs index 8ff6f091..9dd36025 100644 --- a/crates/air-parser/src/parser/lexer/token.rs +++ b/crates/air-parser/src/parser/lexer/token.rs @@ -14,7 +14,10 @@ * limitations under the License. */ -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +use serde::Deserialize; +use serde::Serialize; + +#[derive(Debug, Clone, PartialEq)] pub enum Token<'input> { OpenRoundBracket, CloseRoundBracket, @@ -25,6 +28,8 @@ pub enum Token<'input> { Alphanumeric(&'input str), JsonPath(&'input str, usize), Accumulator(&'input str), + Number(Number), + Boolean(bool), InitPeerId, LastError, @@ -39,3 +44,73 @@ pub enum Token<'input> { Match, MisMatch, } + +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +pub enum Number { + Int(i64), + Float(f64), +} + +impl From for Token<'_> { + fn from(value: Number) -> Self { + Token::Number(value) + } +} + +impl From for serde_json::Value { + fn from(number: Number) -> Self { + number.into() + } +} + +impl From<&Number> for serde_json::Value { + fn from(number: &Number) -> Self { + match number { + Number::Int(value) => (*value).into(), + Number::Float(value) => (*value).into(), + } + } +} + +use super::LexerError; +use super::LexerResult; +use std::convert::TryFrom; + +pub(crate) enum UnparsedNumber<'input> { + // raw value and starting pos + Int(&'input str, usize), + Float(&'input str, usize), +} + +impl TryFrom> for Number { + type Error = LexerError; + + fn try_from(value: UnparsedNumber<'_>) -> LexerResult { + match value { + UnparsedNumber::Int(raw_value, start_pos) => { + let number = raw_value.parse::().map_err(|e| { + LexerError::ParseIntError(start_pos, start_pos + raw_value.len(), e) + })?; + + let number = Self::Int(number); + Ok(number) + } + + UnparsedNumber::Float(raw_value, start_pos) => { + if raw_value.len() > 11 { + return Err(LexerError::TooBigFloat( + start_pos, + start_pos + raw_value.len(), + )); + } + + let number = raw_value.parse::().map_err(|e| { + LexerError::ParseFloatError(start_pos, start_pos + raw_value.len(), e) + })?; + + let number = Self::Float(number); + Ok(number) + } + } + } +} diff --git a/crates/air-parser/src/parser/lexer/utils.rs b/crates/air-parser/src/parser/lexer/utils.rs new file mode 100644 index 00000000..31776668 --- /dev/null +++ b/crates/air-parser/src/parser/lexer/utils.rs @@ -0,0 +1,43 @@ +/* + * 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. + */ + +pub(super) fn is_aqua_alphanumeric(ch: char) -> bool { + ch.is_alphanumeric() || ch == '_' || ch == '-' +} + +pub(super) fn is_json_path_allowed_char(ch: char) -> bool { + // we don't have spec for json path now, but some possible example could be found here + // https://packagist.org/packages/softcreatr/jsonpath + + // good old switch faster here than hash set + match ch { + '$' => true, + '@' => true, + '[' => true, + ']' => true, + '(' => true, + ')' => true, + ':' => true, + '?' => true, + '.' => true, + '*' => true, + ',' => true, + '"' => true, + '\'' => true, + '!' => true, + ch => is_aqua_alphanumeric(ch), + } +} diff --git a/stepper-lib/Cargo.toml b/stepper-lib/Cargo.toml index f38a9795..6f23d2af 100644 --- a/stepper-lib/Cargo.toml +++ b/stepper-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stepper-lib" -version = "0.4.1" +version = "0.5.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 a6075e9b..2f222482 100644 --- a/stepper-lib/src/execution/air/call/resolved_call.rs +++ b/stepper-lib/src/execution/air/call/resolved_call.rs @@ -35,14 +35,14 @@ use air_parser::ast::{CallInstrArgValue, CallOutputValue}; use std::rc::Rc; /// Represents Call instruction with resolved internal parts. -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, PartialEq)] pub(super) struct ResolvedCall<'i> { triplet: Rc, function_arg_paths: Rc>>, output: CallOutputValue<'i>, } -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, PartialEq)] struct ResolvedArguments { call_arguments: String, tetraplets: Vec>, diff --git a/stepper-lib/src/execution/air/compare_matchable/compare_matchable.rs b/stepper-lib/src/execution/air/compare_matchable/compare_matchable.rs index 87410c5e..860af767 100644 --- a/stepper-lib/src/execution/air/compare_matchable/compare_matchable.rs +++ b/stepper-lib/src/execution/air/compare_matchable/compare_matchable.rs @@ -19,6 +19,7 @@ use crate::execution::air::ExecutionResult; use crate::execution::utils::resolve_to_jvaluable; use crate::JValue; +use air_parser::ast; use air_parser::ast::MatchableValue; pub(crate) fn are_matchable_eq<'ctx>( @@ -29,8 +30,17 @@ pub(crate) fn are_matchable_eq<'ctx>( use MatchableValue::*; match (left, right) { - (Literal(name), matchable) => compare_matchable_and_literal(matchable, name, exec_ctx), - (matchable, Literal(name)) => compare_matchable_and_literal(matchable, name, exec_ctx), + (Literal(left_name), Literal(right_name)) => Ok(left_name == right_name), + + (Literal(value), matchable) => compare_matchable(matchable, exec_ctx, make_string_comparator(value)), + (matchable, Literal(value)) => compare_matchable(matchable, exec_ctx, make_string_comparator(value)), + + (Boolean(value), matchable) => compare_matchable(matchable, exec_ctx, make_bool_comparator(value)), + (matchable, Boolean(value)) => compare_matchable(matchable, exec_ctx, make_bool_comparator(value)), + + (Number(value), matchable) => compare_matchable(matchable, exec_ctx, make_number_comparator(value)), + (matchable, Number(value)) => compare_matchable(matchable, exec_ctx, make_number_comparator(value)), + (Variable(left_name), Variable(right_name)) => { let left_jvaluable = resolve_to_jvaluable(left_name, exec_ctx)?; let left_value = left_jvaluable.as_jvalue(); @@ -53,29 +63,33 @@ pub(crate) fn are_matchable_eq<'ctx>( } } -fn compare_matchable_and_literal<'ctx>( +use std::borrow::Cow; +type Comparator<'a> = Box) -> bool + 'a>; + +fn compare_matchable<'ctx>( matchable: &MatchableValue<'_>, - string_literal: &str, exec_ctx: &'ctx ExecutionCtx<'_>, + comparator: Comparator<'ctx>, ) -> ExecutionResult { - use std::borrow::Cow; use MatchableValue::*; - fn compare_jvalue_and_literal(jvalue: Cow<'_, JValue>, string_literal: &str) -> bool { - use std::ops::Deref; - - match jvalue.deref() { - JValue::String(value) => value == string_literal, - _ => false, - } - } - match matchable { - Literal(name) => Ok(name == &string_literal), + Literal(str) => { + let jvalue = str.to_string().into(); + Ok(comparator(Cow::Owned(jvalue))) + } + Number(number) => { + let jvalue = number.clone().into(); + Ok(comparator(Cow::Owned(jvalue))) + } + Boolean(bool) => { + let jvalue = (*bool).into(); + Ok(comparator(Cow::Owned(jvalue))) + } Variable(name) => { let jvaluable = resolve_to_jvaluable(name, exec_ctx)?; let jvalue = jvaluable.as_jvalue(); - Ok(compare_jvalue_and_literal(jvalue, string_literal)) + Ok(comparator(jvalue)) } JsonPath { variable, path } => { let jvaluable = resolve_to_jvaluable(variable, exec_ctx)?; @@ -84,7 +98,38 @@ fn compare_matchable_and_literal<'ctx>( return Ok(false); } - Ok(compare_jvalue_and_literal(Cow::Borrowed(jvalues[0]), string_literal)) + Ok(comparator(Cow::Borrowed(jvalues[0]))) } } } + +fn make_string_comparator(comparable_string: &str) -> Comparator<'_> { + use std::ops::Deref; + + Box::new(move |jvalue: Cow<'_, JValue>| -> bool { + match jvalue.deref() { + JValue::String(value) => value == comparable_string, + _ => false, + } + }) +} + +fn make_bool_comparator(comparable_bool: &bool) -> Comparator<'_> { + use std::ops::Deref; + + let comparable_bool = *comparable_bool; + Box::new(move |jvalue: Cow<'_, JValue>| -> bool { + match jvalue.deref() { + JValue::Bool(jvalue) => jvalue == &comparable_bool, + _ => false, + } + }) +} + +fn make_number_comparator(comparable_number: &ast::Number) -> Comparator<'_> { + use std::ops::Deref; + + let comparable_jvalue: JValue = comparable_number.into(); + + Box::new(move |jvalue: Cow<'_, JValue>| -> bool { jvalue.deref() == &comparable_jvalue }) +} diff --git a/stepper-lib/src/execution/mod.rs b/stepper-lib/src/execution/mod.rs index c96ceff5..a4426682 100644 --- a/stepper-lib/src/execution/mod.rs +++ b/stepper-lib/src/execution/mod.rs @@ -26,3 +26,10 @@ pub(super) use errors::ExecutionError; use std::rc::Rc; pub(self) type ExecutionResult = std::result::Result>; + +#[macro_export] +macro_rules! exec_err { + ($err:expr) => { + Err(std::rc::Rc::new($err)) + }; +} diff --git a/stepper-lib/src/execution/utils/resolve.rs b/stepper-lib/src/execution/utils/resolve.rs index 01f8acfc..52f0ddb0 100644 --- a/stepper-lib/src/execution/utils/resolve.rs +++ b/stepper-lib/src/execution/utils/resolve.rs @@ -30,16 +30,21 @@ pub(crate) fn resolve_to_args<'i>( ctx: &ExecutionCtx<'i>, ) -> ExecutionResult<(JValue, Vec)> { match value { - CallInstrArgValue::InitPeerId => prepare_string_arg(ctx.init_peer_id.as_str(), ctx), + CallInstrArgValue::InitPeerId => prepare_consts(ctx.init_peer_id.clone(), ctx), CallInstrArgValue::LastError => prepare_last_error(ctx), - CallInstrArgValue::Literal(value) => prepare_string_arg(value, ctx), + CallInstrArgValue::Literal(value) => prepare_consts(value.to_string(), ctx), + CallInstrArgValue::Boolean(value) => prepare_consts(*value, ctx), + CallInstrArgValue::Number(value) => prepare_consts(value, ctx), CallInstrArgValue::Variable(name) => prepare_variable(name, ctx), CallInstrArgValue::JsonPath { variable, path } => prepare_json_path(variable, path, ctx), } } -fn prepare_string_arg<'i>(arg: &str, ctx: &ExecutionCtx<'i>) -> ExecutionResult<(JValue, Vec)> { - let jvalue = JValue::String(arg.to_string()); +fn prepare_consts<'i>( + arg: impl Into, + ctx: &ExecutionCtx<'i>, +) -> ExecutionResult<(JValue, Vec)> { + let jvalue = arg.into(); let tetraplet = SecurityTetraplet::literal_tetraplet(ctx.init_peer_id.clone()); Ok((jvalue, vec![tetraplet])) diff --git a/stepper-lib/src/lib.rs b/stepper-lib/src/lib.rs index 84730e03..1902fe43 100644 --- a/stepper-lib/src/lib.rs +++ b/stepper-lib/src/lib.rs @@ -57,10 +57,3 @@ pub mod parser { } pub(crate) type JValue = serde_json::Value; - -#[macro_export] -macro_rules! exec_err { - ($err:expr) => { - Err(std::rc::Rc::new($err)) - }; -} diff --git a/stepper-lib/tests/security_tetraplets/auth_module/Cargo.lock b/stepper-lib/tests/security_tetraplets/auth_module/Cargo.lock index b86850b8..4e25b9b4 100644 --- a/stepper-lib/tests/security_tetraplets/auth_module/Cargo.lock +++ b/stepper-lib/tests/security_tetraplets/auth_module/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "lalrpop-util", "regex", "serde", + "serde_json", "thiserror", ] @@ -672,7 +673,7 @@ dependencies = [ [[package]] name = "stepper-lib" -version = "0.4.0" +version = "0.4.1" dependencies = [ "air-parser", "boolinator", diff --git a/stepper-lib/tests/security_tetraplets/log_storage/Cargo.lock b/stepper-lib/tests/security_tetraplets/log_storage/Cargo.lock index 61ccdc58..7c4d1f2c 100644 --- a/stepper-lib/tests/security_tetraplets/log_storage/Cargo.lock +++ b/stepper-lib/tests/security_tetraplets/log_storage/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "lalrpop-util", "regex", "serde", + "serde_json", "thiserror", ] @@ -672,7 +673,7 @@ dependencies = [ [[package]] name = "stepper-lib" -version = "0.4.0" +version = "0.4.1" dependencies = [ "air-parser", "boolinator", diff --git a/stepper/Cargo.toml b/stepper/Cargo.toml index f449ee78..b714076a 100644 --- a/stepper/Cargo.toml +++ b/stepper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aquamarine" -version = "0.4.1" +version = "0.5.0" authors = ["Fluence Labs"] edition = "2018"