Setup and use a Menhir parser for the OCaml grammar (REBASE POINT)

Uses the new $symbolstartpos feature of Menhir
to get locations identical to the OCamlYacc ones.

REBASE POINT: at the point of this commit, using a diff program
on parser.mly and parser_menhir.mlyp should give identical results
after the header code. If you rebase the Menhir-parser patchset
against a newer ocamlyacc parser (parser.mly), those two files
will have diverged, and you need to merge the parser.mly change
back into parser_menhir.mlyp -- and then deal with them in the
rest of the patch series.
master
Gabriel Scherer 2017-05-23 17:04:49 +02:00
parent f11fa56cfc
commit 9a38c848fc
5 changed files with 2874 additions and 1 deletions

View File

@ -79,6 +79,7 @@ UTILS=utils/config.cmo utils/build_path_prefix_map.cmo utils/misc.cmo \
PARSING=parsing/location.cmo parsing/longident.cmo \
parsing/docstrings.cmo parsing/syntaxerr.cmo \
parsing/ast_helper.cmo parsing/parser.cmo \
parsing/menhirLib.cmo parsing/parser_menhir.cmo \
parsing/lexer.cmo parsing/parse.cmo parsing/printast.cmo \
parsing/pprintast.cmo \
parsing/ast_mapper.cmo parsing/ast_iterator.cmo parsing/attr_helper.cmo \
@ -1059,6 +1060,29 @@ ocamlyacc:
clean::
$(MAKE) -C yacc clean
# The Menhir-generated parser
# In order to avoid a build-time dependency on Menhir,
# we store the result of the parser generator (which
# are OCaml source files) and Menhir's runtime libraries
# (that the parser files rely on) in boot/
parsing/parser_menhir.ml: boot/menhir/parser_menhir.ml
cp $< parsing
parsing/parser_menhir.mli: boot/menhir/parser_menhir.mli
cp $< parsing
parsing/menhirLib.ml: boot/menhir/menhirLib.ml
cp $< parsing
parsing/menhirLib.mli: boot/menhir/menhirLib.mli
cp $< parsing
# Makefile.menhir exports an promote-menhir rule that calls Menhir on
# the current grammar and refreshes the boot/ files. It must be called
# for any modification of the grammar to be taken into account by the
# compiler.
include Makefile.menhir
partialclean:: partialclean-menhir
# OCamldoc
.PHONY: ocamldoc

View File

@ -65,3 +65,11 @@ and use_file = wrap Parser.use_file
and core_type = wrap Parser.parse_core_type
and expression = wrap Parser.parse_expression
and pattern = wrap Parser.parse_pattern
let implementation_menhir = wrap Parser_menhir.implementation
and interface_menhir = wrap Parser_menhir.interface
and toplevel_phrase_menhir = wrap Parser_menhir.toplevel_phrase
and use_file_menhir = wrap Parser_menhir.use_file
and core_type_menhir = wrap Parser_menhir.parse_core_type
and expression_menhir = wrap Parser_menhir.parse_expression
and pattern_menhir = wrap Parser_menhir.parse_pattern

View File

@ -22,3 +22,11 @@ val use_file : Lexing.lexbuf -> Parsetree.toplevel_phrase list
val core_type : Lexing.lexbuf -> Parsetree.core_type
val expression : Lexing.lexbuf -> Parsetree.expression
val pattern : Lexing.lexbuf -> Parsetree.pattern
val implementation_menhir : Lexing.lexbuf -> Parsetree.structure
val interface_menhir : Lexing.lexbuf -> Parsetree.signature
val toplevel_phrase_menhir : Lexing.lexbuf -> Parsetree.toplevel_phrase
val use_file_menhir : Lexing.lexbuf -> Parsetree.toplevel_phrase list
val core_type_menhir : Lexing.lexbuf -> Parsetree.core_type
val expression_menhir : Lexing.lexbuf -> Parsetree.expression
val pattern_menhir : Lexing.lexbuf -> Parsetree.pattern

2831
parsing/parser_menhir.mlyp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -126,7 +126,9 @@ CSLPROF=ocamlprof.cmo
CSLPROF_IMPORTS=config.cmo build_path_prefix_map.cmo misc.cmo identifiable.cmo \
numbers.cmo arg_helper.cmo clflags.cmo terminfo.cmo \
warnings.cmo location.cmo longident.cmo docstrings.cmo \
syntaxerr.cmo ast_helper.cmo parser.cmo lexer.cmo parse.cmo
syntaxerr.cmo ast_helper.cmo \
parser.cmo menhirLib.cmo parser_menhir.cmo \
lexer.cmo parse.cmo
$(call byte_and_opt,ocamlprof,$(CSLPROF_IMPORTS) profiling.cmo $(CSLPROF),)