Category talk:Wren-pattern: Difference between revisions

m
→‎Source code: Now uses Wren S/H lexer.
(Added limited support for 'quantified group' matches.)
m (→‎Source code: Now uses Wren S/H lexer.)
 
(3 intermediate revisions by the same user not shown)
Line 1:
===Wren patterns===
 
Wren doesn't have direct access to a regular expression library (but see Wren-regex section below) and writing such a library from scratch in a small scripting language such as Wren may not be a viable proposition due to its likely size and performance limitations.
 
I have therefore designed and coded a simple pattern matcher instead, the rules of which are described below. Obviously, this has nothing like the full power of regular expressions but I hope it will nevertheless be a useful addition to the armory.
Line 199:
 
A different and usually better approach is to use the 'findWithGroup' or 'findWithGroup2' methods. These work in an analogous way to the 'findLazy' and 'findLazy2' methods. However, this time '/Z' and '&Z' respectively match the parameter strings 't' and 'u' themselves rather than any characters other than these strings and we can therefore quantify them as though they were 'singles'.
 
;Wren-regex
Since this module was written, I've created a Wren-regex module which wraps Go's 'regexp' package. Whilst this addresses some shortcomings in Wren-pattern, it requires a special Go executable to use it and doesn't therefore work with Wren-cli.
 
===Source code===
<langsyntaxhighlight ecmascriptlang="wren">/* Module "pattern.wren" */
 
/* Match represents a single successful match made by methods in the Pattern class.
Line 1,101 ⟶ 1,104:
}
 
Pattern.init_()</langsyntaxhighlight>
9,479

edits