]> gitweb.factorcode.org Git - factor.git/commitdiff
Add 'easy-help.expand-markup'
authorEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Wed, 24 Dec 2008 09:13:28 +0000 (03:13 -0600)
committerEduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Wed, 24 Dec 2008 09:13:28 +0000 (03:13 -0600)
extra/easy-help/expand-markup/expand-markup.factor [new file with mode: 0644]

diff --git a/extra/easy-help/expand-markup/expand-markup.factor b/extra/easy-help/expand-markup/expand-markup.factor
new file mode 100644 (file)
index 0000000..7550158
--- /dev/null
@@ -0,0 +1,47 @@
+
+USING: accessors arrays kernel lexer locals math namespaces parser
+       sequences splitting ;
+
+IN: easy-help.expand-markup
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: scan-one-array ( string -- array rest )
+  string-lines
+  lexer-factory get call
+  [
+  [
+    \ } parse-until >array
+    lexer get line-text>>
+    lexer get column>> tail
+  ]
+  with-lexer
+  ]
+  with-scope ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: contains-markup? ( string -- ? ) "{ $" swap subseq? ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+:: expand-markup ( LINE -- lines )
+  
+  LINE contains-markup?
+    [
+    
+      [let | N [ "{ $" LINE start ] |
+
+        LINE N head
+
+        LINE N 2 + tail scan-one-array  dup " " head? [ 1 tail ] [ ] if
+
+        [ 2array ] dip
+
+        expand-markup
+
+        append ]
+        
+    ]
+    [ LINE 1array ]
+  if ;