Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow underscores in numbers

  • Loading branch information...
commit b3234a79ee1ea429dbb0baeef45d807431bf11a5 1 parent e3785dd
@nickg authored
View
19 src/lexer.l
@@ -58,10 +58,11 @@ STRING \"([^\"]|\"\")*\"
BIT_STRING [BOXbox]\"[0-9a-fA-f_]+\"
CHAR '.'
COMMENT --.*\n
-INT [0-9]+{EXPONENT}?
+DIGITS [0-9][0-9_]*
+INT {DIGITS}{EXPONENT}?
REAL {INT}\.{INT}
-EXPONENT [Ee][+-]?[0-9]+
-BASED_INT {INT}#[0-9a-fA-f]+#
+EXPONENT [Ee][+-]?{DIGITS}
+BASED_INT {INT}#[0-9a-fA-f][0-9a-fA-f_]*#
SPACE [ \t\r\n]+
TICK \'
@@ -347,9 +348,19 @@ static int parse_ex_id(const char *str)
TOKEN(tID);
}
+static void strip_underscores(char *s)
+{
+ char *p;
+ for (p = s; *s != '\0'; s++)
+ if (*s != '_')
+ *p++ = *s;
+ *p = '\0';
+}
+
static int parse_int(const char *str)
{
char *tmp = strdup(str);
+ strip_underscores(tmp);
char *base = strtok(tmp, "eE");
char *exp = strtok(NULL, "eE");
@@ -373,6 +384,7 @@ static int parse_int(const char *str)
static int parse_based_int(const char *str)
{
char *tmp = strdup(str);
+ strip_underscores(tmp);
char *base = strtok(tmp, "#");
char *value = strtok(NULL, "#");
@@ -389,6 +401,7 @@ static int parse_based_int(const char *str)
static int parse_real(const char *str)
{
char *tmp = strdup(str);
+ strip_underscores(tmp);
char *base = strtok(tmp, "eE");
char *exp = strtok(NULL, "eE");
View
1  test/parse/based.vhd
@@ -5,5 +5,6 @@ package p is
constant c : integer := 8#7#;
constant d : integer := 10#1234#;
constant e : integer := 16#beef01#;
+ constant f : integer := 2#1_0#;
end package;
View
2  test/parse/literal.vhd
@@ -9,6 +9,8 @@ architecture a of e is
constant f : real := 0.21712;
constant g : real := 1.4e6;
constant h : real := 235.1e-2;
+ constant i : integer := 1_2_3_4;
+ constant j : real := 5_6_7.12_3;
begin
end architecture;
View
21 test/test_parse.c
@@ -662,7 +662,7 @@ START_TEST(test_literal)
a = parse();
fail_if(a == NULL);
fail_unless(tree_kind(a) == T_ARCH);
- fail_unless(tree_decls(a) == 10);
+ fail_unless(tree_decls(a) == 12);
d = tree_decl(a, 0);
fail_unless(tree_ident(d) == ident_new("POS"));
@@ -743,6 +743,22 @@ START_TEST(test_literal)
fail_unless(l.kind == L_REAL);
fail_unless(l.r == 2.351);
+ d = tree_decl(a, 10);
+ fail_unless(tree_ident(d) == ident_new("I"));
+ v = tree_value(d);
+ fail_unless(tree_kind(v) == T_LITERAL);
+ l = tree_literal(v);
+ fail_unless(l.kind == L_INT);
+ fail_unless(l.i == 1234);
+
+ d = tree_decl(a, 11);
+ fail_unless(tree_ident(d) == ident_new("J"));
+ v = tree_value(d);
+ fail_unless(tree_kind(v) == T_LITERAL);
+ l = tree_literal(v);
+ fail_unless(l.kind == L_REAL);
+ fail_unless(l.r == 567.123);
+
a = parse();
fail_unless(a == NULL);
@@ -1384,6 +1400,9 @@ START_TEST(test_based)
d = tree_decl(p, 4);
fail_unless(tree_literal(tree_value(d)).i == 0xbeef01);
+ d = tree_decl(p, 5);
+ fail_unless(tree_literal(tree_value(d)).i == 2);
+
p = parse();
fail_unless(p == NULL);
Please sign in to comment.
Something went wrong with that request. Please try again.