From 55b651b13bf4204d859f1e8b7265a44f1721066b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pottier?= Date: Tue, 6 Oct 2015 13:26:58 +0200 Subject: [PATCH] Cleanup. Replaced [shift_precedence] with [prec_annotation] everywhere. --- src/fancy-parser.mly | 2 +- src/grammar.ml | 13 +++++-------- src/parameterizedGrammar.ml | 2 +- src/partialGrammar.ml | 8 ++++---- src/syntax.mli | 7 +++++-- src/unparameterizedPrinter.ml | 2 +- src/unparameterizedSyntax.ml | 2 +- src/yacc-parser.mly | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/fancy-parser.mly b/src/fancy-parser.mly index 3287e66d..5aa09733 100644 --- a/src/fancy-parser.mly +++ b/src/fancy-parser.mly @@ -222,7 +222,7 @@ production_group: { pr_producers; pr_action; - pr_branch_shift_precedence = ParserAux.override pos oprec1 oprec2; + pr_branch_prec_annotation = ParserAux.override pos oprec1 oprec2; pr_branch_reduce_precedence = rprec; pr_branch_position = pos }) diff --git a/src/grammar.ml b/src/grammar.ml index f95a07a3..a6046699 100644 --- a/src/grammar.ml +++ b/src/grammar.ml @@ -560,15 +560,12 @@ module Production = struct let (_ : int) = StringMap.fold (fun nonterminal { branches = branches } k -> let nt = Nonterminal.lookup nonterminal in let k' = List.fold_left (fun k branch -> - let action = branch.action - and sprec = branch.branch_shift_precedence - and rprec = branch.branch_reduce_precedence in let symbols = Array.of_list branch.producers in table.(k) <- (nt, Array.map (fun (v, _) -> Symbol.lookup v) symbols); identifiers.(k) <- Array.map snd symbols; - actions.(k) <- Some action; - reduce_precedence.(k) <- rprec; - prec_decl.(k) <- sprec; + actions.(k) <- Some branch.action; + reduce_precedence.(k) <- branch.branch_reduce_precedence; + prec_decl.(k) <- branch.branch_prec_annotation; positions.(k) <- [ branch.branch_position ]; k+1 ) k branches in @@ -740,7 +737,7 @@ module Production = struct let combine e1 e2 = lazy (Lazy.force e1; Lazy.force e2) - let shift_precedence prod = + let precedence prod = let fact1, prec_decl = consult_prec_decl prod in let oterminal = match prec_decl with @@ -1461,7 +1458,7 @@ module Precedence = struct let shift_reduce tok prod = let fact1, tokp = Terminal.precedence_level tok - and fact2, prodp = Production.shift_precedence prod in + and fact2, prodp = Production.precedence prod in match precedence_order tokp prodp with (* Our information is inconclusive. Drop [fact1] and [fact2], diff --git a/src/parameterizedGrammar.ml b/src/parameterizedGrammar.ml index 043ff989..7bea9f9a 100644 --- a/src/parameterizedGrammar.ml +++ b/src/parameterizedGrammar.ml @@ -557,7 +557,7 @@ let expand p_grammar = branch_position = pbranch.pr_branch_position; producers = new_producers; action = pbranch.pr_action; - branch_shift_precedence = pbranch.pr_branch_shift_precedence; + branch_prec_annotation = pbranch.pr_branch_prec_annotation; branch_reduce_precedence = pbranch.pr_branch_reduce_precedence; } diff --git a/src/partialGrammar.ml b/src/partialGrammar.ml index 13935948..2b13128e 100644 --- a/src/partialGrammar.ml +++ b/src/partialGrammar.ml @@ -650,9 +650,9 @@ let check_parameterized_grammar_is_well_defined grammar = (* Check each branch. *) (fun { pr_producers = producers; - pr_branch_shift_precedence = sprec; - pr_action = action - } -> ignore (List.fold_left + pr_branch_prec_annotation; + pr_action = action + } -> ignore (List.fold_left (* Check the producers. *) (fun already_seen (id, p) -> @@ -686,7 +686,7 @@ let check_parameterized_grammar_is_well_defined grammar = check_keywords producers action; - match sprec with + match pr_branch_prec_annotation with | None -> () diff --git a/src/syntax.mli b/src/syntax.mli index 60a0659d..929381b0 100644 --- a/src/syntax.mli +++ b/src/syntax.mli @@ -85,7 +85,10 @@ type declaration = | DType of Stretch.ocamltype * parameter -type branch_shift_precedence = +(* A [%prec] annotation is optional. A production can carry at most one. + If there is one, it is a symbol name. *) + +type branch_prec_annotation = symbol Positions.located option type branch_reduce_precedence = @@ -99,7 +102,7 @@ type parameterized_branch = pr_branch_position : Positions.t; pr_producers : producer list; pr_action : action; - pr_branch_shift_precedence : branch_shift_precedence; + pr_branch_prec_annotation : branch_prec_annotation; pr_branch_reduce_precedence : branch_reduce_precedence } diff --git a/src/unparameterizedPrinter.ml b/src/unparameterizedPrinter.ml index 2b8f320e..741d35b3 100644 --- a/src/unparameterizedPrinter.ml +++ b/src/unparameterizedPrinter.ml @@ -131,7 +131,7 @@ let string_of_producer mode (symbol, ido) = let print_branch mode f branch = Printf.fprintf f "%s%s\n {" (String.concat " " (List.map (string_of_producer mode) branch.producers)) - (Misc.o2s branch.branch_shift_precedence (fun x -> " %prec "^x.value)); + (Misc.o2s branch.branch_prec_annotation (fun x -> " %prec "^x.value)); begin match mode with | PrintNormal -> Action.print f branch.action diff --git a/src/unparameterizedSyntax.ml b/src/unparameterizedSyntax.ml index b0012131..12e0bc77 100644 --- a/src/unparameterizedSyntax.ml +++ b/src/unparameterizedSyntax.ml @@ -21,7 +21,7 @@ type branch = producers : (symbol * identifier) list; (* TEMPORARY convention renversée par rapport à syntax.mli; faire un type record au lieu d'une paire? *) action : action; - branch_shift_precedence : branch_shift_precedence; + branch_prec_annotation : branch_prec_annotation; branch_reduce_precedence : branch_reduce_precedence } diff --git a/src/yacc-parser.mly b/src/yacc-parser.mly index 0730c9ec..049f6201 100644 --- a/src/yacc-parser.mly +++ b/src/yacc-parser.mly @@ -276,7 +276,7 @@ production_group: { pr_producers; pr_action; - pr_branch_shift_precedence = ParserAux.override pos oprec1 oprec2; + pr_branch_prec_annotation = ParserAux.override pos oprec1 oprec2; pr_branch_reduce_precedence = rprec; pr_branch_position = pos }) -- GitLab