aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2018-11-15 16:39:33 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2018-11-15 16:39:33 +0100
commit20058a1f7b67bdbfbc393f08cd968112f0f1c2a8 (patch)
treea08846ead88f438ff7c5fbfe1c6601abf6ae0bec
parentRemove parse.scm. (diff)
downloadtexttv-20058a1f7b67bdbfbc393f08cd968112f0f1c2a8.tar.gz
texttv-20058a1f7b67bdbfbc393f08cd968112f0f1c2a8.tar.xz
Add preliminary parse code.
-rwxr-xr-xscript.scm47
1 files changed, 47 insertions, 0 deletions
diff --git a/script.scm b/script.scm
index c2027b1..b43428d 100755
--- a/script.scm
+++ b/script.scm
@@ -51,6 +51,11 @@
("DH" bold)
(_ identity)))
+(define (push item stack) (cons item stack))
+(define (pop stack) (unless (null? stack)
+ (car+cdr stack)))
+(define (peek stack) (if (null? stack) '() (car stack)))
+
(define (class-handlers class-str)
(fold compose identity
(map classmap (string-split class-str #\space))))
@@ -76,6 +81,28 @@
[,default (format #f "[|~a|]" default)]
))
+;;;
+;;;
+;;;
+
+(define (fmt-tag tag)
+ (sxml-match tag
+ [(a #; (@ (class ,class)) ,text)
+ (underline text)]
+
+ [(h1 (@ (class ,class)) ,nodes ...)
+ ((class-handlers class)
+ (bold (fmt-sub nodes)))]
+
+ [(span (@ (class ,class)) ,nodes ...)
+ ((class-handlers class)
+ (fmt-sub nodes))]
+
+ [,str (guard (string? str)) str]
+
+ [,default (format #f "[|~a|]" default)]
+ ))
+
(define (parse-doc sxml)
(sxml-match sxml
[(*TOP* (div #; (span (@ (class "toprow")) ,top-row ...)
@@ -83,6 +110,26 @@
spans
]))
+'(span (@ (class "B"))
+ "A"
+ (span (@ (class "G"))
+ "B")
+ "C")
+
+;; => (blue A (green B) C)
+;; => set-blue A set-green B unset-green/set-blue C unset-blue
+
+;; push blue : print-esc
+;; print A
+;; push green : print-esc
+;; print B
+;; pop : print-esc
+;; print C
+;; pop : print-esc
+
+
+
+
(define (main args)
(define d (call-with-input-file "100-2.html" xml->sxml))
(display (string-concatenate (map fmt-tag (parse-doc d))))