How to add and use custom context parameters during parsing with F# FsYacc?

醉酒当歌 提交于 2019-12-03 21:20:09

Sorry for the long delay, but finally got around to this.

Whoever wrote FsYacc (the F# team?) missed the functions, as can be seen by their own comment on the page you linked. I tried several variations, but this is the only one I was able to make work (note: this requires either a #nowarn "62" in the .fsy file, which will propagate to the .fs file, or --nowarn:62 for the whole project):

%{

open Ast

type ('a,'b) Fun = 'a -> 'b

%}

%start startAst

%token <string> MyAst
%token EOF

%type < (bool, MyAst) Fun > startAst

%%

startAst:
| MyAst EOF { (fun (x : bool) ->
                if x then
                    MyAst.Type1 $1
                else
                    MyAst.Type2) }

I got no idea why (and don't have the time to go over FsYacc's source, at least not right now).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!