Skip to content

Commit 838c97c

Browse files
committed
created smrule (sum multiplication rule) macro
1 parent 41b30b4 commit 838c97c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/SymbolicUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export Rewriters
5050
# A library for composing together expr -> expr functions
5151

5252
using Combinatorics: permutations, combinations
53-
export @rule, @acrule, RuleSet
53+
export @rule, @acrule, @smrule, RuleSet
5454

5555
# Rule type and @rule macro
5656
include("rule.jl")

src/rule.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,26 @@ macro rule(expr)
384384
end
385385
end
386386

387+
macro smrule(expr)
388+
@assert expr.head == :call && expr.args[1] == :(=>)
389+
lhs = expr.args[2]
390+
rhs = rewrite_rhs(expr.args[3])
391+
keys = Symbol[]
392+
lhs_term = makepattern(lhs, keys)
393+
unique!(keys)
394+
quote
395+
$(__source__)
396+
lhs_pattern = $(lhs_term)
397+
Rule(
398+
$(QuoteNode(expr)),
399+
lhs_pattern,
400+
matcher(lhs_pattern; acSets = permutations),
401+
__MATCHES__ -> $(makeconsequent(rhs)),
402+
rule_depth($lhs_term)
403+
)
404+
end
405+
end
406+
387407
"""
388408
@capture ex pattern
389409

0 commit comments

Comments
 (0)