fix handling of macros at EOF (resolves #62)

This commit is contained in:
Zachary Snow 2020-01-27 19:18:58 -05:00
parent bbd072d41d
commit ad98c14547
4 changed files with 23 additions and 1 deletions

View File

@ -787,6 +787,11 @@ peekChar = do
then lexicalError "unexpected end of input"
else return $head str
atEOF :: Alex Bool
atEOF = do
(_, _, _, str) <- alexGetInput
return $ null str
takeMacroDefinition :: Alex (String, [(String, Maybe String)])
takeMacroDefinition = do
leadCh <- peekChar
@ -1068,7 +1073,11 @@ handleDirective (posOrig, _, _, strOrig) len = do
"define" -> do
dropSpaces
name <- takeString
defn <- takeMacroDefinition
defn <- do
eof <- atEOF
if eof
then return ("", [])
else takeMacroDefinition
modify $ \s -> s { lsEnv = Map.insert name defn env }
alexMonadScan
"undef" -> do

6
test/lex/no_newline.sv Normal file
View File

@ -0,0 +1,6 @@
`include "no_newline.vh"
module top;
`ifdef A
initial $display("A is defined!");
`endif
endmodule

6
test/lex/no_newline.v Normal file
View File

@ -0,0 +1,6 @@
`include "no_newline.vh"
module top;
`ifdef A
initial $display("A is defined!");
`endif
endmodule

1
test/lex/no_newline.vh Normal file
View File

@ -0,0 +1 @@
`define A