From a5a9d00278078f3529cfa36106296bc98a1de929 Mon Sep 17 00:00:00 2001 From: croraf Date: Thu, 8 Oct 2020 17:43:01 +0200 Subject: [PATCH 1/3] [parser Expression] minor expression macro simplification --- boa/src/syntax/parser/expression/mod.rs | 37 +++++++++---------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/boa/src/syntax/parser/expression/mod.rs b/boa/src/syntax/parser/expression/mod.rs index fe9060854e8..232e36e68a6 100644 --- a/boa/src/syntax/parser/expression/mod.rs +++ b/boa/src/syntax/parser/expression/mod.rs @@ -54,7 +54,7 @@ impl PartialEq for Keyword { /// Those exressions are divided by the punctuators passed as the third parameter. /// /// The fifth parameter is an Option which sets the goal symbol to set before parsing (or None to leave it as is). -macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $low_param:ident ),*], $goal:expr, $profile:expr ) => { +macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $low_param:ident ),*], $goal:expr ) => { impl TokenParser for $name where R: Read @@ -62,7 +62,7 @@ macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $lo type Output = Node; fn parse(self, cursor: &mut Cursor)-> ParseResult { - let _timer = BoaProfiler::global().start_event($profile, "Parsing"); + let _timer = BoaProfiler::global().start_event(stringify!($name), "Parsing"); if $goal.is_some() { cursor.set_goal($goal.unwrap()); @@ -132,8 +132,7 @@ expression!( AssignmentExpression, [Punctuator::Comma], [allow_in, allow_yield, allow_await], - None::, - "Expression" + None:: ); /// Parses a logical `OR` expression. @@ -172,8 +171,7 @@ expression!( LogicalANDExpression, [Punctuator::BoolOr], [allow_in, allow_yield, allow_await], - None::, - "LogicalOrExpression" + None:: ); /// Parses a logical `AND` expression. @@ -212,8 +210,7 @@ expression!( BitwiseORExpression, [Punctuator::BoolAnd], [allow_in, allow_yield, allow_await], - None::, - "LogicalANDExpression" + None:: ); /// Parses a bitwise `OR` expression. @@ -252,8 +249,7 @@ expression!( BitwiseXORExpression, [Punctuator::Or], [allow_in, allow_yield, allow_await], - None::, - "BitwiseORExpression" + None:: ); /// Parses a bitwise `XOR` expression. @@ -292,8 +288,7 @@ expression!( BitwiseANDExpression, [Punctuator::Xor], [allow_in, allow_yield, allow_await], - None::, - "BitwiseXORExpression" + None:: ); /// Parses a bitwise `AND` expression. @@ -332,8 +327,7 @@ expression!( EqualityExpression, [Punctuator::And], [allow_in, allow_yield, allow_await], - None::, - "BitwiseANDExpression" + None:: ); /// Parses an equality expression. @@ -377,8 +371,7 @@ expression!( Punctuator::StrictNotEq ], [allow_in, allow_yield, allow_await], - None::, - "EqualityExpression" + None:: ); /// Parses a relational expression. @@ -424,8 +417,7 @@ expression!( Keyword::In ], [allow_yield, allow_await], - None::, - "RelationoalExpression" + None:: ); /// Parses a bitwise shift expression. @@ -465,8 +457,7 @@ expression!( Punctuator::URightSh ], [allow_yield, allow_await], - None::, - "ShiftExpression" + None:: ); /// Parses an additive expression. @@ -504,8 +495,7 @@ expression!( MultiplicativeExpression, [Punctuator::Add, Punctuator::Sub], [allow_yield, allow_await], - None::, - "AdditiveExpression" + None:: ); /// Parses a multiplicative expression. @@ -543,6 +533,5 @@ expression!( ExponentiationExpression, [Punctuator::Mul, Punctuator::Div, Punctuator::Mod], [allow_yield, allow_await], - Some(InputElement::Div), - "MultiplicativeExpression" + Some(InputElement::Div) ); From 695595e1c9c5d207ceb49fd46735a9534d3512d6 Mon Sep 17 00:00:00 2001 From: croraf Date: Thu, 8 Oct 2020 19:00:33 +0200 Subject: [PATCH 2/3] Slightly improve the macro comment --- boa/src/syntax/parser/expression/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/boa/src/syntax/parser/expression/mod.rs b/boa/src/syntax/parser/expression/mod.rs index 232e36e68a6..1bb9f376736 100644 --- a/boa/src/syntax/parser/expression/mod.rs +++ b/boa/src/syntax/parser/expression/mod.rs @@ -45,13 +45,18 @@ impl PartialEq for Keyword { } } -/// Generates an expression parser. +/// Generates an expression parser for a number of expressions whose production rules are of the following pattern. +/// [allowed_identifiers] +/// => [?allowed_identifiers] +/// => [?allowed_identifiers] [?allowed_identifiers] +/// => [?allowed_identifiers] [?allowed_identifiers] +/// ... /// /// This macro has 2 mandatory identifiers: -/// - The `$name` identifier will contain the name of the parsing structure. -/// - The `$lower` identifier will contain the parser for lower level expressions. +/// - The `$name` identifier will contain the name of the TargetExpression. +/// - The `$lower` identifier will contain the parser for the InnerExpression. /// -/// Those exressions are divided by the punctuators passed as the third parameter. +/// A list of punctuators (operands between the and ) are passed as the third parameter. /// /// The fifth parameter is an Option which sets the goal symbol to set before parsing (or None to leave it as is). macro_rules! expression { ($name:ident, $lower:ident, [$( $op:path ),*], [$( $low_param:ident ),*], $goal:expr ) => { From 9a6b0eef0f0b861b35a5b1b3307eb903068c4a10 Mon Sep 17 00:00:00 2001 From: croraf Date: Thu, 8 Oct 2020 19:12:57 +0200 Subject: [PATCH 3/3] Minor reword --- boa/src/syntax/parser/expression/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boa/src/syntax/parser/expression/mod.rs b/boa/src/syntax/parser/expression/mod.rs index 1bb9f376736..66ef2a99dec 100644 --- a/boa/src/syntax/parser/expression/mod.rs +++ b/boa/src/syntax/parser/expression/mod.rs @@ -53,8 +53,8 @@ impl PartialEq for Keyword { /// ... /// /// This macro has 2 mandatory identifiers: -/// - The `$name` identifier will contain the name of the TargetExpression. -/// - The `$lower` identifier will contain the parser for the InnerExpression. +/// - The `$name` identifier is the name of the TargetExpression struct that the parser will be implemented for. +/// - The `$lower` identifier is the name of the InnerExpression struct according to the pattern above. /// /// A list of punctuators (operands between the and ) are passed as the third parameter. ///