Skip to content

Commit 4500cbe

Browse files
authored
Merge pull request #228 from teo-tsirpanis/fix-no-header
Fix compile errors in fsyacc's output if there is no header in the input file.
2 parents e8a4481 + 84fba2c commit 4500cbe

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/FsYacc.Core/fsyaccdriver.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ type Writer(outputFileName, outputFileInterface) =
120120
member x.WriteUInt16(i: int) = fprintf os "%dus;" i
121121

122122
member x.WriteCode(code, pos) =
123-
x.WriteLine "# %d \"%s\"" pos.pos_lnum pos.pos_fname
124-
x.WriteLine "%s" code
125-
let codeLines = code.Replace("\r", "").Split([| '\n' |]).Length
126-
outputLineCount <- outputLineCount + codeLines
127-
x.WriteLine "# %d \"%s\"" outputLineCount outputFileName
123+
if code <> "" then
124+
x.WriteLine "# %d \"%s\"" pos.pos_lnum pos.pos_fname
125+
x.WriteLine "%s" code
126+
let codeLines = code.Replace("\r", "").Split([| '\n' |]).Length
127+
outputLineCount <- outputLineCount + codeLines
128+
x.WriteLine "# %d \"%s\"" outputLineCount outputFileName
128129

129130
member x.OutputLineCount = outputLineCount
130131

tests/LexAndYaccMiniProject/Parser.fsy

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
%{
2-
3-
4-
%}
5-
6-
// The start token becomes a parser function in the compiled code:
1+
// The start token becomes a parser function in the compiled code:
72
%start start
83

94
// Regular tokens

0 commit comments

Comments
 (0)