{
V{ T{ comment { open "<!--" } { payload " comment " } { close "-->" } } }
-} [ [[ <!-- comment --> ]] string>html ] unit-test
\ No newline at end of file
+} [ [[ <!-- comment --> ]] string>html ] unit-test
+
+! From wikipedia factor article
+! https://en.wikipedia.org/w/index.php?title=Factor_(programming_language)&offset=&limit=500&action=history"
+{
+ V{
+ T{ doctype
+ { open "<!DOCTYPE" }
+ { close ">" }
+ { values V{ "html" } }
+ }
+ T{ open-tag
+ { open "<" }
+ { name "html" }
+ { props
+ V{
+ {
+ "class"
+ T{ dquote { payload "client-nojs" } }
+ }
+ { "lang" T{ dquote { payload "en" } } }
+ { "dir" T{ dquote { payload "ltr" } } }
+ }
+ }
+ { close ">" }
+ { children
+ V{
+ T{ open-tag
+ { open "<" }
+ { name "head" }
+ { props V{ } }
+ { close ">" }
+ { children
+ V{
+ T{ open-tag
+ { open "<" }
+ { name "title" }
+ { props V{ } }
+ { close ">" }
+ { children V{ "omg" } }
+ { close-tag
+ T{ close-tag
+ { name "title" }
+ }
+ }
+ }
+ }
+ }
+ { close-tag T{ close-tag { name "head" } } }
+ }
+ T{ open-tag
+ { open "<" }
+ { name "body" }
+ { props V{ } }
+ { close ">" }
+ { children
+ V{
+ T{ open-tag
+ { open "<" }
+ { name "div" }
+ { props
+ V{
+ {
+ "id"
+ T{ squote
+ { payload
+ "ooui-php-6"
+ }
+ }
+ }
+ {
+ "data-ooui"
+ T{ squote
+ { payload
+ "{\"_\":\"mw.htmlform.FieldLayout\",\"fieldWidget\":{\"tag\":\"tagfilter\"},\"align\":\"top\",\"helpInline\":true,\"$overlay\":true,\"label\":{\"html\":\"<a href=\\\"\\/wiki\\/Special:Tags\\\" title=\\\"Special:Tags\\\">Tag<\\/a> filter:\"},\"classes\":[\"mw-htmlform-field-HTMLTagFilter\",\"mw-htmlform-autoinfuse\"]}"
+ }
+ }
+ }
+ }
+ }
+ { close ">" }
+ { children V{ } }
+ { close-tag
+ T{ close-tag
+ { name "div" }
+ }
+ }
+ }
+ }
+ }
+ { close-tag T{ close-tag { name "body" } } }
+ }
+ }
+ }
+ { close-tag T{ close-tag { name "html" } } }
+ }
+ }
+} [
+ [[
+ <!DOCTYPE html>
+ <html class="client-nojs" lang="en" dir="ltr">
+
+ <head> <title>omg</title></head>
+ <body>
+ <div id='ooui-php-6'
+ data-ooui='{"_":"mw.htmlform.FieldLayout","fieldWidget":{"tag":"tagfilter"},"align":"top","helpInline":true,"$overlay":true,"label":{"html":"<a href=\"\/wiki\/Special:Tags\" title=\"Special:Tags\">Tag<\/a> filter:"},"classes":["mw-htmlform-field-HTMLTagFilter","mw-htmlform-autoinfuse"]}'
+ >
+ </div>
+ </body>
+ </html>
+ ]] string>html
+] unit-test
TUPLE: dquote payload ;
C: <dquote> dquote
-: read-squote-string-payload ( n string -- n' string )
+: read-squote-payload ( n string -- n' string )
over [
{ CHAR: \\ CHAR: ' } slice-til-separator-inclusive {
{ f [ drop ] }
{ CHAR: ' [ drop ] }
- { CHAR: \\ [ drop next-char-from drop read-string-payload ] }
- } case
- ] [
- string-expected-got-eof
- ] if ;
-
-: read-dquote-string-payload ( n string -- n' string )
- over [
- { CHAR: \\ CHAR: \" } slice-til-separator-inclusive {
- { f [ drop ] }
- { CHAR: \" [ drop ] }
- { CHAR: \\ [ drop next-char-from drop read-string-payload ] }
+ { CHAR: \\ [ drop next-char-from drop read-squote-payload ] }
} case
] [
string-expected-got-eof
:: read-string ( $n $string $char -- n' string payload )
$n $string $char CHAR: ' =
- [ read-squote-string-payload ]
- [ read-dquote-string-payload ] if drop :> $n'
+ [ read-squote-payload ]
+ [ read-dquote-payload ] if drop :> $n'
$n' $string
$n' [ $n $string string-expected-got-eof ] unless
$n $n' 1 - $string <slice> ;
: read-bracket ( n string slice -- n' string slice' ) CHAR: [ read-matched ;
: read-brace ( n string slice -- n' string slice' ) CHAR: { read-matched ;
: read-paren ( n string slice -- n' string slice' ) CHAR: ( read-matched ;
-: read-string-payload ( n string -- n' string )
+: read-dquote-payload ( n string -- n' string )
over [
{ CHAR: \\ CHAR: \" } slice-til-separator-inclusive {
{ f [ drop ] }
{ CHAR: \" [ drop ] }
- { CHAR: \\ [ drop next-char-from drop read-string-payload ] }
+ { CHAR: \\ [ drop next-char-from drop read-dquote-payload ] }
} case
] [
string-expected-got-eof
] if ;
:: read-string ( n string tag -- n' string seq )
- n string read-string-payload drop :> n'
+ n string read-dquote-payload drop :> n'
n' string
n' [ n string string-expected-got-eof ] unless
n n' 1 - string <slice>