fix lexing of whitespace in number literals

In places where an optional space was previously allowed, allow any
number of arbitrary whitespace characters, in line with the spec and
other tools.
This commit is contained in:
Zachary Snow 2021-07-08 13:50:11 -04:00
parent 190c2488cc
commit 25fe57f75a
4 changed files with 64 additions and 8 deletions

View File

@ -23,7 +23,7 @@ import Text.Read (readMaybe)
-- visual niceties like spaces and underscores
parseNumber :: String -> Number
parseNumber = parseNumber' . map toLower . filter (not . isPad)
where isPad ch = ch == '_' || ch == ' '
where isPad = flip elem "_ \n\t"
parseNumber' :: String -> Number
parseNumber' ['\'', ch] = UnbasedUnsized ch

View File

@ -53,19 +53,19 @@ import Language.SystemVerilog.Parser.Tokens
= @fixedPointNumber
| @unsignedNumber ("." @unsignedNumber)? @exp @sign? @unsignedNumber
@size = @nonZeroUnsignedNumber " "?
@size = @nonZeroUnsignedNumber $white*
@binaryNumber = @size? @binaryBase " "? @binaryValue
@octalNumber = @size? @octalBase " "? @octalValue
@hexNumber = @size? @hexBase " "? @hexValue
@binaryNumber = @size? @binaryBase $white* @binaryValue
@octalNumber = @size? @octalBase $white* @octalValue
@hexNumber = @size? @hexBase $white* @hexValue
@unbasedUnsizedLiteral = "'" ( 0 | 1 | x | X | z | Z )
@decimalNumber
= @unsignedNumber
| @size? @decimalBase " "? @unsignedNumber
| @size? @decimalBase " "? @xDigit "_"*
| @size? @decimalBase " "? @zDigit "_"*
| @size? @decimalBase $white* @unsignedNumber
| @size? @decimalBase $white* @xDigit "_"*
| @size? @decimalBase $white* @zDigit "_"*
@integralNumber
= @decimalNumber
| @octalNumber

View File

@ -0,0 +1,46 @@
module top;
initial begin
$display("%b",
5
/* intentional tab */
'b
/* intentional tab */
01010
);
$display("%b",
3
/* intentional tab */
'o
/* intentional tab */
7
);
$display("%b",
8
/* intentional tab */
'h
/* intentional tab */
ab
);
$display("%b",
8
/* intentional tab */
'd
/* intentional tab */
11
);
$display("%b",
8
/* intentional tab */
'd
/* intentional tab */
x___
);
$display("%b",
8
/* intentional tab */
'd
/* intentional tab */
z___
);
end
endmodule

View File

@ -0,0 +1,10 @@
module top;
initial begin
$display("%b", 5'b01010);
$display("%b", 3'o7);
$display("%b", 8'hab);
$display("%b", 8'd11);
$display("%b", 8'dx___);
$display("%b", 8'dz___);
end
endmodule