Skip to content

Commit

Permalink
More lexing possibilities #52
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed Jun 4, 2018
1 parent f945ff2 commit 73bcf82
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/mango/lexing/code_lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use mango::lexing::string_lexer::StringLexer;
use mango::lexing::typ::Lexer;
use mango::lexing::typ::MaybeToken;
use mango::token::special::UnlexableToken;
use mango::token::tokens::AssociationToken;
use mango::token::tokens::EndBlockToken;
use mango::token::tokens::EndStatementToken;
use mango::token::tokens::IdentifierToken;
Expand Down Expand Up @@ -155,6 +156,19 @@ impl Lexer for CodeLexer {
self.reader_or_delegate = ReaderOrDelegate::Delegate(sublexer);
return self.lex();
}
// Association (before operator)
let association_match_res = self
.reader
.borrow_mut()
.matches(&AssociationToken::subpattern());
if let Match(token) = association_match_res {
if token.chars().last().unwrap() == '=' {
// return Token(Tokens::Association(AssociationToken::from_str(token[..1]).unwrap()));
return Token(Tokens::Association(AssociationToken::from_unprefixed())); // TODO
} else {
return Token(Tokens::Association(AssociationToken::from_unprefixed()));
}
}
// Operator
let operator_match_res = self
.reader
Expand All @@ -163,8 +177,6 @@ impl Lexer for CodeLexer {
if let Match(token) = operator_match_res {
return Token(Tokens::Operator(OperatorToken::from_str(&token).unwrap()));
}
// Association
// todo
// Grouping symbols
if let Match(_) = self.reader.borrow_mut().matches("(") {
return Token(Tokens::ParenthesisOpen(ParenthesisOpenToken::new()));
Expand Down
2 changes: 1 addition & 1 deletion src/mango/token/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_tokens_eq() {
Keyword(KeywordToken::from_str("let").unwrap()),
Keyword(KeywordToken::from_str("mut").unwrap()),
Identifier(IdentifierToken::from_name(my_var)),
Association(AssociationToken::from_unmutated()),
Association(AssociationToken::from_unprefixed()),
Literal(LiteralToken::int(21)),
EndStatement(EndStatementToken::new_semicolon()),
Identifier(IdentifierToken::from_name(my_var)),
Expand Down
6 changes: 5 additions & 1 deletion src/mango/token/tokens/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct AssociationToken {
}

impl AssociationToken {
pub fn from_unmutated() -> Self {
pub fn from_unprefixed() -> Self {
AssociationToken {
symbol: Option::None,
}
Expand All @@ -26,6 +26,10 @@ impl AssociationToken {
symbol: Option::Some(symbol),
}
}

pub fn subpattern() -> String {
format!("{}=", Symbol::subpattern())
}
}

impl ToText for AssociationToken {
Expand Down
2 changes: 1 addition & 1 deletion src/mango/util/strslice/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn charslice<S: Into<String>>(text: S, start: isize, end: isize) -> String {
let new_end = (charcount as isize + end) as usize;
assert!(
new_end >= from,
"charslice: 'start' may not be before 'end' (end was positive)"
"charslice: 'start' may not be before 'end' (end was negative)"
);
length = new_end - from;
} else {
Expand Down

0 comments on commit 73bcf82

Please sign in to comment.