문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top