3

This seems like a dumb question to ask, as when I prototype it inside of a terminal I am able to make this work. But when I use the following specific module:

http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lexing.html

and this code:

(*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) }

I am getting the following error:

Error: Unbound record field label pos_bol

and I am kind of perplexed to why this happening. In the documentation I linked above it says that pos_bol is a field of the type Lexing.position

Sorry, I feel like this is going to have a rather obvious answer when it is answered, but thanks any way!

4

1 回答 1

6

在 OCaml 中,sum 构造函数和记录字段名称在模块内限定范围,如标识符。position记录是在里面定义的Lexing,它没有在当前范围内打开,所以pos.pos_bol你应该使用pos.Lexing.pos_bol.

于 2013-06-13T21:44:46.577 回答