grammar: Remove Ignore expression to avoid parsing ambiguity :'(

This commit is contained in:
John 2023-10-26 14:36:55 -05:00
parent b1f90ca4e9
commit 0445598ae8
4 changed files with 7 additions and 20 deletions

View File

@ -15,14 +15,13 @@ Fn = "fn" Identifier Block ; (* TODO: params, return value*)
(* # Expressions *) (* # Expressions *)
(* expression *) (* expression *)
Expr = Ignore ; Expr = Assign ;
Block = '{' Expr '}' ; Block = '{' Expr '}' ;
Group = '(' Expr? ')' ; Group = '(' Expr? ')' ;
Primary = Item | Identifier | Literal Primary = Item | Identifier | Literal
| Block | Group | Branch ; | Block | Group | Branch ;
(* expression::math *) (* expression::math *)
Ignore = Assign (IgnoreOp Assign )* ;
Assign = Compare (AssignOp Compare)* ; Assign = Compare (AssignOp Compare)* ;
Compare = Range (CompareOp Range )* ; Compare = Range (CompareOp Range )* ;
Range = Logic (RangeOp Logic )* ; Range = Logic (RangeOp Logic )* ;
@ -34,7 +33,6 @@ Factor = Unary (FactorOp Unary )* ;
Unary = (UnaryOp)* Primary ; Unary = (UnaryOp)* Primary ;
(* expression::math::operator *) (* expression::math::operator *)
IgnoreOp = ';' ;
AssignOp = '=' | "+=" | "-=" | "*=" | "/=" | AssignOp = '=' | "+=" | "-=" | "*=" | "/=" |
"&=" | "|=" | "^=" |"<<=" |">>=" ; "&=" | "|=" | "^=" |"<<=" |">>=" ;
CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' ; CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' ;

View File

@ -270,18 +270,16 @@ pub mod expression {
r" | 8 | Assign |", r"`*=`, `/=`, `%=`, `+=`, `-=`, ",//| r" | 8 | Assign |", r"`*=`, `/=`, `%=`, `+=`, `-=`, ",//|
/* | | |*/ r"`&=`, <code>&#124;=</code>, ", //| /* | | |*/ r"`&=`, <code>&#124;=</code>, ", //|
/* | | |*/ r"`^=`, `<<=`, `>>=`", r"| Right to Left")] /* | | |*/ r"`^=`, `<<=`, `>>=`", r"| Right to Left")]
//! | 9 | Ignore | `;` |
//! //!
//! <!-- Note: '&#124;' == '|' /--> //! <!-- Note: '&#124;' == '|' /-->
//! //!
//! ## Syntax //! ## Syntax
//! ```ignore //! ```ignore
//! /* All precedence levels other than Unary fold into Binary */ //! /* All precedence levels other than Unary fold into Binary */
//! Ignore := Assign (CompareOp Assign )* //! Assign := Compare (AssignOp Compare)*
//! Assign := Compare (IgnoreOp Compare)* //! Compare := Logic (CompareOp Logic )*
//! Compare := Logic (AssignOp Logic )*
//! Logic := Bitwise (LogicOp Bitwise)* //! Logic := Bitwise (LogicOp Bitwise)*
//! Bitwise := Shift (BitOp Shift )* //! Bitwise := Shift (BitwiseOp Shift )*
//! Shift := Term (ShiftOp Term )* //! Shift := Term (ShiftOp Term )*
//! Term := Factor (TermOp Factor )* //! Term := Factor (TermOp Factor )*
//! Factor := Unary (FactorOp Unary )* //! Factor := Unary (FactorOp Unary )*
@ -324,7 +322,7 @@ pub mod expression {
r"| 7 |", r"`*=`, `/=`, `%=`, `+=`, `-=`, ",//| r"| 7 |", r"`*=`, `/=`, `%=`, `+=`, `-=`, ",//|
/* | |*/ r"`&=`, <code>&#124;=</code>, ", //| /* | |*/ r"`&=`, <code>&#124;=</code>, ", //|
/* | |*/ r"`^=`, `<<=`, `>>=`, `=`", r"| Left to Right")] /* | |*/ r"`^=`, `<<=`, `>>=`, `=`", r"| Left to Right")]
//! | 8 | `;` | //! | 8 | `,` |
/// Operators which take a single argument /// Operators which take a single argument
/// ///
@ -430,9 +428,6 @@ pub mod expression {
ShlAssign, ShlAssign,
/// `>>=`: Right Shift In-place Assignment /// `>>=`: Right Shift In-place Assignment
ShrAssign, ShrAssign,
// Ignorance operators
/// `;`: Ignore
Ignore,
} }
} }
} }

View File

@ -341,7 +341,7 @@ impl Parser {
impl Parser { impl Parser {
fn expr(&mut self) -> PResult<expression::Expr> { fn expr(&mut self) -> PResult<expression::Expr> {
use expression::Expr; use expression::Expr;
Ok(Expr { ignore: self.ignore()? }) Ok(Expr { ignore: self.assign()? })
} }
fn block(&mut self) -> PResult<expression::Block> { fn block(&mut self) -> PResult<expression::Block> {
self.delimited(Type::LCurly, |p| p.expr(), Type::RCurly) self.delimited(Type::LCurly, |p| p.expr(), Type::RCurly)
@ -409,7 +409,6 @@ macro binary ($($f:ident = $a:ident, $b:ident);*$(;)?) {$(
impl Parser { impl Parser {
binary! { binary! {
// name operands operators // name operands operators
ignore = assign, ignore_op;
assign = compare, assign_op; assign = compare, assign_op;
compare = range, compare_op; compare = range, compare_op;
range = logic, range_op; range = logic, range_op;
@ -491,10 +490,6 @@ impl Parser {
Type::LtLtEq => ShlAssign, Type::LtLtEq => ShlAssign,
Type::GtGtEq => ShrAssign, Type::GtGtEq => ShrAssign,
} }
ignore_op: {
Type::Semi => Ignore,
}
} }
/// Parse a [unary operator](operator::Unary) /// Parse a [unary operator](operator::Unary)
fn unary_op(&mut self) -> PResult<operator::Unary> { fn unary_op(&mut self) -> PResult<operator::Unary> {

View File

@ -147,7 +147,6 @@ impl<W: Write> Visitor<IOResult<()>> for Printer<W> {
Binary::BitXorAssign => "^=", Binary::BitXorAssign => "^=",
Binary::ShlAssign => "<<=", Binary::ShlAssign => "<<=",
Binary::ShrAssign => ">>=", Binary::ShrAssign => ">>=",
Binary::Ignore => ";",
}) })
} }
fn visit_unary_op(&mut self, op: &operator::Unary) -> IOResult<()> { fn visit_unary_op(&mut self, op: &operator::Unary) -> IOResult<()> {