这似乎是一个愚蠢的问题,因为当我在终端内部对其进行原型设计时,我能够完成这项工作.但是当我使用以下特定模块时:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html
而这段代码:
(*Identifiers*)
let ws = [' ' '\t']*
let id = ['A'-'Z' 'a'-'z'] +
let map = id ws ':' ws id
let feed = '{' ws map+ ws '}'
let feeds = '[' ws feed + ws ']'
(*Entry Points *)
rule token = parse
[' ' '\t'] { token lexbuf } (* skip blanks *)
| ['\n' ] { EOL }
| feeds as expr { Feeds( expr ) }
| id as expr { Id(expr) }
| feed as expr {
let pos = Lexing.lexeme_start_p lexbuf in
let pos_bol = pos.pos_bol in
print_string (string_of_int pos_bol);
print_string "\n";
Feed(expr) }
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error: Unbound record field label pos_bol
Run Code Online (Sandbox Code Playgroud)
而且我对为什么会发生这种情况感到困惑.在我上面链接的文档中,它说pos_bol是Lexing.position类型的字段
对不起,我觉得回答时会有一个相当明显的答案,但谢谢!
在OCaml中,sum构造函数和记录字段名称的范围在模块内,如标识符.该position是内部定义的记录Lexing等等,而不是,这不是在当前范围内开了,pos.pos_bol你应该使用pos.Lexing.pos_bol.
| 归档时间: |
|
| 查看次数: |
156 次 |
| 最近记录: |