token.rs: Lex numbers of arbitrary length, for better errors
This commit is contained in:
parent
b3af047d3a
commit
8230d73495
@ -4,6 +4,7 @@
|
||||
//! A [Token] represents all valid sequences of characters,
|
||||
//! sorted by meaning
|
||||
|
||||
use crate::Error;
|
||||
use regex::Regex;
|
||||
use std::{
|
||||
fmt::{Debug, Display},
|
||||
@ -56,8 +57,6 @@ impl<$t> From<&$t str> for $type {
|
||||
};
|
||||
}
|
||||
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Token<'text> {
|
||||
/// The type of this token
|
||||
@ -194,7 +193,7 @@ regex_impl! {<'text> Token<'text> {
|
||||
regex!(Type::RadixMarkerBin = r"(?i)^0b")
|
||||
}
|
||||
pub fn expect_number(text: &str) -> Option<Self> {
|
||||
regex!(Type::Number = r"^+?[[:xdigit:]]{1,5}")
|
||||
regex!(Type::Number = r"^+?[[:xdigit:]]+")
|
||||
}
|
||||
pub fn expect_minus(text: &str) -> Option<Self> {
|
||||
regex!(Type::Minus = r"^-")
|
||||
|
Loading…
Reference in New Issue
Block a user