diff --git a/rust_parser.html b/rust_parser.html index 64088c0..11f98e4 100644 --- a/rust_parser.html +++ b/rust_parser.html @@ -105,7 +105,7 @@

Lexing

Num(u64), }

I could have used more enum values to distinguish between + and * and the different types of parentheses, but instead I just store the character. It probably would have been a good idea to add another integer to each LexItem that stores the location in the input at which the token starts. That would make error reporting more useful. Instead I will just use the position in the token stream for my errors. Since I’m the only user of this program, I will only be angry at myself, so it’s okay.

-

The language I want to parse is very simple to lex. Except numbers, all tokens are just a single character long. So instead of complicated things with regular expressions. Instead I iterate over the characters of my input String and use a match do create a LexItem. The match statement is really handy here, since I can specify multiple alternatives for the same case with | and ranges of characters are also supported.

+

The language I want to parse is very simple to lex. Except numbers, all tokens are just a single character long. So instead of doing complicated things with regular expressions, I iterate over the characters of my input String and use a match do create a LexItem. The match statement is really handy here, since I can specify multiple alternatives for the same case with | and ranges of characters are also supported.

fn lex(input: &String) -> Result<Vec<LexItem>, String> {
     let mut result = Vec::new();