Add back in number w/ units parsing

This commit is contained in:
Jonathan Turner 2019-06-01 05:21:03 +12:00
parent 5ebe9c58aa
commit f38726d2aa
4 changed files with 561 additions and 470 deletions

View file

@ -27,7 +27,7 @@ pub fn row_split(args: CommandArgs) -> Result<OutputStream, ShellError> {
} }
_ => { _ => {
let mut result = VecDeque::new(); let mut result = VecDeque::new();
result.push_back(ReturnValue::Value(Value::Object(crate::object::Dictionary::default()))); //result.push_back(ReturnValue::Value(Value::Object(crate::object::Dictionary::default())));
result result
} }
}) })

View file

@ -23,7 +23,7 @@ crate enum TopToken {
DQString, DQString,
#[regex = "-?[0-9]+[A-Za-z]+"] #[regex = "-?[0-9]+[A-Za-z]+"]
Size, UnitsNum,
#[regex = r"\$"] #[regex = r"\$"]
#[callback = "start_variable"] #[callback = "start_variable"]
@ -88,7 +88,7 @@ impl TopToken {
Num => Token::Num, Num => Token::Num,
SQString => Token::SQString, SQString => Token::SQString,
DQString => Token::DQString, DQString => Token::DQString,
Size => Token::Size, UnitsNum => Token::UnitsNum,
Dollar => Token::Dollar, Dollar => Token::Dollar,
Bare => Token::Bare, Bare => Token::Bare,
Pipe => Token::Pipe, Pipe => Token::Pipe,
@ -344,7 +344,7 @@ pub enum Token {
Num, Num,
SQString, SQString,
DQString, DQString,
Size, UnitsNum,
Dollar, Dollar,
Bare, Bare,
Pipe, Pipe,

View file

@ -4,6 +4,7 @@ use std::str::FromStr;
use crate::parser::ast::*; use crate::parser::ast::*;
use crate::prelude::*; use crate::prelude::*;
use crate::parser::lexer::{SpannedToken, Token}; use crate::parser::lexer::{SpannedToken, Token};
use byte_unit::Byte;
grammar<'input>; grammar<'input>;
@ -21,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(<>)),
//<Size> => Expression::Leaf(Leaf::Int(<>)), <UnitsNum> => Expression::Leaf(Leaf::Int(<>)),
<Variable> => Expression::VariableReference(<>), <Variable> => Expression::VariableReference(<>),
} }
@ -100,6 +101,10 @@ Int: i64 = {
<"num"> => i64::from_str(<>.as_slice()).unwrap() <"num"> => i64::from_str(<>.as_slice()).unwrap()
} }
UnitsNum: i64 = {
<"unitsnum"> => Byte::from_string(<>.as_slice()).unwrap().get_bytes() as i64
}
extern { extern {
type Location = usize; type Location = usize;
type Error = ShellError; type Error = ShellError;
@ -126,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, .. },
"size" => SpannedToken { token: Token::Size, .. }, "unitsnum" => SpannedToken { token: Token::UnitsNum, .. },
} }
} }

File diff suppressed because it is too large Load diff