Huff Lexer
Lexical analyzer for the Huff Language.
The Huff Lexer is instantiable with a string representing the source code.
Once instantiated, the lexer can be used to iterate over the tokens in the source code. It also exposes a number of practical methods for accessing information about the source code throughout lexing.
Usage
The following example steps through the lexing of a simple, single-line source code macro definition.
use ;
use ;
// Instantiate a new lexer
let source = "#define macro HELLO_WORLD()";
let mut lexer = new;
assert_eq!;
// This token should be a Define identifier
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// The next token should be the whitespace
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// Then we should parse the macro keyword
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// The next token should be another whitespace
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// Then we should get the function name
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// Then we should have an open paren
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// Lastly, we should have a closing parenthesis
let tok = lexer.next.unwrap.unwrap;
assert_eq!;
assert_eq!;
// We covered the whole source
assert_eq!;
assert!;