Page Menu
Home
Xreate
Search
Configure Global Search
Log In
Docs
Questions
Repository
Issues
Patches
Internal API
Files
F2730827
regexps.xreate
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Mar 14, 1:16 AM
Size
1 KB
Mime Type
text/plain
Expires
Mon, Mar 16, 1:16 AM (1 d, 10 h)
Engine
blob
Format
Raw Data
Handle
243679
Attached To
rXR Xreate
regexps.xreate
View Options
===========================
DATA
patternAB = [Sequence,
[[ZeroOrMore, "a"],
[Text, "b"]]].
==========================
HANDLERS
Matcher = type variant (Sequence, ZeroOrMore, Text)
matchSequence = function(text::string, sequence::undef):: int{
textLength = length(text):: int.
loop fold(sequence-> matcher:: undef, 0->pos){
n = match(mid(text, pos, textLength), matcher).
if (n == pos_FAIL:: break){
pos
} else {
pos+n
}
}
}
matchZeroOrMore= function(text::string, matcher::string):: int{
textLength = length(text):: int.
loop fold inf(0->pos, n==pos_FAIL){ //<--- infinite loop?
n = match(matcherChild, mid(text, pos, textLength)).
if (n == pos_FAIL:: break){
pos
} else {
pos+n
}
}
}
matchText = function(text::string, matcher::string):: int {
textLength = length(text):: int.
if (length(matcher) <= textLength, mid(text, 0, length(matcher)) == matcher)
{
textLength;
} else {
pos_FAIL;
}
}
match = function(text::string, pattern::undef)::string{
n = switch (pattern[0]) :: int
case (Sequence) {matchSequence(text, pattern[1])}
case (ZeroOrMore) {matchZeroOrMore(text, pattern[1])}
case (Text) {matchText(text, pattern[1])}
case default {pos_FAIL}
if (n != pos_FAIL)
{mid(text, 0, n)}
else
{text_FAIL}
}
=================================
CLIENT
test = function(){
match(patternAB, "aaaaab").
match(patternAB, "baaaaa").
}
Event Timeline
Log In to Comment