]> gitweb.factorcode.org Git - factor.git/commitdiff
new accessors
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 31 Aug 2008 02:59:46 +0000 (21:59 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 31 Aug 2008 02:59:46 +0000 (21:59 -0500)
extra/fjsc/fjsc.factor
extra/json/reader/reader.factor
extra/parser-combinators/parser-combinators.factor
extra/peg/ebnf/ebnf.factor

index 5f1f977d20ca47e8017c331606704a9fe3c96b6e..e12092603af4ab12d9911923f83a5c93dae77482 100755 (executable)
@@ -353,11 +353,11 @@ M: quotation fjsc-parse ( object -- ast )
   ] with-string-writer ;
 
 : fjsc-compile* ( string -- string )
-  'statement' parse parse-result-ast fjsc-compile ;
+  'statement' parse ast>> fjsc-compile ;
 
 : fc* ( string -- string )
   [
-  'statement' parse parse-result-ast values>> do-expressions
+  'statement' parse ast>> values>> do-expressions
   ] { } make [ write ] each ;
 
 
index 6bd690580405f40a5007384cc713f3b5c446305e..e21b1292e3141e7833e86fe117e2d54ecc035e1c 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel parser-combinators namespaces sequences promises strings 
        assocs math math.parser math.vectors math.functions math.order
-       lists hashtables ascii ;
+       lists hashtables ascii accessors ;
 IN: json.reader
 
 ! Grammar for JSON from RFC 4627
@@ -169,11 +169,12 @@ LAZY: 'value' ( -- parser )
     'array' ,
     'number' ,
   ] [<|>] spaced ;
+ERROR: could-not-parse-json ;
 
 : json> ( string -- object )
   #! Parse a json formatted string to a factor object
   'value' parse dup nil? [ 
-    "Could not parse json" throw
+      could-not-parse-json
   ] [ 
-    car parse-result-parsed 
+    car parsed>> 
   ] if ;
index 2414c1ced38ab4d91123f32b4e89ecc18490a407..a05c140b86e9d8cc974ca02298161a61f41a0b51 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: lists lists.lazy promises kernel sequences strings math
 arrays splitting quotations combinators namespaces
-unicode.case unicode.categories sequences.deep ;
+unicode.case unicode.categories sequences.deep accessors ;
 IN: parser-combinators
 
 ! Parser combinator protocol
@@ -13,11 +13,13 @@ M: promise parse ( input parser -- list )
 
 TUPLE: parse-result parsed unparsed ;
 
+ERROR: cannot-parse input ;
+
 : parse-1 ( input parser -- result )
     dupd parse dup nil? [
-        "Cannot parse " rot append throw
+        rot cannot-parse
     ] [
-        nip car parse-result-parsed
+        nip car parsed>>
     ] if ;
 
 C: <parse-result> parse-result
@@ -26,12 +28,12 @@ C: <parse-result> parse-result
     <parse-result> 1list ;
 
 : parse-result-parsed-slice ( parse-result -- slice )
-    dup parse-result-parsed empty? [
-        parse-result-unparsed 0 0 rot <slice>
+    dup parsed>> empty? [
+        unparsed>> 0 0 rot <slice>
     ] [
-        dup parse-result-unparsed
-        dup slice-from [ rot parse-result-parsed length - ] keep
-        rot slice-seq <slice>
+        dup unparsed>>
+        dup from>> [ rot parsed>> length - ] keep
+        rot seq>> <slice>
     ] if ;
 
 : string= ( str1 str2 ignore-case -- ? )
@@ -132,7 +134,7 @@ TUPLE: and-parser parsers ;
 
 : <&> ( parser1 parser2 -- parser )
     over and-parser? [
-        >r and-parser-parsers r> suffix
+        >r parsers>> r> suffix
     ] [
         2array
     ] if and-parser boa ;
@@ -142,11 +144,11 @@ TUPLE: and-parser parsers ;
 
 : and-parser-parse ( list p1  -- list )
     swap [
-        dup parse-result-unparsed rot parse
+        dup unparsed>> rot parse
         [
-            >r parse-result-parsed r>
-            [ parse-result-parsed 2array ] keep
-            parse-result-unparsed <parse-result>
+            >r parsed>> r>
+            [ parsed>> 2array ] keep
+            unparsed>> <parse-result>
         ] lazy-map-with
     ] lazy-map-with lconcat ;
 
index 9ca8f470bb5249a8615edfb3c0f8aa32391be47a..6e9d78e649a7de9f7424e823ece5a1083360b392 100644 (file)
@@ -508,10 +508,10 @@ M: ebnf-non-terminal (transform) ( ast -- parser )
 \r
 : check-parse-result ( result -- result )\r
   dup [\r
-    dup parse-result-remaining [ blank? ] trim empty? [\r
+    dup remaining>> [ blank? ] trim empty? [\r
       [ \r
         "Unable to fully parse EBNF. Left to parse was: " %\r
-        parse-result-remaining % \r
+        remaining>> % \r
       ] "" make throw\r
     ] unless\r
   ] [\r