From 88220d13d4e83f8092eb7d52d430ce446d95e1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pottier?= Date: Wed, 18 May 2016 14:02:56 +0200 Subject: [PATCH] Removed the file [InternalSyntax]. --- src/Driver.mli | 2 +- src/fancy-parser.mly | 2 +- src/internalSyntax.mli | 11 ----------- src/parameterizedGrammar.ml | 3 +-- src/parameterizedGrammar.mli | 4 +--- src/partialGrammar.ml | 3 +-- src/partialGrammar.mli | 4 +++- src/syntax.mli | 34 +++++++++++++++++++++++++++++++++- src/yacc-parser.mly | 2 +- 9 files changed, 42 insertions(+), 23 deletions(-) delete mode 100644 src/internalSyntax.mli diff --git a/src/Driver.mli b/src/Driver.mli index 1d8c654c..9da0d374 100644 --- a/src/Driver.mli +++ b/src/Driver.mli @@ -2,4 +2,4 @@ which could be produced by either ocamlyacc or Menhir. *) val grammar : - (Lexing.lexbuf -> Parser.token) -> Lexing.lexbuf -> Syntax.grammar + (Lexing.lexbuf -> Parser.token) -> Lexing.lexbuf -> Syntax.partial_grammar diff --git a/src/fancy-parser.mly b/src/fancy-parser.mly index 2cd866f6..854c2129 100644 --- a/src/fancy-parser.mly +++ b/src/fancy-parser.mly @@ -29,7 +29,7 @@ open Positions /* ------------------------------------------------------------------------- */ /* Start symbol. */ -%start grammar +%start grammar /* ------------------------------------------------------------------------- */ /* Priorities. */ diff --git a/src/internalSyntax.mli b/src/internalSyntax.mli deleted file mode 100644 index bb3ce881..00000000 --- a/src/internalSyntax.mli +++ /dev/null @@ -1,11 +0,0 @@ -type grammar = - { - p_preludes : Stretch.t list; - p_postludes : Syntax.trailer list; - p_parameters : Stretch.t list; - p_start_symbols : Positions.t StringMap.t; - p_types : (Syntax.parameter * Stretch.ocamltype Positions.located) list; - p_tokens : Syntax.token_properties StringMap.t; - p_rules : Syntax.parameterized_rule StringMap.t; - p_on_error_reduce : Syntax.parameter list; - } diff --git a/src/parameterizedGrammar.ml b/src/parameterizedGrammar.ml index 213bea2b..7a036a86 100644 --- a/src/parameterizedGrammar.ml +++ b/src/parameterizedGrammar.ml @@ -1,7 +1,6 @@ open Positions open Syntax open UnparameterizedSyntax -open InternalSyntax open Misc (* Inference for non terminals. *) @@ -249,7 +248,7 @@ let rec parameter_type env = function [Star] otherwise it is the flexible variable. *) star_variable -let check_grammar p_grammar = +let check_grammar (p_grammar : Syntax.grammar) = (* [n] is the grammar size. *) let n = StringMap.cardinal p_grammar.p_rules in diff --git a/src/parameterizedGrammar.mli b/src/parameterizedGrammar.mli index d43fcc11..3a858085 100644 --- a/src/parameterizedGrammar.mli +++ b/src/parameterizedGrammar.mli @@ -10,6 +10,4 @@ sanitized via [Misc.normalize] when printed in a context where a valid identifier is expected. *) -val expand : InternalSyntax.grammar -> UnparameterizedSyntax.grammar - - +val expand : Syntax.grammar -> UnparameterizedSyntax.grammar diff --git a/src/partialGrammar.ml b/src/partialGrammar.ml index e5c3f475..02605ffe 100644 --- a/src/partialGrammar.ml +++ b/src/partialGrammar.ml @@ -1,6 +1,5 @@ open Misc open Syntax -open InternalSyntax open Positions (* ------------------------------------------------------------------------- *) @@ -432,7 +431,7 @@ let iter_on_only_used_symbols f t = | _ -> ()) t -let symbols_of grammar (pgrammar : Syntax.grammar) = +let symbols_of grammar (pgrammar : Syntax.partial_grammar) = let tokens = grammar.p_tokens in let symbols_of_rule symbols prule = let rec store_except_rule_parameters = diff --git a/src/partialGrammar.mli b/src/partialGrammar.mli index a5a9adcd..0ee56580 100644 --- a/src/partialGrammar.mli +++ b/src/partialGrammar.mli @@ -1,2 +1,4 @@ +open Syntax + val join_partial_grammars : - Syntax.grammar list -> InternalSyntax.grammar + partial_grammar list -> grammar diff --git a/src/syntax.mli b/src/syntax.mli index 7ddcbdb5..783e9c2c 100644 --- a/src/syntax.mli +++ b/src/syntax.mli @@ -1,3 +1,13 @@ +(* The type [partial_grammar] describes the abstract syntax that is produced + by the parsers (yacc-parser and fancy-parser). + + The type [grammar] describes the abstract syntax that is obtained after one + or more partial grammars are joined (see [PartialGrammar]). It differs in + that declarations are organized in a more useful way and a number of + well-formedness checks have been performed. *) + +(* ------------------------------------------------------------------------ *) + (* Terminals and nonterminal symbols are strings. Identifiers (which are used to refer to a symbol's semantic value) are strings. A file name is a string. *) @@ -17,16 +27,24 @@ type identifier = type filename = string +(* ------------------------------------------------------------------------ *) + (* A trailer is a source file fragment. *) type trailer = Stretch.t +(* ------------------------------------------------------------------------ *) + (* OCaml semantic actions are represented as stretches. *) type action = Action.t +(* ------------------------------------------------------------------------ *) + +(* Information about tokens. *) + type token_associativity = LeftAssoc | RightAssoc @@ -52,6 +70,8 @@ type token_properties = mutable tk_is_declared : bool; } +(* ------------------------------------------------------------------------ *) + type parameter = | ParameterVar of symbol Positions.located | ParameterApp of symbol Positions.located * parameters @@ -123,10 +143,22 @@ type parameterized_rule = pr_branches : parameterized_branch list; } -type grammar = +type partial_grammar = { pg_filename : filename; pg_declarations : declaration Positions.located list; pg_rules : parameterized_rule list; pg_trailer : trailer option; } + +type grammar = + { + p_preludes : Stretch.t list; + p_postludes : trailer list; + p_parameters : Stretch.t list; + p_start_symbols : Positions.t StringMap.t; + p_types : (parameter * Stretch.ocamltype Positions.located) list; + p_tokens : token_properties StringMap.t; + p_rules : parameterized_rule StringMap.t; + p_on_error_reduce : parameter list; + } diff --git a/src/yacc-parser.mly b/src/yacc-parser.mly index 8ed78f05..0a310560 100644 --- a/src/yacc-parser.mly +++ b/src/yacc-parser.mly @@ -20,7 +20,7 @@ open Positions %token PERCENTPERCENT %token Syntax.action> ACTION %start grammar -%type grammar +%type grammar /* These declarations solve a shift-reduce conflict in favor of shifting: when the declaration of a non-terminal symbol begins with -- GitLab