@@ -60,6 +60,7 @@ function update_rule_indices!(node::RuleNode, n_rules::Integer)
6060 for child in children
6161 update_rule_indices! (child, n_rules)
6262 end
63+ return
6364end
6465
6566"""
@@ -76,7 +77,7 @@ function update_rule_indices!(
7677 node:: RuleNode ,
7778 n_rules:: Integer ,
7879 mapping:: AbstractDict{<:Integer, <:Integer}
79- )
80+ )
8081 rule_ind = get_rule (node)
8182 if rule_ind > n_rules
8283 error (" Rule index $(rule_ind) exceeds the number of grammar rules ($n_rules )." )
@@ -88,14 +89,15 @@ function update_rule_indices!(
8889 for child in children
8990 update_rule_indices! (child, n_rules, mapping)
9091 end
92+ return
9193end
9294
9395# Check whether the `node`'s rule index exceeds the number of rules `n_rules.`
9496function is_domain_valid (node:: RuleNode , n_rules:: Integer )
9597 if get_rule (node) > n_rules
9698 return false
9799 end
98- all (child -> is_domain_valid (child, n_rules), get_children (node))
100+ return all (child -> is_domain_valid (child, n_rules), get_children (node))
99101end
100102
101103"""
@@ -133,7 +135,7 @@ function is_domain_valid(hole::AbstractHole, n_rules::Integer)
133135 if length (hole. domain) != n_rules
134136 return false
135137 end
136- all (child -> is_domain_valid (child, n_rules), get_children (hole))
138+ return all (child -> is_domain_valid (child, n_rules), get_children (hole))
137139end
138140
139141"""
@@ -154,6 +156,7 @@ function update_rule_indices!(hole::AbstractHole, n_rules::Integer)
154156 for child in children
155157 update_rule_indices! (child, n_rules)
156158 end
159+ return
157160end
158161
159162"""
@@ -168,10 +171,11 @@ Errors if the length of the domain vector exceeds new `n_rules`.
168171- `n_rules`: The new number of rules in the grammar
169172- `mapping`: A dictionary mapping the old rule indices to new ones
170173"""
171- function update_rule_indices! (hole:: AbstractHole ,
174+ function update_rule_indices! (
175+ hole:: AbstractHole ,
172176 n_rules:: Integer ,
173177 mapping:: AbstractDict{<:Integer, <:Integer}
174- )
178+ )
175179 update_rule_indices! (hole, n_rules) # resize (also checks n_rules)
176180 # update domain BV according to mapping
177181 rule_indices = findall (hole. domain)
@@ -185,6 +189,7 @@ function update_rule_indices!(hole::AbstractHole,
185189 for child in children
186190 update_rule_indices! (child, n_rules, mapping)
187191 end
192+ return
188193end
189194
190195"""
@@ -221,16 +226,16 @@ function _get_hole_name(holetype)
221226 else
222227 throw (
223228 ArgumentError (
224- styled """
225- Input to the {code:@rulenode} macro appears to be a hole, but the macro does not support the type: {code:{red:$holetype}}. The macro currently supports concrete subtypes of {code:AbstractHole}s {bold:that are defined in {code:HerbCore.jl}}.
226- """ ,
227- ),
229+ styled """
230+ Input to the {code:@rulenode} macro appears to be a hole, but the macro does not support the type: {code:{red:$holetype}}. The macro currently supports concrete subtypes of {code:AbstractHole}s {bold:that are defined in {code:HerbCore.jl}}.
231+ """ ,
232+ ),
228233 )
229234 end
230235end
231236
232237function _shorthand2rulenode (i:: Integer )
233- :(RuleNode ($ i))
238+ return :(RuleNode ($ i))
234239end
235240
236241function _shorthand2rulenode (ex:: Expr )
@@ -261,8 +266,10 @@ function _shorthand2rulenode(ex::Expr)
261266 # rulenodes without children
262267 ex = postwalk (ex) do x
263268 @capture (x, {children__}) || return x
264- children = [isexpr (child, Int, Integer) ? :(RuleNode ($ child)) : child
265- for child in children]
269+ children = [
270+ isexpr (child, Int, Integer) ? :(RuleNode ($ child)) : child
271+ for child in children
272+ ]
266273 return :([$ (children... )])
267274 end
268275
@@ -303,7 +310,7 @@ Hole[Bool[1, 1, 0, 0]]
303310```
304311"""
305312macro rulenode (ex:: Union{Integer, Expr} )
306- _shorthand2rulenode (ex)
313+ return _shorthand2rulenode (ex)
307314end
308315
309316"""
@@ -325,16 +332,16 @@ RuleNode(ind::Int, _val::Any) = RuleNode(ind, _val, AbstractRuleNode[])
325332Base.:(== )(:: RuleNode , :: AbstractHole ) = false
326333Base.:(== )(:: AbstractHole , :: RuleNode ) = false
327334function Base.:(== )(A:: RuleNode , B:: RuleNode )
328- (A. ind == B. ind) &&
335+ return (A. ind == B. ind) &&
329336 length (A. children) == length (B. children) && # required because zip doesn't check lengths
330337 all (isequal (a, b) for (a, b) in zip (A. children, B. children))
331338end
332339function Base.:(== )(a:: UniformHole , b:: UniformHole )
333- a. domain == b. domain && length (a. children) == length (b. children) &&
340+ return a. domain == b. domain && length (a. children) == length (b. children) &&
334341 all (isequal (a, b) for (a, b) in zip (a. children, b. children))
335342end
336- function Base.:(== )(a:: H , b:: H ) where H <: AbstractHole
337- a. domain == b. domain
343+ function Base.:(== )(a:: H , b:: H ) where { H <: AbstractHole }
344+ return a. domain == b. domain
338345end
339346
340347
@@ -356,18 +363,18 @@ end
356363
357364function Base. show (io:: IO , node:: RuleNode ; separator = " ," )
358365 print (io, node. ind)
359- if ! isempty (children (node))
366+ return if ! isempty (children (node))
360367 Base. show_enclosed_list (io, " {" , children (node), separator, " }" , 0 )
361368 end
362369end
363370
364371function Base. show (io:: IO , node:: AbstractHole ; _... )
365- print (io, " Hole[$(node. domain) ]" )
372+ return print (io, " Hole[$(node. domain) ]" )
366373end
367374
368375function Base. show (io:: IO , node:: UniformHole ; separator = " ," )
369376 print (io, " UniformHole[$(node. domain) ]" )
370- if ! isempty (node. children)
377+ return if ! isempty (node. children)
371378 Base. show_enclosed_list (io, " {" , children (node), separator, " }" , 0 )
372379 end
373380end
@@ -396,8 +403,10 @@ performed in both [`RuleNode`](@ref)s until nodes with a different index
396403are found.
397404"""
398405Base. isless (
399- rn₁:: AbstractRuleNode , rn₂:: AbstractRuleNode ):: Bool = _rulenode_compare (
400- rn₁, rn₂) == - 1
406+ rn₁:: AbstractRuleNode , rn₂:: AbstractRuleNode
407+ ):: Bool = _rulenode_compare (
408+ rn₁, rn₂
409+ ) == - 1
401410
402411function _rulenode_compare (rn₁:: AbstractRuleNode , rn₂:: AbstractRuleNode ):: Int
403412 # Helper function for Base.isless
@@ -461,8 +470,10 @@ Returns every rule in the ruleset that is also used in the [`AbstractRuleNode`](
461470!!! warning
462471 The `ignoreNode` must be a subtree of `node` for it to have an effect.
463472"""
464- function rulesoftype (node:: RuleNode , ruleset:: Set{Int} ,
465- ignoreNode:: Union{Nothing, AbstractRuleNode} = nothing ):: Set{Int}
473+ function rulesoftype (
474+ node:: RuleNode , ruleset:: Set{Int} ,
475+ ignoreNode:: Union{Nothing, AbstractRuleNode} = nothing
476+ ):: Set{Int}
466477 retval = Set {Int} ()
467478
468479 if ! isnothing (ignoreNode) && node == ignoreNode
@@ -483,9 +494,11 @@ function rulesoftype(node::RuleNode, ruleset::Set{Int},
483494 return retval
484495 end
485496end
486- function rulesoftype (node:: RuleNode , rule_index:: Int ,
487- ignoreNode:: Union{Nothing, AbstractRuleNode} = nothing )
488- rulesoftype (node, Set {Int} (rule_index), ignoreNode)
497+ function rulesoftype (
498+ node:: RuleNode , rule_index:: Int ,
499+ ignoreNode:: Union{Nothing, AbstractRuleNode} = nothing
500+ )
501+ return rulesoftype (node, Set {Int} (rule_index), ignoreNode)
489502end
490503
491504rulesoftype (:: Hole , :: Vararg{Any} ) = Set {Int} ()
@@ -503,9 +516,10 @@ function rulesoftype(
503516 grammar:: AbstractGrammar ,
504517 ruletype:: Symbol ,
505518 ignoreNode:: Union{Nothing, RuleNode} = nothing
506- )
507- rulesoftype (
508- node, Set (grammar[ruletype]), ignoreNode)
519+ )
520+ return rulesoftype (
521+ node, Set (grammar[ruletype]), ignoreNode
522+ )
509523end
510524
511525"""
514528Returns true if the rulenode contains the index.
515529"""
516530function contains_index (rulenode:: AbstractRuleNode , index:: Int )
517- ! isempty (rulesoftype (
518- rulenode, index))
531+ return ! isempty (
532+ rulesoftype (
533+ rulenode, index
534+ )
535+ )
519536end
520537
521538"""
@@ -525,7 +542,7 @@ Replace a node in `expr`, specified by `path`, with `new_expr`.
525542Path is a sequence of child indices, starting from the root node.
526543"""
527544function swap_node (expr:: AbstractRuleNode , new_expr:: AbstractRuleNode , path:: Vector{Int} )
528- if length (path) == 1
545+ return if length (path) == 1
529546 expr. children[path[begin ]] = new_expr
530547 else
531548 swap_node (expr. children[path[begin ]], new_expr, path[2 : end ])
538555Replace child `i` of a node, a part of larger `expr`, with `new_expr`.
539556"""
540557function swap_node (expr:: RuleNode , node:: RuleNode , child_index:: Int , new_expr:: RuleNode )
541- if expr == node
558+ return if expr == node
542559 node. children[child_index] = new_expr
543560 else
544561 for child in expr. children
@@ -554,7 +571,7 @@ Extract the derivation sequence from a path (sequence of child indices) and an [
554571If the path is deeper than the deepest node, it returns what it has.
555572"""
556573function get_rulesequence (node:: RuleNode , path:: Vector{Int} )
557- if node. ind == 0 # sign for empty node
574+ if node. ind == 0 # sign for empty node
558575 return Vector {Int} ()
559576 elseif isempty (node. children) # no childnen, nowehere to follow the path; still return the index
560577 return [node. ind]
@@ -563,13 +580,17 @@ function get_rulesequence(node::RuleNode, path::Vector{Int})
563580 elseif isassigned (path, 2 )
564581 # at least two items are left in the path
565582 # need to access the child with get because it can happen that the child is not yet built
566- return append! ([node. ind],
567- get_rulesequence (get (node. children, path[begin ], RuleNode (0 )), path[2 : end ]))
583+ return append! (
584+ [node. ind],
585+ get_rulesequence (get (node. children, path[begin ], RuleNode (0 )), path[2 : end ])
586+ )
568587 else
569588 # if only one item left in the path
570589 # need to access the child with get because it can happen that the child is not yet built
571- return append! ([node. ind],
572- get_rulesequence (get (node. children, path[begin ], RuleNode (0 )), Vector {Int} ()))
590+ return append! (
591+ [node. ind],
592+ get_rulesequence (get (node. children, path[begin ], RuleNode (0 )), Vector {Int} ())
593+ )
573594 end
574595end
575596
642663Returns the path from the `root` to the `targetnode`. Returns nothing if no path exists.
643664"""
644665function get_path (
645- root:: AbstractRuleNode , targetnode:: AbstractRuleNode ):: Union{Vector{Int}, Nothing}
666+ root:: AbstractRuleNode , targetnode:: AbstractRuleNode
667+ ):: Union{Vector{Int}, Nothing}
646668 if root === targetnode
647669 return Vector {Int} ()
648670 end
@@ -661,11 +683,12 @@ end
661683Recursively counts the number of holes in an [`AbstractRuleNode`](@ref)
662684"""
663685function number_of_holes (rn:: RuleNode )
664- reduce (
665- + , [number_of_holes (c) for c in rn. children], init = 0 )
686+ return reduce (
687+ + , [number_of_holes (c) for c in rn. children], init = 0
688+ )
666689end
667690function number_of_holes (rn:: UniformHole )
668- 1 + reduce (+ , [number_of_holes (c) for c in rn. children], init = 0 )
691+ return 1 + reduce (+ , [number_of_holes (c) for c in rn. children], init = 0 )
669692end
670693number_of_holes (rn:: Hole ) = 1
671694
@@ -683,8 +706,10 @@ contains_hole(hole::AbstractHole) = true
683706Checks if an [`AbstractRuleNode`](@ref) tree contains a [`Hole`](@ref).
684707"""
685708function contains_nonuniform_hole (rn:: AbstractRuleNode )
686- any (contains_nonuniform_hole (c)
687- for c in rn. children)
709+ return any (
710+ contains_nonuniform_hole (c)
711+ for c in rn. children
712+ )
688713end
689714contains_nonuniform_hole (hole:: Hole ) = true
690715
0 commit comments