add support for ++ and +=
This commit is contained in:
parent
285f0b8410
commit
498ea72da4
1 changed files with 20 additions and 15 deletions
|
@ -229,6 +229,23 @@ pub const Scanner = struct {
|
|||
);
|
||||
}
|
||||
|
||||
fn makeTripleMatchToken(
|
||||
self: *Scanner,
|
||||
char1: u8,
|
||||
ttype1: TokenType,
|
||||
char2,
|
||||
ttype2: TokenType,
|
||||
fallback: TokenType,
|
||||
) Token {
|
||||
if (self.match(char1)) {
|
||||
return self.makeToken(ttype1);
|
||||
} else if (self.match(char2)) {
|
||||
return self.makeToken(ttype2);
|
||||
} else {
|
||||
return self.makeToken(fallback);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nextToken(self: *Scanner) !?Token {
|
||||
self.skipWhitespace();
|
||||
self.start = self.current;
|
||||
|
@ -255,26 +272,14 @@ pub const Scanner = struct {
|
|||
'$' => self.makeToken(.DollarSign),
|
||||
|
||||
'-' => self.makeToken(.Minus),
|
||||
'+' => self.makeToken(.Plus),
|
||||
'*' => self.makeToken(.Star),
|
||||
'%' => self.makeToken(.Modulo),
|
||||
|
||||
'!' => self.makeMatchToken('=', .BangEqual, .Bang),
|
||||
'=' => self.makeMatchToken('=', .EqualEqual, .Equal),
|
||||
|
||||
// there can be three tokens from a <
|
||||
// - <, which is LessThan
|
||||
// - <=, which is LessEqual
|
||||
// - <<, which is LeftDoubleChevron
|
||||
'<' => blk: {
|
||||
if (self.match('=')) {
|
||||
break :blk self.makeToken(.LessEqual);
|
||||
} else if (self.match('<')) {
|
||||
break :blk self.makeToken(.LeftDoubleChevron);
|
||||
} else {
|
||||
break :blk self.makeToken(.Less);
|
||||
}
|
||||
},
|
||||
'>' => self.makeMatchToken('=', .GreaterEqual, .Greater),
|
||||
'+' => self.makeTripleMatchToken('+', .PlusPlus, '=', .PlusEqual, .Plus),
|
||||
'<' => self.makeTripleMatchToken('=', .LessEqual, '<', .LeftDoubleChevron, .Less),
|
||||
|
||||
'/' => blk: {
|
||||
var next = self.peekNext();
|
||||
|
|
Loading…
Reference in a new issue