@@ -107,32 +107,34 @@ function matcher(segment::Segment)
107
107
end
108
108
109
109
function term_matcher_constructor (term)
110
- matchers = ( matcher (operation (term)), map (matcher, arguments (term))... , )
110
+ matchers = vcat ([ matcher (operation (term))] , map (matcher, parent ( arguments (term))) )
111
111
112
- function term_matcher (success, data, bindings)
113
- ! islist (data) && return nothing # if data is not a list, return nothing
114
- ! iscall (car (data)) && return nothing # if first element is not a call, return nothing
112
+ let matchers = matchers
113
+ function term_matcher (success, data, bindings)
114
+ ! islist (data) && return nothing # if data is not a list, return nothing
115
+ ! iscall (car (data)) && return nothing # if first element is not a call, return nothing
115
116
116
- function loop (term, bindings′, matchers′) # Get it to compile faster
117
- if ! islist (matchers′)
118
- if ! islist (term)
119
- return success (bindings′, 1 )
117
+ function loop (term, bindings′, matchers′) # Get it to compile faster
118
+ if ! islist (matchers′)
119
+ if ! islist (term)
120
+ return success (bindings′, 1 )
121
+ end
122
+ return nothing
120
123
end
121
- return nothing
122
- end
123
- car (matchers′)(term, bindings′) do b, n
124
- loop (drop_n (term, n), b, cdr (matchers′))
124
+ car (matchers′)(term, bindings′) do b, n
125
+ loop (drop_n (term, n), b, cdr (matchers′))
126
+ end
127
+ # explenation of above 3 lines:
128
+ # car(matchers′)(b,n -> loop(drop_n(term, n), b, cdr(matchers′)), term, bindings′)
129
+ # <------ next(b,n) ---------------------------->
130
+ # car = first element of list, cdr = rest of the list, drop_n = drop first n elements of list
131
+ # Calls the first matcher, with the "next" function being loop again but with n terms dropepd from term
132
+ # Term is a linked list (a list and a index). drop n advances the index. when the index sorpasses
133
+ # the length of the list, is considered empty
125
134
end
126
- # explenation of above 3 lines:
127
- # car(matchers′)(b,n -> loop(drop_n(term, n), b, cdr(matchers′)), term, bindings′)
128
- # <------ next(b,n) ---------------------------->
129
- # car = first element of list, cdr = rest of the list, drop_n = drop first n elements of list
130
- # Calls the first matcher, with the "next" function being loop again but with n terms dropepd from term
131
- # Term is a linked list (a list and a index). drop n advances the index. when the index sorpasses
132
- # the length of the list, is considered empty
133
- end
134
135
135
- loop (car (data), bindings, matchers) # Try to eat exactly one term
136
+ loop (car (data), bindings, matchers) # Try to eat exactly one term
137
+ end
136
138
end
137
139
end
138
140
149
151
# calls the success function like term_matcher would do
150
152
151
153
function defslot_term_matcher_constructor (term)
152
- a = arguments (term) # lenght two bc defslot term matcher is allowed only with +,* and ^, that accept two arguments
154
+ a = parent ( arguments (term) ) # lenght two bc defslot term matcher is allowed only with +,* and ^, that accept two arguments
153
155
matchers = (matcher (operation (term)), map (matcher, a)... ) # create matchers for the operation and the two arguments of the term
154
156
155
157
defslot_index = findfirst (x -> isa (x, DefSlot), a) # find the defslot in the term
0 commit comments