implementing regex system from Software Design for Flexibility

This commit is contained in:
2021-10-26 22:53:11 -04:00
commit 598891af43
9 changed files with 72 additions and 0 deletions

1
LICENSE Normal file
View 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
View File

@@ -0,0 +1,4 @@
re-flex
-------
Utilities for regex construction adapted from Software Design for Flexibility.

4
build.hxml Normal file
View File

@@ -0,0 +1,4 @@
-lib kiss
-cp src
--main re_flex.Main
--interp

16
haxelib.json Normal file
View 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
View 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
View File

@@ -0,0 +1 @@
(print "Hello world!")

7
src/re_flex/R.hx Normal file
View 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
View 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 "")))))))

3
test.sh Normal file
View File

@@ -0,0 +1,3 @@
#! /bin/bash
haxe build.hxml