aboutsummaryrefslogtreecommitdiff
path: root/compiler/standardClient.ey
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/standardClient.ey')
-rw-r--r--compiler/standardClient.ey113
1 files changed, 43 insertions, 70 deletions
diff --git a/compiler/standardClient.ey b/compiler/standardClient.ey
index bf13051..49cc4c4 100644
--- a/compiler/standardClient.ey
+++ b/compiler/standardClient.ey
@@ -423,52 +423,33 @@
# regex support
# ideas taken from http://swtch.com/~rsc/regexp/regexp3.html
{
- 0 ==currentCapture
+ 0 ==MATCH 1 ==TERM 2 ==JUMP 3 ==SPLIT 4 ==SAVE
- { ==b ==a
- [
- [ /SPLIT 1 a len 1 add ]
- a _ len dearray
- [ /JUMP b len ]
- b _ len dearray
- ]
- } /alternative deff
-
- { ==b ==a
- a b cat
- } /sequence deff
-
- { ==a
- [
- a _ len dearray
- [ /SPLIT a len neg 1 ]
- ]
- } /star deff
-
- { ==p
- [
- [ /TERM p ]
- ]
- } /terminal deff
-
- { ==a
- [
- a _ len dearray
- [ /MATCH ]
- ]
- } /final deff
-
- { ==i ==a
- [
- [ /SAVE i 2 mul ]
- a _ len dearray
- [ /SAVE i 2 mul 1 add ]
- ]
- } /capture deff
+ { ==b ==a [
+ [ SPLIT 1 a len 1 add ]
+ a _ len dearray
+ [ JUMP b len ]
+ b _ len dearray
+ ] } /alternative deff
- {
- [ ]
- } /empty deff
+ |cat /sequence deff
+
+ { ==a [
+ a _ len dearray
+ [ SPLIT a len neg 1 ]
+ ] } /star deff
+
+ { ==p [
+ [ TERM p ]
+ ] } /terminal deff
+
+ { ==i ==a [
+ [ SAVE i 2 mul ]
+ a _ len dearray
+ [ SAVE i 2 mul 1 add ]
+ ] } /capture deff
+
+ { [ ] } /empty deff
{ ==str
str len 0 eq {
@@ -478,9 +459,7 @@
} ? *
} /head deff
- { ==s
- 1 s str .postfix
- } /tail deff
+ { 1 -01 str .postfix } /tail deff
{ deff }' /install deff
[ "(" ")" "[" "]" "-" "|" "^" "*" "." ] { ==c
@@ -526,6 +505,8 @@
{ i t e ? * }
} /ifthenelse deff
+ 0 ==currentCapture
+
{ # ==re
# "(atom) re: " re cat dump
empty ==a
@@ -659,33 +640,24 @@
i clist .get _ =thread
.pc _ ==pc
prog * =*code
- [
- 0 code /MATCH streq
- {
+ 0 code [
+ { # MATCH
1 =matched
clist .clear
- }
- 0 code /TERM streq
- {
+ } { # TERM
position maxPosition lt {
position string * 1 code * { pc 1 add thread cloneThread nlist .add } rep
} rep
- }
- 0 code /JUMP streq
- { pc 1 code add thread cloneThread clist .add }
- 0 code /SPLIT streq
- {
+ } { # JUMP
+ pc 1 code add thread cloneThread clist .add
+ } { # SPLIT
pc 1 code add thread cloneThread clist .add
pc 2 code add thread cloneThread clist .add
- }
- 0 code /SAVE streq
- {
+ } { # SAVE
position 1 code thread .captures =[]
pc 1 add thread cloneThread clist .add
}
- 1
- { |code dump "unsupported regex-VM instruction" die }
- ] conds
+ ] * *
i 1 add =i
} loop
@@ -705,13 +677,14 @@
matched
} /execute deff
- parse
+ parse ==prog --
[
- [ /SPLIT 3 1 ]
- [ /TERM { -- 1 } ]
- [ /JUMP 2 neg ]
- ] -01 cat
- final ==prog --
+ [ SPLIT 3 1 ]
+ [ TERM { -- 1 } ]
+ [ JUMP 2 neg ]
+ prog _ len dearray
+ [ MATCH ]
+ ] =prog
{ prog execute }
} /enregex deff