From 61ab26e5b0fd4837504bf7142612f46d6aefd6a5 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 10 Jun 2019 22:21:36 +0100 Subject: [PATCH] all punctuator symbols supported and tested --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib/syntax/ast/punc.rs | 8 ++- src/lib/syntax/lexer.rs | 108 +++++++++++++++++++++++++++++++++++-- 4 files changed, 114 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0409223f5a..f297a62b50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "Boa" -version = "0.1.8" +version = "0.1.9" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "gc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index b236caa0e4..2759efba5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "Boa" -version = "0.1.8" +version = "0.1.9" authors = ["Jason Williams "] description = "Boa is a Javascript lexer, parser and Just-in-Time compiler written in Rust. Currently, it has support for some of the language." homepage = "https://github.com/jasonwilliams/boa" diff --git a/src/lib/syntax/ast/punc.rs b/src/lib/syntax/ast/punc.rs index 3efdc94af5..83f901d629 100644 --- a/src/lib/syntax/ast/punc.rs +++ b/src/lib/syntax/ast/punc.rs @@ -24,7 +24,9 @@ pub enum Punctuator { AssignMul, /// `|=` AssignOr, - /// `>>>=` + /// `**=` + AssignPow, + /// `>>=` AssignRightSh, /// `-=` AssignSub, @@ -84,6 +86,8 @@ pub enum Punctuator { OpenParen, /// `|` Or, + /// `**` + Pow, /// `?` Question, /// `>>` @@ -120,6 +124,7 @@ impl Display for Punctuator { Punctuator::AssignMod => "%=", Punctuator::AssignMul => "*=", Punctuator::AssignOr => "|=", + Punctuator::AssignPow => "**=", Punctuator::AssignRightSh => ">>=", Punctuator::AssignSub => "-=", Punctuator::AssignURightSh => ">>>=", @@ -150,6 +155,7 @@ impl Display for Punctuator { Punctuator::OpenBracket => "[", Punctuator::OpenParen => "(", Punctuator::Or => "|", + Punctuator::Pow => "**", Punctuator::Question => "?", Punctuator::RightSh => ">>", Punctuator::Semicolon => ";", diff --git a/src/lib/syntax/lexer.rs b/src/lib/syntax/lexer.rs index d461473702..155380a911 100644 --- a/src/lib/syntax/lexer.rs +++ b/src/lib/syntax/lexer.rs @@ -496,7 +496,9 @@ impl<'a> Lexer<'a> { }; self.push_token(token) } - '*' => op!(self, Punctuator::AssignMul, Punctuator::Mul), + '*' => op!(self, Punctuator::AssignMul, Punctuator::Mul, { + '*' => vop!(self, Punctuator::AssignPow, Punctuator::Pow) + }), '+' => op!(self, Punctuator::AssignAdd, Punctuator::Add, { '+' => Punctuator::Inc }), @@ -576,11 +578,10 @@ mod tests { #[test] fn check_punctuators() { - // TODO: Support ** ++ // https://tc39.es/ecma262/#sec-punctuators let s = "{ ( ) [ ] . ... ; , < > <= >= == != === !== \ + - * % -- << >> >>> & | ^ ! ~ && || ? : \ - = += -= *= &= **= <<= >>= >>>= &= |= ^= =>"; + = += -= *= &= **= ++ ** <<= >>= >>>= &= |= ^= =>"; let mut lexer = Lexer::new(s); lexer.lex().unwrap(); assert_eq!( @@ -669,6 +670,107 @@ mod tests { lexer.tokens[22].data, TokenData::Punctuator(Punctuator::LeftSh) ); + assert_eq!( + lexer.tokens[23].data, + TokenData::Punctuator(Punctuator::RightSh) + ); + assert_eq!( + lexer.tokens[24].data, + TokenData::Punctuator(Punctuator::URightSh) + ); + assert_eq!( + lexer.tokens[25].data, + TokenData::Punctuator(Punctuator::And) + ); + assert_eq!(lexer.tokens[26].data, TokenData::Punctuator(Punctuator::Or)); + assert_eq!( + lexer.tokens[27].data, + TokenData::Punctuator(Punctuator::Xor) + ); + assert_eq!( + lexer.tokens[28].data, + TokenData::Punctuator(Punctuator::Not) + ); + assert_eq!( + lexer.tokens[29].data, + TokenData::Punctuator(Punctuator::Neg) + ); + assert_eq!( + lexer.tokens[30].data, + TokenData::Punctuator(Punctuator::BoolAnd) + ); + assert_eq!( + lexer.tokens[31].data, + TokenData::Punctuator(Punctuator::BoolOr) + ); + assert_eq!( + lexer.tokens[32].data, + TokenData::Punctuator(Punctuator::Question) + ); + assert_eq!( + lexer.tokens[33].data, + TokenData::Punctuator(Punctuator::Colon) + ); + assert_eq!( + lexer.tokens[34].data, + TokenData::Punctuator(Punctuator::Assign) + ); + assert_eq!( + lexer.tokens[35].data, + TokenData::Punctuator(Punctuator::AssignAdd) + ); + assert_eq!( + lexer.tokens[36].data, + TokenData::Punctuator(Punctuator::AssignSub) + ); + assert_eq!( + lexer.tokens[37].data, + TokenData::Punctuator(Punctuator::AssignMul) + ); + assert_eq!( + lexer.tokens[38].data, + TokenData::Punctuator(Punctuator::AssignAnd) + ); + assert_eq!( + lexer.tokens[39].data, + TokenData::Punctuator(Punctuator::AssignPow) + ); + assert_eq!( + lexer.tokens[40].data, + TokenData::Punctuator(Punctuator::Inc) + ); + assert_eq!( + lexer.tokens[41].data, + TokenData::Punctuator(Punctuator::Pow) + ); + assert_eq!( + lexer.tokens[42].data, + TokenData::Punctuator(Punctuator::AssignLeftSh) + ); + assert_eq!( + lexer.tokens[43].data, + TokenData::Punctuator(Punctuator::AssignRightSh) + ); + assert_eq!( + lexer.tokens[44].data, + TokenData::Punctuator(Punctuator::AssignURightSh) + ); + assert_eq!( + lexer.tokens[45].data, + TokenData::Punctuator(Punctuator::AssignAnd) + ); + assert_eq!( + lexer.tokens[46].data, + TokenData::Punctuator(Punctuator::AssignOr) + ); + assert_eq!( + lexer.tokens[47].data, + TokenData::Punctuator(Punctuator::AssignXor) + ); + assert_eq!( + lexer.tokens[48].data, + TokenData::Punctuator(Punctuator::Arrow) + ); } #[test]