Skip to content

Commit

Permalink
Add operator lexing #52
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed Jun 1, 2018
1 parent 0be80eb commit d3a555b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/mango/lexing/code_lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use mango::token::tokens::EndBlockToken;
use mango::token::tokens::EndStatementToken;
use mango::token::tokens::IdentifierToken;
use mango::token::tokens::KeywordToken;
use mango::token::tokens::OperatorToken;
use mango::token::tokens::ParenthesisCloseToken;
use mango::token::tokens::ParenthesisOpenToken;
use mango::token::tokens::StartBlockToken;
Expand Down Expand Up @@ -134,7 +135,7 @@ impl Lexer for CodeLexer {
//
// Indentation done; do the rest of lexing.
//
// Parse identifers and keywords. This assumes that keywords are a subset of identifiers.
// Parse identifiers and keywords. This assumes that keywords are a subset of identifiers.
if let Match(word) = self
.reader
.borrow_mut()
Expand All @@ -155,7 +156,13 @@ impl Lexer for CodeLexer {
return self.lex();
}
// Operator
// todo
let operator_match_res = self
.reader
.borrow_mut()
.matches(OperatorToken::subpattern());
if let Match(token) = operator_match_res {
return Token(Tokens::Operator(OperatorToken::from_str(&token).unwrap()));
}
// Association
// todo
// Grouping symbols
Expand Down
4 changes: 4 additions & 0 deletions src/mango/token/tokens/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl OperatorToken {
pub fn is_mult_div(&self) -> bool {
self.symbol == Symbol::Asterisk || self.symbol == Symbol::Slash
}

pub fn subpattern() -> &'static str {
Symbol::subpattern()
}
}

impl ToText for OperatorToken {
Expand Down
5 changes: 5 additions & 0 deletions src/mango/util/codeparts/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl Symbol {
))),
}
}

/// Generate an eager subpattern to match tokens, that can be composed in a regular expression.
pub fn subpattern() -> &'static str {
r"(\+|\-|\*|\/)"
}
}

impl Display for Symbol {
Expand Down

0 comments on commit d3a555b

Please sign in to comment.