I'm using FsLex and FsYacc for string parsing in F# application. During Abstract Syntax Tree (AST) creation parser has to do a decision how to create the AST (make different trees, throw an exception, etc). The parser behaviour must depend on several parameters.
Here I've found that it is allowed to declare something like:
%type < (context -> context) > toplevel
But I could not find how to use this construction and during project compilation have "fsyacc.exe" exited with code 1." error
The Question is: is it possible and how to use context parameters during parsing with FsYacc?
Example of what I've tried:
%start startAst
%type < (bool -> MyAst) > startAst
%%
startAst:
| MyAst EOF {
(fun (x : bool) ->
if x then
MyAst.Type1 $1
else
MyAst.Type2)
}
...
and I've expected usage something like this:
let lexbuf = Lexing.LexBuffer<char>.FromString text
lexbuf |> Lexer.tokenize |> Parser.startAst (ctx: bool)
Thanks in advance
Update following exception and call stack is generated during fsyacc.exe execution:
Unhandled Exception: System.Exception: more than one input given
at FSharp.PowerPack.FsYacc.Driver.clo@67-5.Invoke(String x)
at <StartupCode$fsyacc>.$Arg.findMatchingArg$cont@104-1(FSharpRef`1 cursor, FSharpFunc`2 other, String usageText, FSharpList`1 argSpecs, String arg, Unit unitVar)
at <StartupCode$fsyacc>.$Arg.findMatchingArg@64(FSharpRef`1 cursor, String[] argv, FSharpFunc`2 other, String usageText, Int32 nargs, FSharpList`1 argSpecs, String arg, FSharpList`1 args)
at Internal.Utilities.ArgParser.ParsePartial(FSharpRef`1 cursor, String[] argv, IEnumerable`1 arguments, FSharpOption`1 otherArgs, FSharpOption`1 usageText)
at Internal.Utilities.ArgParser.Parse(IEnumerable`1 arguments, FSharpOption`1 otherArgs, FSharpOption`1 usageText)
at <StartupCode$fsyacc>.$FSharp.PowerPack.FsYacc.Driver.main@()