diff options
Diffstat (limited to 'parsing/parse.ml')
-rw-r--r-- | parsing/parse.ml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/parsing/parse.ml b/parsing/parse.ml new file mode 100644 index 0000000000..04764f5eb9 --- /dev/null +++ b/parsing/parse.ml @@ -0,0 +1,36 @@ +(* Entry points in the parser *) + +exception Error of int * int (* Syntax error *) +(* Skip tokens to the end of the phrase *) + +let rec skip_phrase lexbuf = + try + match Lexer.token lexbuf with + Parser.SEMISEMI | Parser.EOF -> () + | _ -> skip_phrase lexbuf + with Lexer.Error(_,_,_) -> + skip_phrase lexbuf + +let maybe_skip_phrase lexbuf = + if Parsing.is_current_lookahead Parser.SEMISEMI + or Parsing.is_current_lookahead Parser.EOF + then () + else skip_phrase lexbuf + +let wrap parsing_fun lexbuf = + try + parsing_fun Lexer.token lexbuf + with + Lexer.Error(_, _, _) as err -> + if !Location.input_name = "" then skip_phrase lexbuf; + raise err + | Parsing.Parse_error -> + let start = Lexing.lexeme_start lexbuf + and stop = Lexing.lexeme_end lexbuf in + if !Location.input_name = "" + then maybe_skip_phrase lexbuf; + raise(Error(start, stop)) + +let toplevel_phrase = wrap Parser.toplevel_phrase +and implementation = wrap Parser.implementation +and interface = wrap Parser.interface |