Merge pull request #72 from wycats/testing

Parsing tests
This commit is contained in:
Jonathan Turner 2019-06-03 05:51:23 +12:00 committed by GitHub
commit a9fa96f09d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 516 additions and 126 deletions

22
Cargo.lock generated
View file

@ -1,5 +1,17 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # 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]] [[package]]
name = "adler32" name = "adler32"
version = "1.0.3" version = "1.0.3"
@ -659,6 +671,11 @@ dependencies = [
"array-macro 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "enumset" name = "enumset"
version = "0.4.0" version = "0.4.0"
@ -1153,6 +1170,7 @@ dependencies = [
name = "nu" name = "nu"
version = "0.1.1" version = "0.1.1"
dependencies = [ 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)", "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)", "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)", "byte-unit 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1165,6 +1183,7 @@ dependencies = [
"cursive 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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-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-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)", "futures_codec 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1174,6 +1193,7 @@ dependencies = [
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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 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)", "logos-derive 0.10.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2245,6 +2265,7 @@ dependencies = [
] ]
[metadata] [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 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 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" "checksum ansi_colours 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0f302a81afc6a7f4350c04f0ba7cfab529cc009bca3324b3fb5764e6add8b6"
@ -2319,6 +2340,7 @@ dependencies = [
"checksum enum-map 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ccd9b2d5e0eb5c2ff851791e2af90ab4531b1168cfc239d1c0bf467e60ba3c89" "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-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-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 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 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" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a"

View file

@ -48,6 +48,9 @@ app_dirs = "1.2.1"
toml = "0.5.1" toml = "0.5.1"
toml-query = "0.9.0" toml-query = "0.9.0"
clap = "2.33.0" clap = "2.33.0"
enum_derive = "0.1.7"
adhoc_derive = "0.1.2"
lazy_static = "1.3.0"
git2 = "0.8.0" git2 = "0.8.0"
[dependencies.pancurses] [dependencies.pancurses]

View file

@ -173,7 +173,7 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
Ok(line) if line.trim() == "" => LineResult::Success(line.clone()), Ok(line) if line.trim() == "" => LineResult::Success(line.clone()),
Ok(line) => { Ok(line) => {
let result = match crate::parser::parse(&line, &ctx.registry()) { let result = match crate::parser::parse(&line) {
Err(err) => { Err(err) => {
return LineResult::Error(err); return LineResult::Error(err);
} }
@ -226,7 +226,7 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
) => match left.run(ctx, input).await { ) => match left.run(ctx, input).await {
Ok(val) => ClassifiedInputStream::from_input_stream(val), Ok(val) => ClassifiedInputStream::from_input_stream(val),
Err(err) => return LineResult::Error(err), Err(err) => return LineResult::Error(err),
} },
( (
Some(ClassifiedCommand::External(left)), Some(ClassifiedCommand::External(left)),

View file

@ -1,4 +1,4 @@
use crate::parser::{Args, CommandConfig, CommandRegistry}; use crate::parser::Args;
use crate::prelude::*; use crate::prelude::*;
use indexmap::IndexMap; use indexmap::IndexMap;
@ -30,12 +30,6 @@ impl Context {
self.commands.clone() self.commands.clone()
} }
pub fn registry(&self) -> CommandMap {
CommandMap {
commands: self.clone_commands(),
}
}
crate fn has_command(&self, name: &str) -> bool { crate fn has_command(&self, name: &str) -> bool {
self.commands.contains_key(name) self.commands.contains_key(name)
} }
@ -61,20 +55,3 @@ impl Context {
command.run(command_args) command.run(command_args)
} }
} }
pub struct CommandMap {
#[allow(unused)]
commands: IndexMap<String, Arc<dyn Command>>,
}
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(),
}
}
}

View file

@ -37,6 +37,7 @@ fn evaluate_leaf(leaf: &ast::Leaf) -> Value {
Leaf::Bare(path) => Value::string(path.to_string()), Leaf::Bare(path) => Value::string(path.to_string()),
Leaf::Boolean(b) => Value::boolean(*b), Leaf::Boolean(b) => Value::boolean(*b),
Leaf::Int(i) => Value::int(*i), Leaf::Int(i) => Value::int(*i),
Leaf::Unit(i, unit) => unit.compute(*i),
} }
} }

View file

@ -6,13 +6,13 @@ crate mod registry;
crate mod span; crate mod span;
crate use ast::{ParsedCommand, Pipeline}; crate use ast::{ParsedCommand, Pipeline};
crate use registry::{Args, CommandConfig, CommandRegistry}; crate use registry::{Args, CommandConfig};
use crate::errors::ShellError; use crate::errors::ShellError;
use lexer::Lexer; use lexer::Lexer;
use parser::PipelineParser; use parser::PipelineParser;
pub fn parse(input: &str, _registry: &dyn CommandRegistry) -> Result<Pipeline, ShellError> { pub fn parse(input: &str) -> Result<Pipeline, ShellError> {
let parser = PipelineParser::new(); let parser = PipelineParser::new();
let tokens = Lexer::new(input, false); let tokens = Lexer::new(input, false);
@ -21,3 +21,147 @@ pub fn parse(input: &str, _registry: &dyn CommandRegistry) -> Result<Pipeline, S
Err(err) => Err(ShellError::parse_error(err, input.to_string())), Err(err) => 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")))
],
);
}
}

View file

@ -1,7 +1,10 @@
use crate::parser::lexer::SpannedToken; use crate::parser::lexer::SpannedToken;
use crate::prelude::*;
use adhoc_derive::FromStr;
use derive_new::new; use derive_new::new;
use getset::Getters; use getset::Getters;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::io::Write;
use std::str::FromStr; use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] #[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 { impl FromStr for Operator {
type Err = (); type Err = ();
fn from_str(input: &str) -> Result<Self, <Self as std::str::FromStr>::Err> { fn from_str(input: &str) -> Result<Self, <Self as std::str::FromStr>::Err> {
@ -53,6 +62,42 @@ pub enum Expression {
VariableReference(Variable), VariableReference(Variable),
} }
impl From<&str> for Expression {
fn from(input: &str) -> Expression {
Expression::Leaf(Leaf::String(input.into()))
}
}
impl From<i64> for Expression {
fn from(input: i64) -> Expression {
Expression::Leaf(Leaf::Int(input.into()))
}
}
impl From<BarePath> for Expression {
fn from(input: BarePath) -> Expression {
Expression::Leaf(Leaf::Bare(input))
}
}
impl From<Variable> for Expression {
fn from(input: Variable) -> Expression {
Expression::VariableReference(input)
}
}
impl From<Flag> for Expression {
fn from(input: Flag) -> Expression {
Expression::Flag(input)
}
}
impl From<Binary> for Expression {
fn from(input: Binary) -> Expression {
Expression::Binary(Box::new(input))
}
}
impl Expression { impl Expression {
crate fn print(&self) -> String { crate fn print(&self) -> String {
match self { match self {
@ -161,6 +206,13 @@ pub enum Variable {
Other(String), 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 { impl Variable {
crate fn from_str(input: &str) -> Expression { crate fn from_str(input: &str) -> Expression {
match input { 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)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct BarePath { pub struct BarePath {
head: String, 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<Unit>) -> Expression {
Expression::Leaf(Leaf::Unit(num, unit.into()))
}
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum Leaf { pub enum Leaf {
String(String), String(String),
@ -210,6 +308,7 @@ pub enum Leaf {
#[allow(unused)] #[allow(unused)]
Boolean(bool), Boolean(bool),
Int(i64), Int(i64),
Unit(i64, Unit),
} }
crate fn bare_string(head: &String, tail: &Vec<String>) -> String { crate fn bare_string(head: &String, tail: &Vec<String>) -> String {
@ -225,6 +324,7 @@ impl Leaf {
Leaf::Bare(path) => format!("{}", path.to_string()), Leaf::Bare(path) => format!("{}", path.to_string()),
Leaf::Boolean(b) => format!("{}", b), Leaf::Boolean(b) => format!("{}", b),
Leaf::Int(i) => format!("{}", i), 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::Bare(path) => format!("{}", path.to_string()),
Leaf::Boolean(b) => format!("{}", b), Leaf::Boolean(b) => format!("{}", b),
Leaf::Int(i) => format!("{}", i), 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 { pub struct Binary {
crate left: Expression, crate left: Expression,
crate operator: Operator, crate operator: Operator,
crate right: Expression, crate right: Expression,
} }
impl Binary {
crate fn new(
left: impl Into<Expression>,
operator: Operator,
right: impl Into<Expression>,
) -> Binary {
Binary {
left: left.into(),
operator,
right: right.into(),
}
}
}
crate fn binary(
left: impl Into<Expression>,
operator: impl Into<Operator>,
right: impl Into<Expression>,
) -> Binary {
Binary {
left: left.into(),
operator: operator.into(),
right: right.into(),
}
}
impl Binary { impl Binary {
fn print(&self) -> String { fn print(&self) -> String {
format!( format!(
@ -271,6 +398,14 @@ pub enum Flag {
Longhand(String), Longhand(String),
} }
crate fn flag(s: &str) -> Flag {
Flag::Longhand(s.into())
}
crate fn short(s: &str) -> Flag {
Flag::Shorthand(s.into())
}
impl Flag { impl Flag {
#[allow(unused)] #[allow(unused)]
crate fn print(&self) -> String { crate fn print(&self) -> String {
@ -286,13 +421,45 @@ impl Flag {
} }
} }
#[derive(new, Debug, Clone)] #[derive(new, Debug, Clone, Eq, PartialEq)]
pub struct ParsedCommand { pub struct ParsedCommand {
crate name: String, crate name: String,
crate args: Vec<Expression>, crate args: Vec<Expression>,
} }
#[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<Expression>)> for ParsedCommand {
fn from(input: (&str, Vec<Expression>)) -> ParsedCommand {
ParsedCommand {
name: input.0.to_string(),
args: input.1,
}
}
}
#[derive(new, Debug, Eq, PartialEq)]
pub struct Pipeline { pub struct Pipeline {
crate commands: Vec<ParsedCommand>, crate commands: Vec<ParsedCommand>,
} }
@ -304,4 +471,8 @@ impl Pipeline {
Pipeline { commands } Pipeline { commands }
} }
crate fn print(&self) -> String {
itertools::join(self.commands.iter().map(|i| i.print()), " | ")
}
} }

View file

@ -14,6 +14,7 @@ crate enum TopToken {
END, END,
#[regex = "-?[0-9]+"] #[regex = "-?[0-9]+"]
#[callback = "after_num"]
Num, Num,
#[regex = r#"'([^']|\\')*'"#] #[regex = r#"'([^']|\\')*'"#]
@ -22,9 +23,6 @@ crate enum TopToken {
#[regex = r#""([^"]|\\")*""#] #[regex = r#""([^"]|\\")*""#]
DQString, DQString,
#[regex = "-?[0-9]+[A-Za-z]+"]
UnitsNum,
#[regex = r"\$"] #[regex = r"\$"]
#[callback = "start_variable"] #[callback = "start_variable"]
Dollar, Dollar,
@ -88,7 +86,6 @@ impl TopToken {
Num => Token::Num, Num => Token::Num,
SQString => Token::SQString, SQString => Token::SQString,
DQString => Token::DQString, DQString => Token::DQString,
UnitsNum => Token::UnitsNum,
Dollar => Token::Dollar, Dollar => Token::Dollar,
Bare => Token::Bare, Bare => Token::Bare,
Pipe => Token::Pipe, Pipe => Token::Pipe,
@ -113,6 +110,11 @@ impl TopToken {
} }
} }
fn after_num<S>(lex: &mut logos::Lexer<TopToken, S>) {
trace!("after_num EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::AfterNum;
}
fn start_variable<S>(lex: &mut logos::Lexer<TopToken, S>) { fn start_variable<S>(lex: &mut logos::Lexer<TopToken, S>) {
trace!("start_variable EXTRAS={:?}", lex.extras); trace!("start_variable EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::Var; lex.extras.current = LexerStateName::Var;
@ -123,6 +125,49 @@ fn end_bare_variable<S>(lex: &mut logos::Lexer<TopToken, S>) {
lex.extras.current = LexerStateName::AfterVariableToken; 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<Token> {
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<S>(lex: &mut logos::Lexer<AfterNum, S>) {
trace!("end_unit EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::Top;
}
fn end_number<S>(lex: &mut logos::Lexer<AfterNum, S>) {
trace!("end_unit EXTRAS={:?}", lex.extras);
lex.extras.current = LexerStateName::Top;
}
#[derive(Logos, Debug, Clone, Copy, Eq, PartialEq)] #[derive(Logos, Debug, Clone, Copy, Eq, PartialEq)]
#[extras = "LexerState"] #[extras = "LexerState"]
crate enum VariableToken { crate enum VariableToken {
@ -241,6 +286,7 @@ crate enum LexerStateName {
Top, Top,
Var, Var,
AfterMemberDot, AfterMemberDot,
AfterNum,
AfterVariableToken, AfterVariableToken,
} }
@ -344,7 +390,7 @@ pub enum Token {
Num, Num,
SQString, SQString,
DQString, DQString,
UnitsNum, Unit,
Dollar, Dollar,
Bare, Bare,
Pipe, Pipe,
@ -421,6 +467,17 @@ impl Iterator for Lexer<'source> {
} }
} }
LexerStateName::AfterNum => {
let (lexer, range, slice, token) = advance::<AfterNum>(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 => { LexerStateName::AfterMemberDot => {
let (lexer, range, slice, token) = let (lexer, range, slice, token) =
advance::<AfterMemberDot>(self.lexer.clone()); advance::<AfterMemberDot>(self.lexer.clone());
@ -708,7 +765,7 @@ mod tests {
assert_lex( assert_lex(
"open input2.json | from-json | select glossary", "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( assert_lex(

View file

@ -22,7 +22,7 @@ Command: ParsedCommand = {
Leaf: Expression = { Leaf: Expression = {
<String> => Expression::Leaf(Leaf::String(<>)), <String> => Expression::Leaf(Leaf::String(<>)),
<Int> => Expression::Leaf(Leaf::Int(<>)), <Int> => Expression::Leaf(Leaf::Int(<>)),
<UnitsNum> => Expression::Leaf(Leaf::Int(<>)), <UnitsNum> => Expression::Leaf(<>),
<Var> => <>, <Var> => <>,
} }
@ -101,8 +101,8 @@ Int: i64 = {
<"num"> => i64::from_str(<>.as_slice()).unwrap() <"num"> => i64::from_str(<>.as_slice()).unwrap()
} }
UnitsNum: i64 = { UnitsNum: Leaf = {
<"unitsnum"> => Byte::from_string(<>.as_slice()).unwrap().get_bytes() as i64 <num: Int> <unit: "unit"> => Leaf::Unit(num, Unit::from_str(unit.as_slice()).unwrap())
} }
extern { extern {
@ -131,6 +131,6 @@ extern {
"bare" => SpannedToken { token: Token::Bare, .. }, "bare" => SpannedToken { token: Token::Bare, .. },
"dqstring" => SpannedToken { token: Token::DQString, .. }, "dqstring" => SpannedToken { token: Token::DQString, .. },
"sqstring" => SpannedToken { token: Token::SQString, .. }, "sqstring" => SpannedToken { token: Token::SQString, .. },
"unitsnum" => SpannedToken { token: Token::UnitsNum, .. }, "unit" => SpannedToken { token: Token::Unit, .. },
} }
} }

View file

@ -1,5 +1,5 @@
// auto-generated: "lalrpop 0.17.0" // auto-generated: "lalrpop 0.17.0"
// sha256: 87c2cd6c2bebdfcacc6ef8d0463e82c6959682b98cab66dffe6dfaf11cb41 // sha256: f1722e94b575b555d0b256de7fbf9e994068cc397fab85faa22717fb778ca4
#![allow(unused)] #![allow(unused)]
use std::str::FromStr; use std::str::FromStr;
use crate::parser::ast::*; use crate::parser::ast::*;
@ -41,108 +41,109 @@ mod __parse__Pipeline {
Variant10(i64), Variant10(i64),
Variant11(Operator), Variant11(Operator),
Variant12(Pipeline), Variant12(Pipeline),
Variant13(Leaf),
} }
const __ACTION: &'static [i8] = &[ const __ACTION: &'static [i8] = &[
// State 0 // State 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 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 // 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 // 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 // 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 4 // 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 // 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 // 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 // State 7
0, 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, 0, 0, -21, 0,
// State 8 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // State 21
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, 0, 45, 0, 0, 0,
// State 22 // 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 // State 23
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 24 // State 24
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 25 // 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 // State 26
-28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, 0, -28, -28, -28, 0, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, -28, 0, -28, -28, -28, 0, -28, -28, -28,
// State 27 // 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 // 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 // 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, 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, 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 // 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, 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // State 43
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0,
// State 44 // 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 // State 45
0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 46 // 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 // State 47
-13, 0, 0, 63, 0, 0, -13, -13, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 63, 0, 0, -13, -13, -13, -13, -13, -13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// State 48 // 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 // 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 // State 50
-53, 0, 0, 0, 0, 0, -53, -53, -53, -53, -53, -53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, -53, 0, 0, 0, 0, 0, -53, -53, -53, -53, -53, -53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64,
// State 51 // State 51
@ -154,31 +155,31 @@ mod __parse__Pipeline {
// State 54 // State 54
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0,
// State 55 // 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 // State 56
0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, -16, 0, 0, 0, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, -16,
// State 57 // State 57
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 61, 0, 28, 0, 0, 0, 0, 0,
// State 58 // 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 // 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 // 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 // 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 // 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 // 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 // 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 // State 65
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -11, 0,
// State 66 // 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 // 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] = &[ const __EOF_ACTION: &'static [i8] = &[
// State 0 // State 0
@ -238,15 +239,15 @@ mod __parse__Pipeline {
// State 27 // State 27
-49, -49,
// State 28 // State 28
-51, 0,
// State 29 // State 29
0,
// State 30
-48, -48,
// State 31 // State 30
0, 0,
// State 32 // State 31
-15, -15,
// State 32
0,
// State 33 // State 33
0, 0,
// State 34 // State 34
@ -262,9 +263,9 @@ mod __parse__Pipeline {
// State 39 // State 39
0, 0,
// State 40 // State 40
0,
// State 41
-25, -25,
// State 41
-51,
// State 42 // State 42
-43, -43,
// State 43 // State 43
@ -324,11 +325,11 @@ mod __parse__Pipeline {
// State 1 // 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, 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 // 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 // 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, 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 // 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 // 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, 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 // State 6
@ -338,9 +339,9 @@ mod __parse__Pipeline {
// State 8 // 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, 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 // 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 // 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 // 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, 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 // State 12
@ -376,19 +377,19 @@ mod __parse__Pipeline {
// State 27 // 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, 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 // 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, 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, 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, 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 // 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, 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 // 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, 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 // 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, 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 // State 36
@ -412,7 +413,7 @@ mod __parse__Pipeline {
// State 45 // 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, 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 // 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 // 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, 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 // State 48
@ -475,7 +476,7 @@ mod __parse__Pipeline {
r###""member""###, r###""member""###,
r###""num""###, r###""num""###,
r###""sqstring""###, r###""sqstring""###,
r###""unitsnum""###, r###""unit""###,
r###""variable""###, r###""variable""###,
r###""{""###, r###""{""###,
r###""|""###, r###""|""###,
@ -609,7 +610,7 @@ mod __parse__Pipeline {
SpannedToken { token: Token::Member, .. } if true => Some(14), SpannedToken { token: Token::Member, .. } if true => Some(14),
SpannedToken { token: Token::Num, .. } if true => Some(15), SpannedToken { token: Token::Num, .. } if true => Some(15),
SpannedToken { token: Token::SQString, .. } if true => Some(16), 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::Variable, .. } if true => Some(18),
SpannedToken { token: Token::OpenBrace, .. } if true => Some(19), SpannedToken { token: Token::OpenBrace, .. } if true => Some(19),
SpannedToken { token: Token::Pipe, .. } if true => Some(20), SpannedToken { token: Token::Pipe, .. } if true => Some(20),
@ -695,7 +696,7 @@ mod __parse__Pipeline {
_ => unreachable!(), _ => unreachable!(),
}, },
17 => match __token { 17 => match __token {
__tok @ SpannedToken { token: Token::UnitsNum, .. } => __Symbol::Variant0((__tok)), __tok @ SpannedToken { token: Token::Unit, .. } => __Symbol::Variant0((__tok)),
_ => unreachable!(), _ => unreachable!(),
}, },
18 => match __token { 18 => match __token {
@ -1027,7 +1028,7 @@ mod __parse__Pipeline {
} }
50 => { 50 => {
__state_machine::SimulatedReduce::Reduce { __state_machine::SimulatedReduce::Reduce {
states_to_pop: 1, states_to_pop: 2,
nonterminal_produced: 24, nonterminal_produced: 24,
} }
} }
@ -1308,6 +1309,17 @@ mod __parse__Pipeline {
_ => panic!("symbol type mismatch") _ => 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< fn __pop_Variant11<
'input, 'input,
>( >(
@ -1992,7 +2004,7 @@ mod __parse__Pipeline {
) -> (usize, usize) ) -> (usize, usize)
{ {
// Leaf = UnitsNum => ActionFn(8); // Leaf = UnitsNum => ActionFn(8);
let __sym0 = __pop_Variant10(__symbols); let __sym0 = __pop_Variant13(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym0.2.clone();
let __nt = super::__action8::<>(__sym0); let __nt = super::__action8::<>(__sym0);
@ -2357,13 +2369,14 @@ mod __parse__Pipeline {
_: ::std::marker::PhantomData<(&'input ())>, _: ::std::marker::PhantomData<(&'input ())>,
) -> (usize, usize) ) -> (usize, usize)
{ {
// UnitsNum = "unitsnum" => ActionFn(40); // UnitsNum = Int, "unit" => ActionFn(40);
let __sym0 = __pop_Variant0(__symbols); let __sym1 = __pop_Variant0(__symbols);
let __sym0 = __pop_Variant10(__symbols);
let __start = __sym0.0.clone(); let __start = __sym0.0.clone();
let __end = __sym0.2.clone(); let __end = __sym1.2.clone();
let __nt = super::__action40::<>(__sym0); let __nt = super::__action40::<>(__sym0, __sym1);
__symbols.push((__start, __Symbol::Variant10(__nt), __end)); __symbols.push((__start, __Symbol::Variant13(__nt), __end));
(1, 24) (2, 24)
} }
pub(crate) fn __reduce51< pub(crate) fn __reduce51<
'input, 'input,
@ -2501,10 +2514,10 @@ fn __action7<
fn __action8< fn __action8<
'input, 'input,
>( >(
(_, __0, _): (usize, i64, usize), (_, __0, _): (usize, Leaf, usize),
) -> Expression ) -> Expression
{ {
Expression::Leaf(Leaf::Int(__0)) Expression::Leaf(__0)
} }
fn __action9< fn __action9<
@ -2804,10 +2817,11 @@ fn __action39<
fn __action40< fn __action40<
'input, 'input,
>( >(
(_, __0, _): (usize, SpannedToken<'input>, usize), (_, num, _): (usize, i64, usize),
) -> i64 (_, 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< fn __action41<

View file

@ -197,6 +197,7 @@ fn expect_simple_expr(expr: ast::Expression) -> Result<Value, ShellError> {
ast::Leaf::String(s) => Value::string(s), ast::Leaf::String(s) => Value::string(s),
ast::Leaf::Boolean(b) => Value::boolean(b), ast::Leaf::Boolean(b) => Value::boolean(b),
ast::Leaf::Int(i) => Value::int(i), ast::Leaf::Int(i) => Value::int(i),
ast::Leaf::Unit(i, unit) => unit.compute(i),
}), }),
// TODO: Diagnostic // TODO: Diagnostic