Browse Source

Merge pull request #2 from someguynamedmatt/remove-positions

Removed Position attributes from the Expr structs
pull/5/head
Jason Williams 6 years ago committed by GitHub
parent
commit
26db2be6a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/lib/syntax/ast/expr.rs
  2. 11
      src/lib/syntax/parser.rs
  3. 9
      tests/js/defineVar.js

9
src/lib/syntax/ast/expr.rs

@ -2,25 +2,18 @@ use std::collections::btree_map::BTreeMap;
use std::fmt::{Display, Formatter, Result}; use std::fmt::{Display, Formatter, Result};
use syntax::ast::constant::Const; use syntax::ast::constant::Const;
use syntax::ast::op::{BinOp, Operator, UnaryOp}; use syntax::ast::op::{BinOp, Operator, UnaryOp};
use syntax::ast::pos::Position;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Expr { pub struct Expr {
/// The expression definition /// The expression definition
pub def: ExprDef, pub def: ExprDef,
/// The starting position
pub start: Position,
/// The ending position
pub end: Position,
} }
impl Expr { impl Expr {
/// Create a new expression with a starting and ending position /// Create a new expression with a starting and ending position
pub fn new(def: ExprDef, start: Position, end: Position) -> Expr { pub fn new(def: ExprDef) -> Expr {
Expr { Expr {
def: def, def: def,
start: start,
end: end,
} }
} }
} }

11
src/lib/syntax/parser.rs

@ -5,16 +5,15 @@ 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) => {
{ {
Expr::new($def, try!($this.get_token($this.pos)).pos, try!($this.get_token($this.pos)).pos) Expr::new($def)
} }
}; };
($this:expr, $def:expr, $first:expr) => { ($this:expr, $def:expr, $first:expr) => {
Expr::new($def, $first.pos, try!($this.get_token($this.pos)).pos) Expr::new($def)
}; };
); );
@ -61,9 +60,7 @@ impl Parser {
// TODO: refactor this or the `mk!` perhaps? // TODO: refactor this or the `mk!` perhaps?
Ok( Ok(
Expr::new( Expr::new(
ExprDef::BlockExpr(exprs), ExprDef::BlockExpr(exprs)
Position::new(1, 1),
Position::new(1, 1)
) )
) )
} }
@ -130,7 +127,7 @@ impl Parser {
} }
} }
} }
Ok(Expr::new(ExprDef::VarDeclExpr(vars), Position::new(1, 16), Position::new(1, 16))) Ok(Expr::new(ExprDef::VarDeclExpr(vars)))
} }
Keyword::Return => Ok(mk!( Keyword::Return => Ok(mk!(
self, self,

9
tests/js/defineVar.js

@ -1,3 +1,6 @@
var a = 'Jason'; var b = 'Jason';
var b = 'boa'; if(1===1){
console.log(a, b); b = 'another name';
}
console.log(b);

Loading…
Cancel
Save