Browse Source

Merge pull request #1 from someguynamedmatt/parser-bug

Remove calls to the mk macro on final returns in parser.rs
pull/2/head
Jason Williams 6 years ago committed by GitHub
parent
commit
152b86c027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Cargo.lock
  2. 3
      src/bin/bin.rs
  3. 14
      src/lib/syntax/parser.rs
  4. 2
      tests/js/defineVar.js

2
Cargo.lock generated

@ -1,4 +1,4 @@
[[package]] [[package]]
name = "Boa" name = "Boa"
version = "0.1.2" version = "0.1.3"

3
src/bin/bin.rs

@ -5,7 +5,8 @@ use std::fs::read_to_string;
pub fn main() { pub fn main() {
let buffer = read_to_string("tests/js/defineVar.js").unwrap(); let buffer = read_to_string("tests/js/defineVar.js").unwrap();
let lexer = Lexer::new(&buffer); let mut lexer = Lexer::new(&buffer);
lexer.lex().unwrap();
let tokens = lexer.tokens; let tokens = lexer.tokens;
match Parser::new(tokens).parse_all() { match Parser::new(tokens).parse_all() {
Ok(e) => println!("{}", e), Ok(e) => println!("{}", e),

14
src/lib/syntax/parser.rs

@ -5,6 +5,7 @@ use syntax::ast::keyword::Keyword;
use syntax::ast::op::{BinOp, BitOp, CompOp, LogOp, NumOp, Operator, UnaryOp}; use syntax::ast::op::{BinOp, BitOp, CompOp, LogOp, NumOp, Operator, UnaryOp};
use syntax::ast::punc::Punctuator; use syntax::ast::punc::Punctuator;
use syntax::ast::token::{Token, TokenData}; use syntax::ast::token::{Token, TokenData};
use syntax::ast::pos::Position;
macro_rules! mk ( macro_rules! mk (
($this:expr, $def:expr) => { ($this:expr, $def:expr) => {
@ -55,7 +56,16 @@ impl Parser {
let result = try!(self.parse()); let result = try!(self.parse());
exprs.push(result); exprs.push(result);
} }
Ok(mk!(self, ExprDef::BlockExpr(exprs)))
// In the case of `BlockExpr` the Positions seem unnecessary
// TODO: refactor this or the `mk!` perhaps?
Ok(
Expr::new(
ExprDef::BlockExpr(exprs),
Position::new(1, 1),
Position::new(1, 1)
)
)
} }
fn get_token(&self, pos: usize) -> Result<Token, ParseError> { fn get_token(&self, pos: usize) -> Result<Token, ParseError> {
@ -120,7 +130,7 @@ impl Parser {
} }
} }
} }
Ok(mk!(self, ExprDef::VarDeclExpr(vars))) Ok(Expr::new(ExprDef::VarDeclExpr(vars), Position::new(1, 16), Position::new(1, 16)))
} }
Keyword::Return => Ok(mk!( Keyword::Return => Ok(mk!(
self, self,

2
tests/js/defineVar.js

@ -1 +1,3 @@
var a = 'Jason'; var a = 'Jason';
var b = 'boa';
console.log(a, b);

Loading…
Cancel
Save