diff --git a/src/fancy-parser.mly b/src/fancy-parser.mly index 3287e66d22b87279d69a0bb02be445d32e83d71e..5aa09733e35727373517b1a8bddc2edd57cb62ca 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 f95a07a390e2cde44f8a5b92020dd5cf3397dc51..a6046699b04e0615adcbf1c455f9535f3a6c980e 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 043ff98929433e066d36468cb064df170439b965..7bea9f9a3714874150e79fb1ca0740c8b48bdb1a 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 13935948de4842528900093ae94c40180618b145..2b13128ed598c00f5a962e56f36954068b78777f 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 60a0659dd1de988a89865d2c851ad14fff7afaa4..929381b0306b0fe312b2093c837b7a43340c5166 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 2b8f320e14a13fd4ce509a2cdb94af52da5d7c2a..741d35b399dff3496f51456ff5da18394738f176 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 b00121310d2f4c64e44859a8bd3ff27128a830c1..12e0bc77c1148d4fe6358b07600847fbd1159267 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 0730c9ec90a11615ede8904845445bbdeee25740..049f6201eea13c069bd2d8c481daeb9dd7ee9178 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 })