implementing regex system from Software Design for Flexibility
This commit is contained in:
1
LICENSE
Normal file
1
LICENSE
Normal file
@@ -0,0 +1 @@
|
||||
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
|
4
README.md
Normal file
4
README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
re-flex
|
||||
-------
|
||||
|
||||
Utilities for regex construction adapted from Software Design for Flexibility.
|
4
build.hxml
Normal file
4
build.hxml
Normal file
@@ -0,0 +1,4 @@
|
||||
-lib kiss
|
||||
-cp src
|
||||
--main re_flex.Main
|
||||
--interp
|
16
haxelib.json
Normal file
16
haxelib.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"main": "re_flex.Main",
|
||||
"name": "re-flex",
|
||||
"description": "",
|
||||
"classPath": "src/",
|
||||
"dependencies": {
|
||||
"kiss": ""
|
||||
},
|
||||
"url": "https://github.com/NQNStudios/kisslang",
|
||||
"contributors": [
|
||||
"NQNStudios"
|
||||
],
|
||||
"version": "0.0.0",
|
||||
"releasenote": "",
|
||||
"tags": []
|
||||
}
|
7
src/re_flex/Main.hx
Normal file
7
src/re_flex/Main.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package re_flex;
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.Prelude;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class Main {}
|
1
src/re_flex/Main.kiss
Normal file
1
src/re_flex/Main.kiss
Normal file
@@ -0,0 +1 @@
|
||||
(print "Hello world!")
|
7
src/re_flex/R.hx
Normal file
7
src/re_flex/R.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package re_flex;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class R {}
|
29
src/re_flex/R.kiss
Normal file
29
src/re_flex/R.kiss
Normal file
@@ -0,0 +1,29 @@
|
||||
(var anyChar ".")
|
||||
(var start "^")
|
||||
(var end "\$")
|
||||
|
||||
(function :String _group [:Array<Dynamic> exprs]
|
||||
(+ "(" (apply + exprs) ")"))
|
||||
|
||||
(var group (Reflect.makeVarArgs _group))
|
||||
|
||||
(function :String escape [:String str]
|
||||
(group (EReg.escape str)))
|
||||
|
||||
(function :String _oneOf [:Array<Dynamic> exprs]
|
||||
(group (exprs.join "|")))
|
||||
|
||||
(var oneOf (Reflect.makeVarArgs _oneOf))
|
||||
|
||||
(function :String repeat [:String expr &opt :Int min :Int max]
|
||||
(apply group
|
||||
(concat
|
||||
(for _ (range min) expr)
|
||||
(cond
|
||||
// unlimited repetitions after minimum if max is null:
|
||||
(!max
|
||||
[(group expr) "*"])
|
||||
((= max min)
|
||||
[])
|
||||
(true
|
||||
(for _ (range (- max min)) (oneOf expr "")))))))
|
Reference in New Issue
Block a user