Commit 25fe57f7 by Zachary Snow

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.
parent 190c2488
...@@ -23,7 +23,7 @@ import Text.Read (readMaybe) ...@@ -23,7 +23,7 @@ import Text.Read (readMaybe)
-- visual niceties like spaces and underscores -- visual niceties like spaces and underscores
parseNumber :: String -> Number parseNumber :: String -> Number
parseNumber = parseNumber' . map toLower . filter (not . isPad) parseNumber = parseNumber' . map toLower . filter (not . isPad)
where isPad ch = ch == '_' || ch == ' ' where isPad = flip elem "_ \n\t"
parseNumber' :: String -> Number parseNumber' :: String -> Number
parseNumber' ['\'', ch] = UnbasedUnsized ch parseNumber' ['\'', ch] = UnbasedUnsized ch
......
...@@ -53,19 +53,19 @@ import Language.SystemVerilog.Parser.Tokens ...@@ -53,19 +53,19 @@ import Language.SystemVerilog.Parser.Tokens
= @fixedPointNumber = @fixedPointNumber
| @unsignedNumber ("." @unsignedNumber)? @exp @sign? @unsignedNumber | @unsignedNumber ("." @unsignedNumber)? @exp @sign? @unsignedNumber
@size = @nonZeroUnsignedNumber " "? @size = @nonZeroUnsignedNumber $white*
@binaryNumber = @size? @binaryBase " "? @binaryValue @binaryNumber = @size? @binaryBase $white* @binaryValue
@octalNumber = @size? @octalBase " "? @octalValue @octalNumber = @size? @octalBase $white* @octalValue
@hexNumber = @size? @hexBase " "? @hexValue @hexNumber = @size? @hexBase $white* @hexValue
@unbasedUnsizedLiteral = "'" ( 0 | 1 | x | X | z | Z ) @unbasedUnsizedLiteral = "'" ( 0 | 1 | x | X | z | Z )
@decimalNumber @decimalNumber
= @unsignedNumber = @unsignedNumber
| @size? @decimalBase " "? @unsignedNumber | @size? @decimalBase $white* @unsignedNumber
| @size? @decimalBase " "? @xDigit "_"* | @size? @decimalBase $white* @xDigit "_"*
| @size? @decimalBase " "? @zDigit "_"* | @size? @decimalBase $white* @zDigit "_"*
@integralNumber @integralNumber
= @decimalNumber = @decimalNumber
| @octalNumber | @octalNumber
......
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment