Reputation: 3644
I've been using fslex and fsyacc, and the F# source files (.fs
they generate from the lexer (.fsl
) and parser (.fsp
) rules refer to the original .fsl
(and sometimes to the same .fs
source file) all over the place with statement such as this (numbers are line numbers):
lex.fs
1 # 1 "/[PROJECT-PATH-HERE]/lex.fsp
...
16 # 16 "/PROJECT-PATH-HERE]/lex.fs
17 // This is the type of tokens accepted by the parser
18 type token =
19 | EOF
...
Also, the .fs
files generated by pars.fsp
do the same kind of thing, but additionaly reference to the F# signature file (.fsi
) generated alongside it. What does any of this do/mean?
Upvotes: 0
Views: 142
Reputation: 11525
The annotations you see in the generated code are F# Compiler Directives (specifically, the 'line' directive).
The 'line' directive makes it so that when the F# compiler needs to emit a warning/error message for some part of the generated code, it has a way to determine which part of the original file corresponds to that part of the generated code. In other words, the F# compiler can generate a warning/error message referencing the original code which is the basis of the generated code causing the error.
Upvotes: 2