I have a parser which parses the std input using Ocamlyacc and lex. How can I trigger the start parse rule on a string in OCaml?
Asked
Active
Viewed 76 times
1 Answers
2
Without seeing your code, it's hard to answer but assuming your start rule is called start
, and your generated parser module is called Parser.ml
and yout generated lexer module is called Lexer.ml
, you should do something like :
let parse_from_string s =
let lex = Lexing.from_string s in
try
Lexing.(lex.lex_curr_p <- {lex.lex_curr_p with pos_cnum = 0});
Parser.start Lexer.token lex
with
| Failure s ->
Printf.eprintf "Error near %s\n\n"
(string_of_position lex.lex_start_p)

ghilesZ
- 1,502
- 1
- 18
- 30