From b9159f033bab6686bafe799676c990215702c0b1 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 2 Jun 2019 09:28:40 -0700 Subject: [PATCH] Parsing tests --- Cargo.lock | 22 +++++ Cargo.toml | 3 + src/cli.rs | 4 +- src/context.rs | 25 +----- src/evaluate/evaluator.rs | 1 + src/parser.rs | 148 +++++++++++++++++++++++++++++- src/parser/ast.rs | 177 +++++++++++++++++++++++++++++++++++- src/parser/lexer.rs | 69 ++++++++++++-- src/parser/parser.lalrpop | 8 +- src/parser/parser.rs | 184 ++++++++++++++++++++------------------ src/parser/registry.rs | 1 + 11 files changed, 516 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22c36fea44..7e9ae53f2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,17 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adhoc_derive" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "adler32" version = "1.0.3" @@ -645,6 +657,11 @@ dependencies = [ "array-macro 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "enum_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "enumset" version = "0.4.0" @@ -1072,6 +1089,7 @@ dependencies = [ name = "nu" version = "0.1.1" dependencies = [ + "adhoc_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "byte-unit 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1084,6 +1102,7 @@ dependencies = [ "cursive 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "dunce 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "enum_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "futures-preview 0.3.0-alpha.16 (registry+https://github.com/rust-lang/crates.io-index)", "futures-sink-preview 0.3.0-alpha.16 (registry+https://github.com/rust-lang/crates.io-index)", "futures_codec 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1092,6 +1111,7 @@ dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-util 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "language-reporting 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "logos 0.10.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)", "logos-derive 0.10.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2110,6 +2130,7 @@ dependencies = [ ] [metadata] +"checksum adhoc_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa59c078ee916c8c12c50d1d0e1c4015475ce664f05375e54cf06545930c61" "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum ansi_colours 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0f302a81afc6a7f4350c04f0ba7cfab529cc009bca3324b3fb5764e6add8b6" @@ -2183,6 +2204,7 @@ dependencies = [ "checksum enum-map 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ccd9b2d5e0eb5c2ff851791e2af90ab4531b1168cfc239d1c0bf467e60ba3c89" "checksum enum-map-derive 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "153f6e8a8b2868e2fedf921b165f30229edcccb74d6a9bb1ccf0480ef61cd07e" "checksum enum-map-internals 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38b0bacf3ea7aba18ce84032efc3f0fa29f5c814048b742ab3e64d07d83ac3e8" +"checksum enum_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "406ac2a8c9eedf8af9ee1489bee9e50029278a6456c740f7454cf8a158abc816" "checksum enumset 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cac0a22e173f6570a7d69a2ab9e3fe79cf0dcdd0fdb162bfc932b97158f2b2a7" "checksum enumset_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01d93b926a992a4a526c2a14e2faf734fdef5bf9d0a52ba69a2ca7d4494c284b" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" diff --git a/Cargo.toml b/Cargo.toml index 02a59f0fd9..515dce5b1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,9 @@ app_dirs = "1.2.1" toml = "0.5.1" toml-query = "0.9.0" clap = "2.33.0" +enum_derive = "0.1.7" +adhoc_derive = "0.1.2" +lazy_static = "1.3.0" [dependencies.pancurses] version = "0.16" diff --git a/src/cli.rs b/src/cli.rs index c5a4beac56..8cbcc0244f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -167,7 +167,7 @@ async fn process_line(readline: Result, ctx: &mut Context Ok(line) if line.trim() == "" => LineResult::Success(line.clone()), Ok(line) => { - let result = match crate::parser::parse(&line, &ctx.registry()) { + let result = match crate::parser::parse(&line) { Err(err) => { return LineResult::Error(err); } @@ -220,7 +220,7 @@ async fn process_line(readline: Result, ctx: &mut Context ) => match left.run(ctx, input).await { Ok(val) => ClassifiedInputStream::from_input_stream(val), Err(err) => return LineResult::Error(err), - } + }, ( Some(ClassifiedCommand::External(left)), diff --git a/src/context.rs b/src/context.rs index 5b75f68149..cc8752eefb 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,4 +1,4 @@ -use crate::parser::{Args, CommandConfig, CommandRegistry}; +use crate::parser::Args; use crate::prelude::*; use indexmap::IndexMap; @@ -30,12 +30,6 @@ impl Context { self.commands.clone() } - pub fn registry(&self) -> CommandMap { - CommandMap { - commands: self.clone_commands(), - } - } - crate fn has_command(&self, name: &str) -> bool { self.commands.contains_key(name) } @@ -61,20 +55,3 @@ impl Context { command.run(command_args) } } - -pub struct CommandMap { - #[allow(unused)] - commands: IndexMap>, -} - -impl CommandRegistry for CommandMap { - fn get(&self, name: &str) -> CommandConfig { - CommandConfig { - name: name.to_string(), - mandatory_positional: vec![], - optional_positional: vec![], - rest_positional: true, - named: IndexMap::new(), - } - } -} diff --git a/src/evaluate/evaluator.rs b/src/evaluate/evaluator.rs index 71eab8b134..d5f61010be 100644 --- a/src/evaluate/evaluator.rs +++ b/src/evaluate/evaluator.rs @@ -39,6 +39,7 @@ fn evaluate_leaf(leaf: &ast::Leaf) -> Value { Leaf::Bare(path) => Value::string(path.to_string()), Leaf::Boolean(b) => Value::boolean(*b), Leaf::Int(i) => Value::int(*i), + Leaf::Unit(i, unit) => unit.compute(*i), } } diff --git a/src/parser.rs b/src/parser.rs index 742e6ca771..36413f7eef 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -6,13 +6,13 @@ crate mod registry; crate mod span; crate use ast::{ParsedCommand, Pipeline}; -crate use registry::{Args, CommandConfig, CommandRegistry}; +crate use registry::{Args, CommandConfig}; use crate::errors::ShellError; use lexer::Lexer; use parser::PipelineParser; -pub fn parse(input: &str, _registry: &dyn CommandRegistry) -> Result { +pub fn parse(input: &str) -> Result { let parser = PipelineParser::new(); let tokens = Lexer::new(input, false); @@ -21,3 +21,147 @@ pub fn parse(input: &str, _registry: &dyn CommandRegistry) -> Result Err(ShellError::parse_error(err, input.to_string())), } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::parser::ast::{bare, binary, flag, short, unit, var, Pipeline}; + use pretty_assertions::assert_eq; + + fn assert_parse(source: &str, expected: Pipeline) { + let parsed = parse(source).unwrap(); + let printed = parsed.print(); + assert_eq!(parsed, expected); + assert_eq!(source, printed); + } + + macro_rules! commands { + ( $( ( $name:tt $( $command:expr)* ) )|* ) => { + Pipeline::new(vec![ + $( + command!($name $($command)*) + ),* + ]) + } + } + + macro_rules! command { + ($name:ident $( $command:expr )*) => { + ParsedCommand::new(stringify!($name).into(), vec![ $($command.into()),* ]) + }; + + ($name:ident $( $command:expr )*) => { + ParsedCommand::new(stringify!($name).into(), vec![ $($command.into()),* ]) + }; + + ($name:tt $( $command:expr )*) => { + ParsedCommand::new($name.into(), vec![ $($command.into()),* ]) + }; + } + + #[test] + fn parse_simple_command() { + assert_parse("ls", commands![(ls)]); + } + + #[test] + fn parse_command_with_args() { + assert_parse( + r#"open Cargo.toml | select package.authors | split-row " ""#, + commands![ + (open bare("Cargo.toml")) + | (select bare("package.authors")) + | ("split-row" " ") + ], + ); + + assert_parse(r#"git add ."#, commands![("git" bare("add") bare("."))]); + + assert_parse( + "open Cargo.toml | select package.version | echo $it", + commands![ + (open bare("Cargo.toml")) + | (select bare("package.version")) + | (echo var("it")) + ], + ); + + assert_parse( + "open Cargo.toml --raw", + commands![(open bare("Cargo.toml") flag("raw"))], + ); + + assert_parse( + "open Cargo.toml -r", + commands![(open bare("Cargo.toml") short("r"))], + ); + + assert_parse( + "open Cargo.toml | from-toml | to-toml", + commands![(open bare("Cargo.toml")) | ("from-toml") | ("to-toml")], + ); + + assert_parse( + r#"config --get "ignore dups" | format-list"#, + commands![(config flag("get") "ignore dups") | ("format-list")], + ); + + assert_parse( + "open Cargo.toml | from-toml | select dependencies | column serde", + commands![ + (open bare("Cargo.toml")) + | ("from-toml") + | (select bare("dependencies")) + | (column bare("serde")) + ], + ); + + assert_parse( + "config --set tabs 2", + commands![(config flag("set") bare("tabs") 2)], + ); + + assert_parse( + r#"ls | skip 1 | first 2 | select "file name" | rm $it"#, + commands![ + (ls) + | (skip 1) + | (first 2) + | (select "file name") + | (rm var("it")) + ], + ); + + assert_parse( + r#"git branch --merged | split-row "`n" | where $it != "* master""#, + commands![ + // TODO: Handle escapes correctly. Should we do ` escape because of paths? + (git bare("branch") flag("merged")) | ("split-row" "`n") | (where binary(var("it"), "!=", "* master")) + ], + ); + + assert_parse( + r#"open input2.json | from-json | select glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso | where $it > "GML""#, + commands![ + (open bare("input2.json")) + | ("from-json") + | (select bare("glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso")) + | (where binary(var("it"), ">", "GML")) + ] + ); + + assert_parse( + r"cd ..\.cargo\", + commands![ + (cd bare(r"..\.cargo\")) + ], + ); + + assert_parse( + "ls | where size < 1KB", + commands![ + (ls) | (where binary(bare("size"), "<", unit(1, "KB"))) + ], + ); + } +} diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 50abd228f6..01ab15be5b 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -1,7 +1,10 @@ use crate::parser::lexer::SpannedToken; +use crate::prelude::*; +use adhoc_derive::FromStr; use derive_new::new; use getset::Getters; use serde_derive::{Deserialize, Serialize}; +use std::io::Write; use std::str::FromStr; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] @@ -27,6 +30,12 @@ impl Operator { } } +impl From<&str> for Operator { + fn from(input: &str) -> Operator { + Operator::from_str(input).unwrap() + } +} + impl FromStr for Operator { type Err = (); fn from_str(input: &str) -> Result::Err> { @@ -53,6 +62,42 @@ pub enum Expression { VariableReference(Variable), } +impl From<&str> for Expression { + fn from(input: &str) -> Expression { + Expression::Leaf(Leaf::String(input.into())) + } +} + +impl From for Expression { + fn from(input: i64) -> Expression { + Expression::Leaf(Leaf::Int(input.into())) + } +} + +impl From for Expression { + fn from(input: BarePath) -> Expression { + Expression::Leaf(Leaf::Bare(input)) + } +} + +impl From for Expression { + fn from(input: Variable) -> Expression { + Expression::VariableReference(input) + } +} + +impl From for Expression { + fn from(input: Flag) -> Expression { + Expression::Flag(input) + } +} + +impl From for Expression { + fn from(input: Binary) -> Expression { + Expression::Binary(Box::new(input)) + } +} + impl Expression { crate fn print(&self) -> String { match self { @@ -161,6 +206,13 @@ pub enum Variable { Other(String), } +crate fn var(name: &str) -> Expression { + match name { + "it" => Expression::VariableReference(Variable::It), + other => Expression::VariableReference(Variable::Other(other.to_string())), + } +} + impl Variable { crate fn from_str(input: &str) -> Expression { match input { @@ -183,6 +235,13 @@ impl Variable { } } +pub fn bare(s: &str) -> BarePath { + BarePath { + head: s.into(), + tail: vec![], + } +} + #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] pub struct BarePath { head: String, @@ -202,6 +261,45 @@ impl BarePath { } } +#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, FromStr)] +pub enum Unit { + #[adhoc(regex = "^B$")] + B, + #[adhoc(regex = "^KB$")] + KB, + #[adhoc(regex = "^MB$")] + MB, + #[adhoc(regex = "^GB$")] + GB, + #[adhoc(regex = "^TB$")] + TB, + #[adhoc(regex = "^PB$")] + PB, +} + +impl From<&str> for Unit { + fn from(input: &str) -> Unit { + Unit::from_str(input).unwrap() + } +} + +impl Unit { + crate fn compute(&self, size: i64) -> Value { + Value::int(match self { + Unit::B => size, + Unit::KB => size * 1024, + Unit::MB => size * 1024 * 1024, + Unit::GB => size * 1024 * 1024 * 1024, + Unit::TB => size * 1024 * 1024 * 1024 * 1024, + Unit::PB => size * 1024 * 1024 * 1024 * 1024 * 1024, + }) + } +} + +pub fn unit(num: i64, unit: impl Into) -> Expression { + Expression::Leaf(Leaf::Unit(num, unit.into())) +} + #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] pub enum Leaf { String(String), @@ -210,6 +308,7 @@ pub enum Leaf { #[allow(unused)] Boolean(bool), Int(i64), + Unit(i64, Unit), } crate fn bare_string(head: &String, tail: &Vec) -> String { @@ -225,6 +324,7 @@ impl Leaf { Leaf::Bare(path) => format!("{}", path.to_string()), Leaf::Boolean(b) => format!("{}", b), Leaf::Int(i) => format!("{}", i), + Leaf::Unit(i, unit) => format!("{}{:?}", i, unit), } } @@ -234,17 +334,44 @@ impl Leaf { Leaf::Bare(path) => format!("{}", path.to_string()), Leaf::Boolean(b) => format!("{}", b), Leaf::Int(i) => format!("{}", i), + Leaf::Unit(i, unit) => format!("{}{:?}", i, unit), } } } -#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)] +#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] pub struct Binary { crate left: Expression, crate operator: Operator, crate right: Expression, } +impl Binary { + crate fn new( + left: impl Into, + operator: Operator, + right: impl Into, + ) -> Binary { + Binary { + left: left.into(), + operator, + right: right.into(), + } + } +} + +crate fn binary( + left: impl Into, + operator: impl Into, + right: impl Into, +) -> Binary { + Binary { + left: left.into(), + operator: operator.into(), + right: right.into(), + } +} + impl Binary { fn print(&self) -> String { format!( @@ -271,6 +398,14 @@ pub enum Flag { Longhand(String), } +crate fn flag(s: &str) -> Flag { + Flag::Longhand(s.into()) +} + +crate fn short(s: &str) -> Flag { + Flag::Shorthand(s.into()) +} + impl Flag { #[allow(unused)] crate fn print(&self) -> String { @@ -286,13 +421,45 @@ impl Flag { } } -#[derive(new, Debug, Clone)] +#[derive(new, Debug, Clone, Eq, PartialEq)] pub struct ParsedCommand { crate name: String, crate args: Vec, } -#[derive(new, Debug)] +impl ParsedCommand { + fn print(&self) -> String { + let mut out = vec![]; + + write!(out, "{}", self.name).unwrap(); + + for arg in self.args.iter() { + write!(out, " {}", arg.print()).unwrap(); + } + + String::from_utf8_lossy(&out).into_owned() + } +} + +impl From<&str> for ParsedCommand { + fn from(input: &str) -> ParsedCommand { + ParsedCommand { + name: input.to_string(), + args: vec![], + } + } +} + +impl From<(&str, Vec)> for ParsedCommand { + fn from(input: (&str, Vec)) -> ParsedCommand { + ParsedCommand { + name: input.0.to_string(), + args: input.1, + } + } +} + +#[derive(new, Debug, Eq, PartialEq)] pub struct Pipeline { crate commands: Vec, } @@ -304,4 +471,8 @@ impl Pipeline { Pipeline { commands } } + + crate fn print(&self) -> String { + itertools::join(self.commands.iter().map(|i| i.print()), " | ") + } } diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index 387ba6f04f..5299d46171 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -14,6 +14,7 @@ crate enum TopToken { END, #[regex = "-?[0-9]+"] + #[callback = "after_num"] Num, #[regex = r#"'([^']|\\')*'"#] @@ -22,9 +23,6 @@ crate enum TopToken { #[regex = r#""([^"]|\\")*""#] DQString, - #[regex = "-?[0-9]+[A-Za-z]+"] - UnitsNum, - #[regex = r"\$"] #[callback = "start_variable"] Dollar, @@ -88,7 +86,6 @@ impl TopToken { Num => Token::Num, SQString => Token::SQString, DQString => Token::DQString, - UnitsNum => Token::UnitsNum, Dollar => Token::Dollar, Bare => Token::Bare, Pipe => Token::Pipe, @@ -113,6 +110,11 @@ impl TopToken { } } +fn after_num(lex: &mut logos::Lexer) { + trace!("after_num EXTRAS={:?}", lex.extras); + lex.extras.current = LexerStateName::AfterNum; +} + fn start_variable(lex: &mut logos::Lexer) { trace!("start_variable EXTRAS={:?}", lex.extras); lex.extras.current = LexerStateName::Var; @@ -123,6 +125,49 @@ fn end_bare_variable(lex: &mut logos::Lexer) { lex.extras.current = LexerStateName::AfterVariableToken; } +#[derive(Logos, Debug, Clone, Copy, Eq, PartialEq)] +#[extras = "LexerState"] +crate enum AfterNum { + #[error] + Error, + + #[end] + END, + + #[regex = "(B|KB|MB|GB|TB|PB)"] + #[callback = "end_unit"] + Unit, + + #[regex = r"\s"] + #[callback = "end_number"] + Whitespace, +} + +impl AfterNum { + fn to_token(&self) -> Option { + use AfterNum::*; + + let result = match self { + END => return None, + Unit => Token::Unit, + Whitespace => Token::Whitespace, + Error => unreachable!("Don't call to_token with the error variant"), + }; + + Some(result) + } +} + +fn end_unit(lex: &mut logos::Lexer) { + trace!("end_unit EXTRAS={:?}", lex.extras); + lex.extras.current = LexerStateName::Top; +} + +fn end_number(lex: &mut logos::Lexer) { + trace!("end_unit EXTRAS={:?}", lex.extras); + lex.extras.current = LexerStateName::Top; +} + #[derive(Logos, Debug, Clone, Copy, Eq, PartialEq)] #[extras = "LexerState"] crate enum VariableToken { @@ -241,6 +286,7 @@ crate enum LexerStateName { Top, Var, AfterMemberDot, + AfterNum, AfterVariableToken, } @@ -344,7 +390,7 @@ pub enum Token { Num, SQString, DQString, - UnitsNum, + Unit, Dollar, Bare, Pipe, @@ -421,6 +467,17 @@ impl Iterator for Lexer<'source> { } } + LexerStateName::AfterNum => { + let (lexer, range, slice, token) = advance::(self.lexer.clone()); + self.lexer = lexer; + + match token { + AfterNum::Error => return Some(Err(lex_error(&range, self.lexer.source))), + AfterNum::Whitespace if !self.whitespace => self.next(), + other => return spanned(other.to_token()?, slice, &range), + } + } + LexerStateName::AfterMemberDot => { let (lexer, range, slice, token) = advance::(self.lexer.clone()); @@ -708,7 +765,7 @@ mod tests { assert_lex( "open input2.json | from-json | select glossary", - tokens![ Bare("open") SP Bare("input2") "???." Member("json") SP "|" SP Bare("from-json") SP "|" SP Bare("select") SP Bare("glossary") ], + tokens![ Bare("open") SP Bare("input2.json") SP "|" SP Bare("from-json") SP "|" SP Bare("select") SP Bare("glossary") ], ); assert_lex( diff --git a/src/parser/parser.lalrpop b/src/parser/parser.lalrpop index 2e58f37a7d..d2347ff69b 100644 --- a/src/parser/parser.lalrpop +++ b/src/parser/parser.lalrpop @@ -22,7 +22,7 @@ Command: ParsedCommand = { Leaf: Expression = { => Expression::Leaf(Leaf::String(<>)), => Expression::Leaf(Leaf::Int(<>)), - => Expression::Leaf(Leaf::Int(<>)), + => Expression::Leaf(<>), => <>, } @@ -101,8 +101,8 @@ Int: i64 = { <"num"> => i64::from_str(<>.as_slice()).unwrap() } -UnitsNum: i64 = { - <"unitsnum"> => Byte::from_string(<>.as_slice()).unwrap().get_bytes() as i64 +UnitsNum: Leaf = { + => Leaf::Unit(num, Unit::from_str(unit.as_slice()).unwrap()) } extern { @@ -131,6 +131,6 @@ extern { "bare" => SpannedToken { token: Token::Bare, .. }, "dqstring" => SpannedToken { token: Token::DQString, .. }, "sqstring" => SpannedToken { token: Token::SQString, .. }, - "unitsnum" => SpannedToken { token: Token::UnitsNum, .. }, + "unit" => SpannedToken { token: Token::Unit, .. }, } } \ No newline at end of file diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 63f68726fa..77c0b7ba8e 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,5 +1,5 @@ // auto-generated: "lalrpop 0.17.0" -// sha256: 87c2cd6c2bebdfcacc6ef8d0463e82c6959682b98cab66dffe6dfaf11cb41 +// sha256: f1722e94b575b555d0b256de7fbf9e994068cc397fab85faa22717fb778ca4 #![allow(unused)] use std::str::FromStr; use crate::parser::ast::*; @@ -41,108 +41,109 @@ mod __parse__Pipeline { Variant10(i64), Variant11(Operator), Variant12(Pipeline), + Variant13(Leaf), } const __ACTION: &'static [i8] = &[ // State 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 1 - 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 29, 0, 30, -19, 0, + 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 0, 0, 29, -19, 0, // State 2 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, // State 3 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 4 - -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, 34, -14, -14, 0, -14, -14, -14, 0, -14, -14, -14, + -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, -14, 33, -14, -14, 0, -14, -14, 0, 0, -14, -14, -14, // State 5 - -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, 0, -53, -53, -53, 0, -53, -53, -53, + -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -53, 0, -53, -53, 0, 0, -53, -53, -53, // State 6 - -45, -45, -45, -45, -45, -45, -45, -45, -45, -45, -45, 0, -45, -45, 0, -45, -45, -45, 0, -45, -45, -45, + -45, -45, -45, -45, -45, -45, -45, -45, -45, -45, -45, 0, -45, -45, 0, -45, -45, 0, 0, -45, -45, -45, // State 7 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -21, 0, // State 8 - -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, 0, -54, -54, -54, 0, -54, -54, -54, + -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54, 0, -54, -54, 0, 0, -54, -54, -54, // State 9 - 36, -24, -24, 0, -24, -24, 37, 38, 39, 40, 41, 0, -24, -24, 0, -24, -24, -24, 0, -24, -24, 0, + 35, -24, -24, 0, -24, -24, 36, 37, 38, 39, 40, 0, -24, -24, 0, -24, -24, 0, 0, -24, -24, 0, // State 10 - 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 29, 0, 30, -20, 0, + 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 0, 0, 29, -20, 0, // State 11 - -46, -46, -46, -46, -46, -46, -46, -46, -46, -46, -46, 0, -46, -46, 0, -46, -46, -46, 0, -46, -46, -46, + -46, -46, -46, -46, -46, -46, -46, -46, -46, -46, -46, 0, -46, -46, 0, -46, -46, 0, 0, -46, -46, -46, // State 12 - -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, 0, -30, -30, -30, 0, -30, -30, -30, + -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, 0, -30, -30, 42, 0, -30, -30, -30, // State 13 - -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, 0, -13, -13, -13, 0, -13, -13, -13, + -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, 0, -13, -13, 0, 0, -13, -13, -13, // State 14 - -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, 0, -12, -12, -12, 0, -12, -12, -12, + -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, -12, 0, -12, -12, 0, 0, -12, -12, -12, // State 15 - -22, -22, -22, -22, -22, -22, -22, -22, -22, -22, -22, 0, -22, -22, 0, -22, -22, -22, 0, -22, -22, -22, + -22, -22, -22, -22, -22, -22, -22, -22, -22, -22, -22, 0, -22, -22, 0, -22, -22, 0, 0, -22, -22, -22, // State 16 - -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, 0, -23, -23, 0, -23, -23, -23, 0, -23, -23, -23, + -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, 0, -23, -23, 0, -23, -23, 0, 0, -23, -23, -23, // State 17 - -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, 0, -29, -29, -29, 0, -29, -29, -29, + -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, -29, 0, -29, -29, 0, 0, -29, -29, -29, // State 18 - -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, 0, -31, -31, -31, 0, -31, -31, -31, + -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, 0, -31, -31, 0, 0, -31, -31, -31, // State 19 - -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 0, -32, -32, -32, 0, -32, -32, -32, + -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 0, -32, -32, 0, 0, -32, -32, -32, // State 20 - -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, 44, -44, -44, 0, -44, -44, -44, 0, -44, -44, -44, + -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, -44, 44, -44, -44, 0, -44, -44, 0, 0, -44, -44, -44, // State 21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, // State 22 - 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 29, 0, 30, 0, 0, + 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 0, 0, 29, 0, 0, // State 23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 24 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 25 - -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, 0, -50, -50, -50, 0, -50, -50, -50, + -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, 0, -50, -50, 0, 0, -50, -50, -50, // State 26 -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, 0, -28, -28, -28, 0, -28, -28, -28, // State 27 - -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, 0, -49, -49, -49, 0, -49, -49, -49, + -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, -49, 0, -49, -49, 0, 0, -49, -49, -49, // State 28 - -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, 0, -51, -51, -51, 0, -51, -51, -51, + 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 0, 0, 29, 0, 0, // State 29 - 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 29, 0, 30, 0, 0, - // State 30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0, - // State 31 + // State 30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 31 + -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, 55, -15, -15, 0, -15, -15, 0, 0, -15, -15, -15, // State 32 - -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, -15, 55, -15, -15, 0, -15, -15, -15, 0, -15, -15, -15, - // State 33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, + // State 33 + 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 0, 0, 29, 0, 0, // State 34 - 0, 22, 23, 0, 24, 25, 0, 0, 0, 0, 0, 0, 5, 26, 0, 27, 28, 29, 0, 30, 0, 0, + 0, -36, -36, 0, -36, -36, 0, 0, 0, 0, 0, 0, -36, -36, 0, -36, -36, 0, 0, -36, 0, 0, // State 35 - 0, -36, -36, 0, -36, -36, 0, 0, 0, 0, 0, 0, -36, -36, 0, -36, -36, -36, 0, -36, 0, 0, + 0, -37, -37, 0, -37, -37, 0, 0, 0, 0, 0, 0, -37, -37, 0, -37, -37, 0, 0, -37, 0, 0, // State 36 - 0, -37, -37, 0, -37, -37, 0, 0, 0, 0, 0, 0, -37, -37, 0, -37, -37, -37, 0, -37, 0, 0, + 0, -39, -39, 0, -39, -39, 0, 0, 0, 0, 0, 0, -39, -39, 0, -39, -39, 0, 0, -39, 0, 0, // State 37 - 0, -39, -39, 0, -39, -39, 0, 0, 0, 0, 0, 0, -39, -39, 0, -39, -39, -39, 0, -39, 0, 0, + 0, -35, -35, 0, -35, -35, 0, 0, 0, 0, 0, 0, -35, -35, 0, -35, -35, 0, 0, -35, 0, 0, // State 38 - 0, -35, -35, 0, -35, -35, 0, 0, 0, 0, 0, 0, -35, -35, 0, -35, -35, -35, 0, -35, 0, 0, + 0, -38, -38, 0, -38, -38, 0, 0, 0, 0, 0, 0, -38, -38, 0, -38, -38, 0, 0, -38, 0, 0, // State 39 - 0, -38, -38, 0, -38, -38, 0, 0, 0, 0, 0, 0, -38, -38, 0, -38, -38, -38, 0, -38, 0, 0, + 0, -40, -40, 0, -40, -40, 0, 0, 0, 0, 0, 0, -40, -40, 0, -40, -40, 0, 0, -40, 0, 0, // State 40 - 0, -40, -40, 0, -40, -40, 0, 0, 0, 0, 0, 0, -40, -40, 0, -40, -40, -40, 0, -40, 0, 0, + 0, -25, -25, 0, -25, -25, 0, 0, 0, 0, 0, 0, -25, -25, 0, -25, -25, 0, 0, -25, -25, 0, // State 41 - 0, -25, -25, 0, -25, -25, 0, 0, 0, 0, 0, 0, -25, -25, 0, -25, -25, -25, 0, -25, -25, 0, + -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, -51, 0, -51, -51, 0, 0, -51, -51, -51, // State 42 - -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, 58, -43, -43, 0, -43, -43, -43, 0, -43, -43, -43, + -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, -43, 58, -43, -43, 0, -43, -43, 0, 0, -43, -43, -43, // State 43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0, // State 44 - -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, 0, -52, -52, -52, 0, -52, -52, -52, + -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, -52, 0, -52, -52, 0, 0, -52, -52, -52, // State 45 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 46 - 36, 0, 0, 0, 0, 0, 37, 38, 39, 40, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 35, 0, 0, 0, 0, 0, 36, 37, 38, 39, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 47 -13, 0, 0, 63, 0, 0, -13, -13, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 48 - -26, -26, -26, -26, -26, -26, -26, -26, -26, -26, -26, 0, -26, -26, 0, -26, -26, -26, 0, -26, -26, -26, + -26, -26, -26, -26, -26, -26, -26, -26, -26, -26, -26, 0, -26, -26, 0, -26, -26, 0, 0, -26, -26, -26, // State 49 - -27, -27, -27, -27, -27, -27, -27, -27, -27, -27, -27, 0, -27, -27, 0, -27, -27, -27, 0, -27, -27, -27, + -27, -27, -27, -27, -27, -27, -27, -27, -27, -27, -27, 0, -27, -27, 0, -27, -27, 0, 0, -27, -27, -27, // State 50 -53, 0, 0, 0, 0, 0, -53, -53, -53, -53, -53, -53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, // State 51 @@ -154,31 +155,31 @@ mod __parse__Pipeline { // State 54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, // State 55 - -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 0, -4, -4, -4, 0, -4, -4, -4, + -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 0, -4, -4, 0, 0, -4, -4, -4, // State 56 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, -16, // State 57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0, // State 58 - -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, 0, -7, -7, -7, 0, -7, -7, -7, + -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7, 0, -7, -7, 0, 0, -7, -7, -7, // State 59 - -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, 0, -34, -34, -34, 0, -34, -34, -34, + -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, -34, 0, -34, -34, 0, 0, -34, -34, -34, // State 60 - -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, 0, -33, -33, -33, 0, -33, -33, -33, + -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, -33, 0, -33, -33, 0, 0, -33, -33, -33, // State 61 - -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, 0, -42, -42, -42, 0, -42, -42, -42, + -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, -42, 0, -42, -42, 0, 0, -42, -42, -42, // State 62 - -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, 0, -41, -41, -41, 0, -41, -41, -41, + -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, -41, 0, -41, -41, 0, 0, -41, -41, -41, // State 63 - -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, 0, -17, -17, -17, 0, -17, -17, -17, + -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, -17, 0, -17, -17, 0, 0, -17, -17, -17, // State 64 - -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, 0, -18, -18, -18, 0, -18, -18, -18, + -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, -18, 0, -18, -18, 0, 0, -18, -18, -18, // State 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0, // State 66 - -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, 0, -5, -5, -5, 0, -5, -5, -5, + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, 0, -5, -5, 0, 0, -5, -5, -5, // State 67 - -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, 0, -8, -8, -8, 0, -8, -8, -8, + -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, 0, -8, -8, 0, 0, -8, -8, -8, ]; const __EOF_ACTION: &'static [i8] = &[ // State 0 @@ -238,15 +239,15 @@ mod __parse__Pipeline { // State 27 -49, // State 28 - -51, + 0, // State 29 - 0, - // State 30 -48, - // State 31 + // State 30 0, - // State 32 + // State 31 -15, + // State 32 + 0, // State 33 0, // State 34 @@ -262,9 +263,9 @@ mod __parse__Pipeline { // State 39 0, // State 40 - 0, - // State 41 -25, + // State 41 + -51, // State 42 -43, // State 43 @@ -324,11 +325,11 @@ mod __parse__Pipeline { // State 1 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 0, 0, 15, 16, 17, 0, 18, 19, 20, 21, 0, // State 2 - 0, 0, 0, 0, 0, 0, 31, 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, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 3 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 4 - 0, 0, 33, 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, 32, 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 5 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 6 @@ -338,9 +339,9 @@ mod __parse__Pipeline { // State 8 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 9 - 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 10 - 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 9, 0, 42, 0, 12, 13, 14, 0, 0, 15, 16, 17, 0, 18, 19, 20, 21, 0, + 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 9, 0, 41, 0, 12, 13, 14, 0, 0, 15, 16, 17, 0, 18, 19, 20, 21, 0, // State 11 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 12 @@ -376,19 +377,19 @@ mod __parse__Pipeline { // State 27 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 28 - 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 29 0, 0, 0, 0, 0, 0, 0, 51, 7, 52, 9, 0, 47, 0, 12, 13, 14, 0, 0, 15, 16, 17, 0, 18, 19, 20, 21, 0, - // State 30 + // State 29 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 31 + // State 30 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + // State 31 + 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 32 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 33 - 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 34 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 9, 0, 57, 0, 12, 13, 14, 0, 0, 15, 16, 17, 0, 18, 19, 20, 21, 0, + // State 34 + 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 35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 36 @@ -412,7 +413,7 @@ mod __parse__Pipeline { // State 45 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 46 - 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, // State 47 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 48 @@ -475,7 +476,7 @@ mod __parse__Pipeline { r###""member""###, r###""num""###, r###""sqstring""###, - r###""unitsnum""###, + r###""unit""###, r###""variable""###, r###""{""###, r###""|""###, @@ -609,7 +610,7 @@ mod __parse__Pipeline { SpannedToken { token: Token::Member, .. } if true => Some(14), SpannedToken { token: Token::Num, .. } if true => Some(15), SpannedToken { token: Token::SQString, .. } if true => Some(16), - SpannedToken { token: Token::UnitsNum, .. } if true => Some(17), + SpannedToken { token: Token::Unit, .. } if true => Some(17), SpannedToken { token: Token::Variable, .. } if true => Some(18), SpannedToken { token: Token::OpenBrace, .. } if true => Some(19), SpannedToken { token: Token::Pipe, .. } if true => Some(20), @@ -695,7 +696,7 @@ mod __parse__Pipeline { _ => unreachable!(), }, 17 => match __token { - __tok @ SpannedToken { token: Token::UnitsNum, .. } => __Symbol::Variant0((__tok)), + __tok @ SpannedToken { token: Token::Unit, .. } => __Symbol::Variant0((__tok)), _ => unreachable!(), }, 18 => match __token { @@ -1027,7 +1028,7 @@ mod __parse__Pipeline { } 50 => { __state_machine::SimulatedReduce::Reduce { - states_to_pop: 1, + states_to_pop: 2, nonterminal_produced: 24, } } @@ -1308,6 +1309,17 @@ mod __parse__Pipeline { _ => panic!("symbol type mismatch") } } + fn __pop_Variant13< + 'input, + >( + __symbols: &mut ::std::vec::Vec<(usize,__Symbol<'input>,usize)> + ) -> (usize, Leaf, usize) + { + match __symbols.pop().unwrap() { + (__l, __Symbol::Variant13(__v), __r) => (__l, __v, __r), + _ => panic!("symbol type mismatch") + } + } fn __pop_Variant11< 'input, >( @@ -1992,7 +2004,7 @@ mod __parse__Pipeline { ) -> (usize, usize) { // Leaf = UnitsNum => ActionFn(8); - let __sym0 = __pop_Variant10(__symbols); + let __sym0 = __pop_Variant13(__symbols); let __start = __sym0.0.clone(); let __end = __sym0.2.clone(); let __nt = super::__action8::<>(__sym0); @@ -2357,13 +2369,14 @@ mod __parse__Pipeline { _: ::std::marker::PhantomData<(&'input ())>, ) -> (usize, usize) { - // UnitsNum = "unitsnum" => ActionFn(40); - let __sym0 = __pop_Variant0(__symbols); + // UnitsNum = Int, "unit" => ActionFn(40); + let __sym1 = __pop_Variant0(__symbols); + let __sym0 = __pop_Variant10(__symbols); let __start = __sym0.0.clone(); - let __end = __sym0.2.clone(); - let __nt = super::__action40::<>(__sym0); - __symbols.push((__start, __Symbol::Variant10(__nt), __end)); - (1, 24) + let __end = __sym1.2.clone(); + let __nt = super::__action40::<>(__sym0, __sym1); + __symbols.push((__start, __Symbol::Variant13(__nt), __end)); + (2, 24) } pub(crate) fn __reduce51< 'input, @@ -2501,10 +2514,10 @@ fn __action7< fn __action8< 'input, >( - (_, __0, _): (usize, i64, usize), + (_, __0, _): (usize, Leaf, usize), ) -> Expression { - Expression::Leaf(Leaf::Int(__0)) + Expression::Leaf(__0) } fn __action9< @@ -2804,10 +2817,11 @@ fn __action39< fn __action40< 'input, >( - (_, __0, _): (usize, SpannedToken<'input>, usize), -) -> i64 + (_, num, _): (usize, i64, usize), + (_, unit, _): (usize, SpannedToken<'input>, usize), +) -> Leaf { - Byte::from_string(__0.as_slice()).unwrap().get_bytes() as i64 + Leaf::Unit(num, Unit::from_str(unit.as_slice()).unwrap()) } fn __action41< diff --git a/src/parser/registry.rs b/src/parser/registry.rs index a589189507..ddccdee375 100644 --- a/src/parser/registry.rs +++ b/src/parser/registry.rs @@ -197,6 +197,7 @@ fn expect_simple_expr(expr: ast::Expression) -> Result { ast::Leaf::String(s) => Value::string(s), ast::Leaf::Boolean(b) => Value::boolean(b), ast::Leaf::Int(i) => Value::int(i), + ast::Leaf::Unit(i, unit) => unit.compute(i), }), // TODO: Diagnostic