3 ms·
Can we do submatch addressing with derivatives? I think the answer is yes: extend the definition of an expression to include a recorder R(re,recorded-string) s
by jhallenworld 11y ago
Can we do submatch addressing with derivatives?
I think the answer is yes: extend the definition of an expression to include a recorder R(re,recorded-string) such that D(R(re,),c) -> R(D(re,c),c) -> R(re1,c). D(R(re1,c),d) -> R(D(re1,d),cd) -> R(re2,cd). Eventually you have R(,string), the recorded sub-matched string.
Checking each of the rules with it...
D(R(∅,s),c) -> ∅.
D(R(ε,s),c) -> ∅.
D(R(c,s),c) -> R(ε,sc).
D(R(c,s),d) -> ∅.
D(R(re,s),c) -> R(D(re,c),sc):
D(R(re1,s1)R(re2,s2),c) -> δ(R(re1,s))R(D(re2,c),s2c) | R(D(re1,c),s1c)R(re2,s2).
D(R(re1,s1)|R(re2,s2),c) -> D(R(re1,s1),c)|D(R(re2,s2),c).
D(R(re*,s),c) -> R(D(re*,c),sc).
R(∅,s) -> ∅.
δ(R(∅,s)) -> ∅.
δ(R(ε,s)) -> R(ε,s).
δ(R(re*,s)) -> R(ε,s).
δ(R(re1,s1)R(re2,s2)) -> δ(R(re1,s1))δ(R(re2,s2)).
δ(R(re1,s1)|R(re2,s2)) -> δ(R(re1,s1))|δ(R(re2,s2)).
I think it's good: when the input is done, you have a match only if the AST is only made up of R(ε,s1)R(ε,s2)...