ometa htmlLex {
elem = text | comment | script | unitag | tag2 | tag,
html = elem+,
tag2 = tag:t html:h '<' '/' seq(t[0]) '>' -> [t[0],t[1],h],
comment = spaces seq('') anything)*:c seq('-->') -> ['#', c.join('')],
word = spaces (letterOrDigit | '_' | '$')+:w -> w.join(''),
qstr = spaces ('"' | '\''):q (~exactly(q) char)*:s exactly(q) -> s.join(''),
attr = word:k spaces '=' qstr:v -> [k,v],
attr = word:k spaces '=' word:v -> [k,v],
attr = word:k -> [k,k],
scriptstart = seq('') anything)*:s seq('') spaces -> ['js',s.join('')],
unitag = '<' word:tn attr*:a spaces '/' spaces '>' -> [tn,a],
tag = '<' word:tn attr*:a spaces '>' -> [tn, a],
text = (~'<' char)+:t -> ['txt',t.join('')]
}
txt="
this is the \
\
first \
attempt.\
I will be ok.
"
tree=htmlLex.matchAll(txt,'html')
[[p, [], [[txt, this is the
], [b, [[sql, test]], [[txt,
first ], [js, test ]]], [txt, attempt.
], [br, [[sql, test 2]]], [txt, I will be ok.
]]]]
ometa getSql {
has :n = [[~exactly(n) anything*]* [exactly(n) anything+:r] anything*] -> r,
sqltag = [:tn has('sql'):sql has('js'):script] -> [tn, sql[0], script[0]]
| [:tn has('sql'):sql anything*] -> [tn, sql[0]],
elems = elem+,
elem = sqltag
| [ :tn :a elems:e ] -> ['~', tn, a, e]
| [ :tn :v ] -> ['-', tn, v]
| [ elems:e ] -> e
}
getSql.match(tree,'elems')
[[~, p, [], [[~, [txt, this is the
], [b, [[sql, test]], [[txt,
first ], [js, test ]]], [[-, txt, attempt.
], [br, test 2], [-, txt, I will be ok.
]]]]]]
tree
getSql.match(['p',[['sql','test']], [['txt','woof']]], 'elems')
getSql.match(['p',[['sql','test']], [['txt','woof'],['js','bark']]], 'sqltag') [p, test, bark]