about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/treewalk/parser.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-02-07T16·29+0300
committerclbot <clbot@tvl.fyi>2022-02-07T16·58+0000
commit0d0b43ed8819e66a0888eb6d1d1f47b171ae62e0 (patch)
tree305c04d3fe26c92ed7037f0b0f41f38444ce83ea /users/tazjin/rlox/src/treewalk/parser.rs
parent8b8c98380e85b2057a3c35ce3d76879fab4266b0 (diff)
fix(users/tazjin): rustfmt code with non-default settings r/3776
rustfmt only sometimes detects path-based nested config
files (probably some kind of race?), so my users folder uses a
separate formatting check for rustfmt to avoid flaky CI. Enough flakes
around already ...

Change-Id: Ifd862f9974f071b3a256643dd8e56c019116156a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5242
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/treewalk/parser.rs')
-rw-r--r--users/tazjin/rlox/src/treewalk/parser.rs122
1 files changed, 53 insertions, 69 deletions
diff --git a/users/tazjin/rlox/src/treewalk/parser.rs b/users/tazjin/rlox/src/treewalk/parser.rs
index 003cc34b4665..5794b42d1577 100644
--- a/users/tazjin/rlox/src/treewalk/parser.rs
+++ b/users/tazjin/rlox/src/treewalk/parser.rs
@@ -124,56 +124,54 @@ pub enum Statement {
 
 // Parser
 
-/*
-program        → declaration* EOF ;
-
-declaration    → funDecl
-               | varDecl
-               | statement ;
-
-funDecl        → "fun" function ;
-function       → IDENTIFIER "(" parameters? ")" block ;
-parameters     → IDENTIFIER ( "," IDENTIFIER )* ;
-
-
-statement      → exprStmt
-               | forStmt
-               | ifStmt
-               | printStmt
-               | returnStmt
-               | whileStmt
-               | block ;
-
-forStmt        → "for" "(" ( varDecl | exprStmt | ";" )
-                 expression? ";"
-                 expression? ")" statement ;
-
-returnStmt     → "return" expression? ";" ;
-
-whileStmt      → "while" "(" expression ")" statement ;
-
-exprStmt       → expression ";" ;
-
-ifStmt         → "if" "(" expression ")" statement
-               ( "else" statement )? ;
-
-printStmt      → "print" expression ";" ;
-
-expression     → assignment ;
-assignment     → IDENTIFIER "=" assignment
-               | logic_or ;
-logic_or       → logic_and ( "or" logic_and )* ;
-logic_and      → equality ( "and" equality )* ;
-equality       → comparison ( ( "!=" | "==" ) comparison )* ;
-comparison     → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
-term           → factor ( ( "-" | "+" ) factor )* ;
-factor         → unary ( ( "/" | "*" ) unary )* ;
-unary          → ( "!" | "-" ) unary | call ;
-call           → primary ( "(" arguments? ")" )* ;
-arguments      → expression ( "," expression )* ;
-primary        → NUMBER | STRING | "true" | "false" | "nil"
-               | "(" expression ")" ;
-*/
+// program        → declaration* EOF ;
+//
+// declaration    → funDecl
+// | varDecl
+// | statement ;
+//
+// funDecl        → "fun" function ;
+// function       → IDENTIFIER "(" parameters? ")" block ;
+// parameters     → IDENTIFIER ( "," IDENTIFIER )* ;
+//
+//
+// statement      → exprStmt
+// | forStmt
+// | ifStmt
+// | printStmt
+// | returnStmt
+// | whileStmt
+// | block ;
+//
+// forStmt        → "for" "(" ( varDecl | exprStmt | ";" )
+// expression? ";"
+// expression? ")" statement ;
+//
+// returnStmt     → "return" expression? ";" ;
+//
+// whileStmt      → "while" "(" expression ")" statement ;
+//
+// exprStmt       → expression ";" ;
+//
+// ifStmt         → "if" "(" expression ")" statement
+// ( "else" statement )? ;
+//
+// printStmt      → "print" expression ";" ;
+//
+// expression     → assignment ;
+// assignment     → IDENTIFIER "=" assignment
+// | logic_or ;
+// logic_or       → logic_and ( "or" logic_and )* ;
+// logic_and      → equality ( "and" equality )* ;
+// equality       → comparison ( ( "!=" | "==" ) comparison )* ;
+// comparison     → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
+// term           → factor ( ( "-" | "+" ) factor )* ;
+// factor         → unary ( ( "/" | "*" ) unary )* ;
+// unary          → ( "!" | "-" ) unary | call ;
+// call           → primary ( "(" arguments? ")" )* ;
+// arguments      → expression ( "," expression )* ;
+// primary        → NUMBER | STRING | "true" | "false" | "nil"
+// | "(" expression ")" ;
 
 struct Parser {
     tokens: Vec<Token>,
@@ -213,9 +211,7 @@ impl Parser {
                 if params.len() >= 255 {
                     return Err(Error {
                         line: self.peek().line,
-                        kind: ErrorKind::InternalError(
-                            "255 parameter limit exceeded.".into(),
-                        ),
+                        kind: ErrorKind::InternalError("255 parameter limit exceeded.".into()),
                     });
                 }
 
@@ -429,10 +425,7 @@ impl Parser {
 
             return Err(Error {
                 line: equals.line,
-                kind: ErrorKind::InvalidAssignmentTarget(format!(
-                    "{:?}",
-                    equals
-                )),
+                kind: ErrorKind::InvalidAssignmentTarget(format!("{:?}", equals)),
             });
         }
 
@@ -495,9 +488,7 @@ impl Parser {
     }
 
     fn unary(&mut self) -> ExprResult {
-        if self.match_token(&TokenKind::Bang)
-            || self.match_token(&TokenKind::Minus)
-        {
+        if self.match_token(&TokenKind::Bang) || self.match_token(&TokenKind::Minus) {
             return Ok(Expr::Unary(Unary {
                 operator: self.previous().clone(),
                 right: Box::new(self.unary()?),
@@ -557,10 +548,7 @@ impl Parser {
 
             TokenKind::LeftParen => {
                 let expr = self.expression()?;
-                self.consume(
-                    &TokenKind::RightParen,
-                    ErrorKind::UnmatchedParens,
-                )?;
+                self.consume(&TokenKind::RightParen, ErrorKind::UnmatchedParens)?;
                 return Ok(Expr::Grouping(Grouping(Box::new(expr))));
             }
 
@@ -632,11 +620,7 @@ impl Parser {
         &self.tokens[self.current - 1]
     }
 
-    fn consume(
-        &mut self,
-        kind: &TokenKind,
-        err: ErrorKind,
-    ) -> Result<Token, Error> {
+    fn consume(&mut self, kind: &TokenKind, err: ErrorKind) -> Result<Token, Error> {
         if self.check_token(kind) {
             return Ok(self.advance());
         }