Skip to content

Commit

Permalink
Fairly complex regular expressions for ints and floats #52
Browse files Browse the repository at this point in the history
  • Loading branch information
mverleg committed Jun 17, 2018
1 parent 10650d5 commit 4346a4f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/mango/token/tokens/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ impl LiteralToken {
LiteralToken::Real(f64eq::new(value))
}

/// This matches integer literals, either just numbers in base 10, or base 2-36 with prefix.
/// The syntax for -37 in base 16 is -16b25 and 2748 is 16bABC.
/// Incorrect values like 4b7 or 0b0 are not handled at the lexing stage.
pub fn subpattern_int() -> &'static str {
"[a-z]?\""
r"(?:\+|-*)(?:[1-9][0-9]*b(?:_?[0-9a-zA-Z])+|[0-9](?:_?[0-9])*)"
}

/// This matches real literals (base 10), which look like this:
/// sign / int1 / period / int2 / e / sign / int
/// Here int is a series of 0-9 digits separated by at most one underscore.
/// Signs are optional, everything from 'e' is optional, and int1 OR int2 is optional.
pub fn subpattern_real() -> &'static str {
// TODO: do I want to allow numbers to start with a period?
// TODO: for now, only base10 for reals (would 8b11e2 be 9*8^2 or 9*10^2?)
r"(?:\+|-*)(?:\d(?:_?\d)*\.\d(?:_?\d)*|\d(?:_?\d)*\.|\.\d(?:_?\d)*)(?:e(?:\+|-|)\d(?:_?\d)*)?"
}
}

Expand Down

0 comments on commit 4346a4f

Please sign in to comment.