]> gitweb.factorcode.org Git - factor.git/commitdiff
XMode doesn't use parser combinators at all; regexes allow parens for grouping
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Fri, 13 Feb 2009 02:42:32 +0000 (20:42 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Fri, 13 Feb 2009 02:42:32 +0000 (20:42 -0600)
basis/regexp/nfa/nfa.factor
basis/xmode/catalog/catalog.factor
basis/xmode/loader/loader.factor
basis/xmode/loader/syntax/syntax.factor
basis/xmode/marker/marker.factor
basis/xmode/utilities/utilities-tests.factor
basis/xmode/utilities/utilities.factor

index 537c85c2d3b20acfd305a3903bab4b27a3a08667..44481454fcf885143ef6a2a429ef4ade95ddc6fe 100644 (file)
@@ -183,15 +183,8 @@ M: character-class-range nfa-node ( node -- )
     ] if ;
 
 M: capture-group nfa-node ( node -- )
-    "capture-groups" feature-is-broken
-    eps literal-transition add-simple-entry
-    capture-group-on add-traversal-flag
-    term>> nfa-node
-    eps literal-transition add-simple-entry
-    capture-group-off add-traversal-flag
-    2 [ concatenate-nodes ] times ;
+    term>> nfa-node ;
 
-! xyzzy
 M: non-capture-group nfa-node ( node -- )
     term>> nfa-node ;
 
index 3a87d71d58b065678a84f6880f15a32e855d7dc4..b08e47ddc56e96b6e138c2bc1b547fe20dfb9aa9 100644 (file)
@@ -1,7 +1,7 @@
 USING: xmode.loader xmode.utilities xmode.rules namespaces
 strings splitting assocs sequences kernel io.files xml memoize
 words globs combinators io.encodings.utf8 sorting accessors xml.data
-xml.traversal ;
+xml.traversal xml.syntax ;
 IN: xmode.catalog
 
 TUPLE: mode file file-name-glob first-line-glob ;
@@ -97,8 +97,8 @@ ERROR: mutually-recursive-rulesets ruleset ;
     ] if ;
 
 : finalize-mode ( rulesets -- )
-    rule-sets [
-        dup [ nip finalize-rule-set ] assoc-each
+    dup rule-sets [
+        [ nip finalize-rule-set ] assoc-each
     ] with-variable ;
 
 : load-mode ( name -- rule-sets )
index 61b60b52924d809f3299ea4a31314188883f8dc9..d6f3943e145627c452ceb76a16e459ce0d033ee4 100644 (file)
@@ -1,7 +1,7 @@
 USING: xmode.loader.syntax xmode.tokens xmode.rules
 xmode.keyword-map xml.data xml.traversal xml assocs kernel
 combinators sequences math.parser namespaces parser
-xmode.utilities regexp io.files accessors ;
+xmode.utilities regexp io.files accessors xml.syntax ;
 IN: xmode.loader
 
 ! Based on org.gjt.sp.jedit.XModeHandler
@@ -48,7 +48,7 @@ TAG: KEYWORDS parse-rule-tag
     swap (>>keywords) ;
 
 : ?<regexp> ( string/f -- regexp/f )
-    dup [ rule-set get ignore-case?>> drop <regexp> ] when ;
+    dup [ rule-set get ignore-case?>> <?insensitive-regexp> ] when ;
 
 : (parse-rules-tag) ( tag -- rule-set )
     <rule-set> dup rule-set set
index 88ff7b919b6744145bcfb60d937c455c79bc3203..60318e669e7fea9cffb97649a07d07c21a2236d7 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors xmode.tokens xmode.rules xmode.keyword-map
 xml.data xml.traversal xml assocs kernel combinators sequences
 math.parser namespaces make parser lexer xmode.utilities
-regexp io.files splitting arrays xml.syntax.private ;
+regexp io.files splitting arrays xml.syntax xml.syntax.private ;
 IN: xmode.loader.syntax
 
 ! Rule tag parsing utilities
@@ -11,10 +11,10 @@ IN: xmode.loader.syntax
     new swap init-from-tag swap add-rule ; inline
 
 : RULE:
-    scan scan-word scan-word
-    parse-definition { } make
-    [ swap [ (parse-rule-tag) ] 2curry ] dip
-    swap define-tag ; parsing
+    scan scan-word scan-word [
+        parse-definition { } make
+        swap [ (parse-rule-tag) ] 2curry
+    ] dip swap define-tag ; parsing
 
 ! Attribute utilities
 : string>boolean ( string -- ? ) "TRUE" = ;
@@ -47,7 +47,8 @@ IN: xmode.loader.syntax
     swap position-attrs <matcher> ;
 
 : parse-regexp-matcher ( tag -- matcher )
-    dup children>string rule-set get ignore-case?>> drop <regexp>
+    dup children>string
+    rule-set get ignore-case?>> <?insensitive-regexp>
     swap position-attrs <matcher> ;
 
 : shared-tag-attrs ( -- )
index 5cbd9e1e9c99e3d6cc51f29ea9254337a94125f1..e106af79526eb2209de8a46fe9cbeb419df22c04 100755 (executable)
@@ -4,11 +4,25 @@ IN: xmode.marker
 USING: kernel namespaces make xmode.rules xmode.tokens
 xmode.marker.state xmode.marker.context xmode.utilities
 xmode.catalog sequences math assocs combinators strings
-regexp splitting ascii parser-combinators regexp.backend
+regexp splitting ascii regexp.backend unicode.case
 ascii combinators.short-circuit accessors ;
-! parser-combinators is for the string-head? word
 ! regexp.backend is for the regexp class
 
+! Next two words copied from parser-combinators
+! Just like head?, but they optionally ignore case
+
+: string= ( str1 str2 ignore-case -- ? )
+    [ [ >upper ] bi@ ] when sequence= ;
+
+: string-head? ( str1 str2 ignore-case -- ? )
+    2over shorter?
+    [ 3drop f ] [
+        [
+            [ nip ]
+            [ length head-slice ] 2bi
+        ] dip string=
+    ] if ;
+
 ! Based on org.gjt.sp.jedit.syntax.TokenMarker
 
 : current-keyword ( -- string )
index 45238ca2b18bcf1e0688b52f21c88f9b1211873a..0ef221f23732e44d69fde9a44ddd316f5c9d1015 100644 (file)
@@ -1,7 +1,6 @@
+USING: assocs xmode.utilities tools.test ;
 IN: xmode.utilities.tests
-USING: accessors xmode.utilities tools.test xml xml.data kernel
-strings vectors sequences io.files prettyprint assocs
-unicode.case ;
+
 [ "hi" 3 ] [
     { 1 2 3 4 5 6 7 8 } [ H{ { 3 "hi" } } at ] map-find
 ] unit-test
@@ -9,44 +8,3 @@ unicode.case ;
 [ f f ] [
     { 1 2 3 4 5 6 7 8 } [ H{ { 11 "hi" } } at ] map-find
 ] unit-test
-
-TUPLE: company employees type ;
-
-: <company> V{ } clone f company boa ;
-
-: add-employee employees>> push ;
-
-<TAGS: parse-employee-tag
-
-TUPLE: employee name description ;
-
-TAG: employee
-    employee new
-    { { "name" f (>>name) } { f (>>description) } }
-    init-from-tag swap add-employee ;
-
-TAGS>
-
-\ parse-employee-tag see
-
-: parse-company-tag
-    [
-        <company>
-        { { "type" >upper (>>type) } }
-        init-from-tag dup
-    ] keep
-    children>> [ tag? ] filter
-    [ parse-employee-tag ] with each ;
-
-[
-    T{ company f
-        V{
-            T{ employee f "Joe" "VP Sales" }
-            T{ employee f "Jane" "CFO" }
-        }
-        "PUBLIC"
-    }
-] [
-    "resource:basis/xmode/utilities/test.xml"
-    file>xml parse-company-tag
-] unit-test
index 22db69de3f2b5ae61ab861ec0e8c3dd53b4124ad..1b2b4a352ffede5c44296ae15e3f370b1f3bd4c7 100644 (file)
@@ -1,5 +1,6 @@
 USING: accessors sequences assocs kernel quotations namespaces
-xml.data xml.traversal combinators macros parser lexer words fry ;
+xml.data xml.traversal combinators macros parser lexer words fry
+regexp ;
 IN: xmode.utilities
 
 : implies ( x y -- z ) [ not ] dip or ; inline
@@ -35,3 +36,6 @@ MACRO: (init-from-tag) ( specs -- )
 
 : init-from-tag ( tag tuple specs -- tuple )
     over [ (init-from-tag) ] dip ; inline
+
+: <?insensitive-regexp> ( string ? -- regexp )
+    "i" "" ? <optioned-regexp> ;