我试图让我的F#代码从词法分析器中捕获错误输入的异常。虽然引发了异常,但它没有被其他模块捕获。有人能帮忙吗?
let lexstring expr =
try
LexBuffer<char>.FromString(expr)
with
Lexer.IllegalCharacter -> failwith "XXXXXXXXXXXX"
词法分析器代码如下:
| ['-']?digit+('.'digit+)?(['e''E']digit+)? { FLOAT (Double.Parse(lexeme lexbuf)) }
// EOF
| eof { EOF }
| _ { raise IllegalCharacter }
错误消息如下:
Lexer.IllegalCharacter occurred
HResult=-2146233088
Message=Exception of type 'Lexer+IllegalCharacter' was thrown.
Source=FSharp.Core
StackTrace:
at Microsoft.FSharp.Core.Operators.Raise[T](Exception exn)
at Lexer._fslex_tokenize(Int32 _fslex_state, LexBuffer`1 lexbuf) in E:\Programming\F#\fsapp_ozan\parser\Lexer.fsl:line 48
InnerException: