Skip to content

Commit

Permalink
fix #158: remove old number-literal size-specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Feb 20, 2023
1 parent ded1b3a commit d9db883
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
44 changes: 0 additions & 44 deletions src/syntax/excerpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,50 +228,6 @@ pub fn excerpt_as_bigint(report: Option<RcReport>, excerpt: &str, span: &Span) -
}


fn parse_width(report: RcReport, chars: &[char], span: &Span) -> Result<(Option<usize>, usize), ()>
{
if !chars.iter().any(|c| *c == '\'')
{ return Ok((None, 0)); }

let mut width: usize = 0;
let mut index = 0;
loop
{
let c = chars[index];
index += 1;

if c == '_'
{ continue; }

if c == '\''
{ break; }

let digit = match c.to_digit(10)
{
Some(d) => d,
None => return Err(report.error_span("invalid digits in width specifier", span))
};

width = match width.checked_mul(10)
{
Some(v) => v,
None => return Err(report.error_span("width specifier is too large", span))
};

width = match width.checked_add(digit as usize)
{
Some(v) => v,
None => return Err(report.error_span("width specifier is too large", span))
};
}

if width == 0
{ return Err(report.error_span("invalid width specifier", span)); }

Ok((Some(width), index))
}


fn parse_radix(chars: &[char], index: usize) -> (usize, usize)
{
if chars[index] == '0' && index + 1 < chars.len()
Expand Down
3 changes: 1 addition & 2 deletions src/syntax/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,5 @@ fn is_number_mid(c: char) -> bool
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '_' ||
c == '.' ||
c == '\''
c == '.'
}
7 changes: 4 additions & 3 deletions src/test/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ fn test_literals()
test("0o10a", Fail(("test", 1, "invalid")));
test("0x10g", Fail(("test", 1, "invalid")));

test("8'0x0", Fail(("test", 1, "invalid")));
test("0b8'0x00", Fail(("test", 1, "invalid")));
test("0x8'0x00", Fail(("test", 1, "invalid")));
test("8'5", Fail(("test", 1, "unexpected character")));
test("8'0x0", Fail(("test", 1, "unexpected character")));
test("0b8'0x00", Fail(("test", 1, "unexpected character")));
test("0x8'0x00", Fail(("test", 1, "unexpected character")));
}


Expand Down

0 comments on commit d9db883

Please sign in to comment.