diff options
Diffstat (limited to 'src/frontend/lex.rs')
-rw-r--r-- | src/frontend/lex.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/frontend/lex.rs b/src/frontend/lex.rs index 771ba38..0d9fd22 100644 --- a/src/frontend/lex.rs +++ b/src/frontend/lex.rs @@ -60,7 +60,7 @@ pub enum Keyword { If, When, Elif, Else, Match, Try, Catch, Finally, Struct, Tuple, Enum, Union, Interface, - Distinct, Ref, // todo: Mut once figured out + Distinct, Ref, Ptr, Mut, Break, Continue, Return, In, Is, Of, As, } @@ -293,6 +293,8 @@ pub fn tokenize(input: &str) -> Result<TokenStream> { "interface" => res.push(Key(Interface)), "distinct" => res.push(Key(Distinct)), "ref" => res.push(Key(Ref)), + "ptr" => res.push(Key(Ptr)), + "mut" => res.push(Key(Mut)), "break" => res.push(Key(Break)), "continue" => res.push(Key(Continue)), "return" => res.push(Key(Return)), @@ -347,14 +349,14 @@ pub fn tokenize(input: &str) -> Result<TokenStream> { res.push(Sep(ArrayLeftBracket)); state.bracket_stack.push(Bracket::Array); }, - ')' => { + ')' => { // match parens match state.paren_stack.pop() { Some(Paren::Func) => res.push(Sep(FuncRightParen)), Some(Paren::Tuple) => res.push(Sep(TupleRightParen)), None => return Err(MismatchedParens.into()), } }, - ']' => { + ']' => { // match brackets match state.bracket_stack.pop() { Some(Bracket::Generic) => res.push(Sep(GenericRightBracket)), Some(Bracket::Array) => res.push(Sep(ArrayRightBracket)), @@ -366,8 +368,8 @@ pub fn tokenize(input: &str) -> Result<TokenStream> { input.next(); } }, - '`' => { - res.push(Sep(BackTick)); + '`' => { // backticks are used for operators, so generics/parameters may follow + res.push(Sep(BackTick)); // todo: backticks could like not be used for operators match input.peek() { Some('(') => { res.push(Sep(FuncLeftParen)); @@ -488,6 +490,8 @@ impl std::fmt::Display for Keyword { Interface => write!(f, "interface"), Distinct => write!(f, "distinct"), Ref => write!(f, "ref"), + Ptr => write!(f, "ptr"), + Mut => write!(f, "mut"), Break => write!(f, "break"), Continue => write!(f, "continue"), Return => write!(f, "return"), @@ -498,6 +502,7 @@ impl std::fmt::Display for Keyword { } } } + impl std::fmt::Display for Punctuation { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use Punctuation::*; |