Skip to content

Commit

Permalink
Fix ordering of imported rules in syntax packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed Oct 11, 2022
1 parent 1ea3637 commit 5c79170
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/parser/syntax-package-merger.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ public defn merge (pkgs:Tuple<SyntaxPackage>) -> MergedSyntaxPackage :
;Scan through all DefRule and add them to the local-rules and foreign-rules
;tables.
defn fill-rule-tables () :
for pkg in pkgs do :
;The packages are traversed in reverse order so that the
;foreign rules come out in the proper order.
;Given base + p1, p2, the final ordering of foreign rules are:
; p2 / rule1
; p2 / rule2
; p2 / ...
; p1 / rule1
; p1 / rule2
; p1 / ...
; base / rule1
; base / rule2
; base / ...
for pkg in in-reverse(pkgs) do :
for rule in rules(pkg) do :
val rec = local-table[ProdName(name(pkg), name(rule))]
val local? = package(rec) == name(pkg)
Expand Down Expand Up @@ -157,9 +169,12 @@ public defn merge (pkgs:Tuple<SyntaxPackage>) -> MergedSyntaxPackage :
add(new-rules, rule)

;If no InlinedRules patterns were executed, then by default
;add all foreign rules to the end of the list.
;add all foreign rules to the start of the list.
if not inlined-foreign-rules? :
add-all(new-rules, foreign-rules[key(entry)])
if not empty?(foreign-rules[key(entry)]) :
val saved-rules = to-tuple(new-rules)
clear(new-rules)
add-all(new-rules, cat(foreign-rules[key(entry)], saved-rules))

key(entry) => new-rules

Expand Down

0 comments on commit 5c79170

Please sign in to comment.