Browse Source

all punctuator symbols supported and tested

pull/27/head
Jason Williams 6 years ago
parent
commit
61ab26e5b0
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 8
      src/lib/syntax/ast/punc.rs
  4. 108
      src/lib/syntax/lexer.rs

2
Cargo.lock generated

@ -2,7 +2,7 @@
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "Boa" name = "Boa"
version = "0.1.8" version = "0.1.9"
dependencies = [ dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "gc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",

2
Cargo.toml

@ -1,6 +1,6 @@
[package] [package]
name = "Boa" name = "Boa"
version = "0.1.8" version = "0.1.9"
authors = ["Jason Williams <jase.williams@gmail.com>"] authors = ["Jason Williams <jase.williams@gmail.com>"]
description = "Boa is a Javascript lexer, parser and Just-in-Time compiler written in Rust. Currently, it has support for some of the language." 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" homepage = "https://github.com/jasonwilliams/boa"

8
src/lib/syntax/ast/punc.rs

@ -24,7 +24,9 @@ pub enum Punctuator {
AssignMul, AssignMul,
/// `|=` /// `|=`
AssignOr, AssignOr,
/// `>>>=` /// `**=`
AssignPow,
/// `>>=`
AssignRightSh, AssignRightSh,
/// `-=` /// `-=`
AssignSub, AssignSub,
@ -84,6 +86,8 @@ pub enum Punctuator {
OpenParen, OpenParen,
/// `|` /// `|`
Or, Or,
/// `**`
Pow,
/// `?` /// `?`
Question, Question,
/// `>>` /// `>>`
@ -120,6 +124,7 @@ impl Display for Punctuator {
Punctuator::AssignMod => "%=", Punctuator::AssignMod => "%=",
Punctuator::AssignMul => "*=", Punctuator::AssignMul => "*=",
Punctuator::AssignOr => "|=", Punctuator::AssignOr => "|=",
Punctuator::AssignPow => "**=",
Punctuator::AssignRightSh => ">>=", Punctuator::AssignRightSh => ">>=",
Punctuator::AssignSub => "-=", Punctuator::AssignSub => "-=",
Punctuator::AssignURightSh => ">>>=", Punctuator::AssignURightSh => ">>>=",
@ -150,6 +155,7 @@ impl Display for Punctuator {
Punctuator::OpenBracket => "[", Punctuator::OpenBracket => "[",
Punctuator::OpenParen => "(", Punctuator::OpenParen => "(",
Punctuator::Or => "|", Punctuator::Or => "|",
Punctuator::Pow => "**",
Punctuator::Question => "?", Punctuator::Question => "?",
Punctuator::RightSh => ">>", Punctuator::RightSh => ">>",
Punctuator::Semicolon => ";", Punctuator::Semicolon => ";",

108
src/lib/syntax/lexer.rs

@ -496,7 +496,9 @@ impl<'a> Lexer<'a> {
}; };
self.push_token(token) 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, { '+' => op!(self, Punctuator::AssignAdd, Punctuator::Add, {
'+' => Punctuator::Inc '+' => Punctuator::Inc
}), }),
@ -576,11 +578,10 @@ mod tests {
#[test] #[test]
fn check_punctuators() { fn check_punctuators() {
// TODO: Support ** ++
// https://tc39.es/ecma262/#sec-punctuators // https://tc39.es/ecma262/#sec-punctuators
let s = "{ ( ) [ ] . ... ; , < > <= >= == != === !== \ let s = "{ ( ) [ ] . ... ; , < > <= >= == != === !== \
+ - * % -- << >> >>> & | ^ ! ~ && || ? : \ + - * % -- << >> >>> & | ^ ! ~ && || ? : \
= += -= *= &= **= <<= >>= >>>= &= |= ^= =>"; = += -= *= &= **= ++ ** <<= >>= >>>= &= |= ^= =>";
let mut lexer = Lexer::new(s); let mut lexer = Lexer::new(s);
lexer.lex().unwrap(); lexer.lex().unwrap();
assert_eq!( assert_eq!(
@ -669,6 +670,107 @@ mod tests {
lexer.tokens[22].data, lexer.tokens[22].data,
TokenData::Punctuator(Punctuator::LeftSh) 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] #[test]

Loading…
Cancel
Save