factor: escape more char:
parent
6903949936
commit
b72db611f1
|
@ -128,7 +128,7 @@ M: array collapse-decorators
|
||||||
dup [ length 2 - ] keep [ char: \: = ] find-last-from [ 1 + tail ] [ drop ] if ;
|
dup [ length 2 - ] keep [ char: \: = ] find-last-from [ 1 + tail ] [ drop ] if ;
|
||||||
|
|
||||||
: scoped-less-than-name ( string -- string' )
|
: scoped-less-than-name ( string -- string' )
|
||||||
dup [ length 2 - ] keep [ char: < = ] find-last-from [ 1 + tail ] [ drop ] if ;
|
dup [ length 2 - ] keep [ char: \< = ] find-last-from [ 1 + tail ] [ drop ] if ;
|
||||||
|
|
||||||
: trim-top-level ( string -- string' )
|
: trim-top-level ( string -- string' )
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,7 +63,7 @@ Exponent = "e" => [[ char: e ]] (OptionalMinus DecimalIntegerLiteral)?
|
||||||
|
|
||||||
CharacterLiteral = "$" Character:c => [[ c ]]
|
CharacterLiteral = "$" Character:c => [[ c ]]
|
||||||
|
|
||||||
StringLiteral = "'" (StringLiteralCharacter | "''" => [[ char: ' ]])*:s "'"
|
StringLiteral = "'" (StringLiteralCharacter | "''" => [[ char: \' ]])*:s "'"
|
||||||
=> [[ s >string ]]
|
=> [[ s >string ]]
|
||||||
StringLiteralCharacter = [^']
|
StringLiteralCharacter = [^']
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ M: real smalltalk>string number>string ;
|
||||||
M: string smalltalk>string
|
M: string smalltalk>string
|
||||||
[
|
[
|
||||||
"'" %
|
"'" %
|
||||||
[ dup char: ' = [ dup , , ] [ , ] if ] each
|
[ dup char: \' = [ dup , , ] [ , ] if ] each
|
||||||
"'" %
|
"'" %
|
||||||
] "" make ;
|
] "" make ;
|
||||||
|
|
||||||
|
|
|
@ -382,7 +382,7 @@ M: x11-ui-backend beep ( -- )
|
||||||
|
|
||||||
PRIVATE<
|
PRIVATE<
|
||||||
: escape-' ( string -- string' )
|
: escape-' ( string -- string' )
|
||||||
[ dup char: ' = [ drop "'\\''" ] [ 1string ] if ] { } map-as concat ;
|
[ dup char: \' = [ drop "'\\''" ] [ 1string ] if ] { } map-as concat ;
|
||||||
|
|
||||||
: xmessage ( string -- )
|
: xmessage ( string -- )
|
||||||
escape-' "/usr/bin/env xmessage '" "'" surround system drop ;
|
escape-' "/usr/bin/env xmessage '" "'" surround system drop ;
|
||||||
|
|
|
@ -116,7 +116,7 @@ C: <ebnf> ebnf ;
|
||||||
[ "\"\\" member? ] satisfy 2seq ,
|
[ "\"\\" member? ] satisfy 2seq ,
|
||||||
[ char: \" = not ] satisfy ,
|
[ char: \" = not ] satisfy ,
|
||||||
] choice* repeat1 "\"" "\"" surrounded-by ,
|
] choice* repeat1 "\"" "\"" surrounded-by ,
|
||||||
[ char: ' = not ] satisfy repeat1 "'" "'" surrounded-by ,
|
[ char: \' = not ] satisfy repeat1 "'" "'" surrounded-by ,
|
||||||
] choice* [ "" flatten-as unescape-string ] action ;
|
] choice* [ "" flatten-as unescape-string ] action ;
|
||||||
|
|
||||||
: non-terminal-parser ( -- parser )
|
: non-terminal-parser ( -- parser )
|
||||||
|
|
|
@ -15,8 +15,8 @@ PRIVATE<
|
||||||
|
|
||||||
: printable? ( ch -- ? )
|
: printable? ( ch -- ? )
|
||||||
{
|
{
|
||||||
[ char: \s char: < between? ]
|
[ char: \s char: \< between? ]
|
||||||
[ char: > char: ~ between? ]
|
[ char: \> char: \~ between? ]
|
||||||
[ char: \t = ]
|
[ char: \t = ]
|
||||||
} 1|| ;
|
} 1|| ;
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ IN: html.entities
|
||||||
PRIVATE<
|
PRIVATE<
|
||||||
|
|
||||||
CONSTANT: html-escapes {
|
CONSTANT: html-escapes {
|
||||||
{ char: & "&" }
|
{ char: \& "&" }
|
||||||
{ char: < "<" }
|
{ char: \< "<" }
|
||||||
{ char: > ">" }
|
{ char: \> ">" }
|
||||||
{ char: \" """ }
|
{ char: \" """ }
|
||||||
{ char: ' "'" }
|
{ char: \' "'" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: next-escape ( seq -- i elt )
|
: next-escape ( seq -- i elt )
|
||||||
|
|
|
@ -40,18 +40,18 @@ SYMBOL: tagstack
|
||||||
$[ [ current _ = ] take-until ] [ advance drop ] bi ;
|
$[ [ current _ = ] take-until ] [ advance drop ] bi ;
|
||||||
|
|
||||||
: read-single-quote ( sequence-parser -- string )
|
: read-single-quote ( sequence-parser -- string )
|
||||||
char: ' (read-quote) ;
|
char: \' (read-quote) ;
|
||||||
|
|
||||||
: read-double-quote ( sequence-parser -- string )
|
: read-double-quote ( sequence-parser -- string )
|
||||||
char: \" (read-quote) ;
|
char: \" (read-quote) ;
|
||||||
|
|
||||||
: read-quote ( sequence-parser -- string )
|
: read-quote ( sequence-parser -- string )
|
||||||
dup get+increment char: ' =
|
dup get+increment char: \' =
|
||||||
[ read-single-quote ] [ read-double-quote ] if ;
|
[ read-single-quote ] [ read-double-quote ] if ;
|
||||||
|
|
||||||
: read-key ( sequence-parser -- string )
|
: read-key ( sequence-parser -- string )
|
||||||
skip-whitespace
|
skip-whitespace
|
||||||
[ current { [ char: = = ] [ blank? ] } 1|| ] take-until ;
|
[ current { [ char: \= = ] [ blank? ] } 1|| ] take-until ;
|
||||||
|
|
||||||
: read-token ( sequence-parser -- string )
|
: read-token ( sequence-parser -- string )
|
||||||
[ current blank? ] take-until ;
|
[ current blank? ] take-until ;
|
||||||
|
@ -70,17 +70,17 @@ SYMBOL: tagstack
|
||||||
[ advance drop ] bi ;
|
[ advance drop ] bi ;
|
||||||
|
|
||||||
: read-bang ( sequence-parser -- )
|
: read-bang ( sequence-parser -- )
|
||||||
advance dup { [ current char: - = ] [ peek-next char: - = ] } 1&&
|
advance dup { [ current char: \- = ] [ peek-next char: \- = ] } 1&&
|
||||||
[ advance advance read-comment ] [ read-dtd ] if ;
|
[ advance advance read-comment ] [ read-dtd ] if ;
|
||||||
|
|
||||||
: read-tag ( sequence-parser -- string )
|
: read-tag ( sequence-parser -- string )
|
||||||
[
|
[
|
||||||
[ current "><" member? ] take-until
|
[ current "><" member? ] take-until
|
||||||
[ char: / = ] trim-tail
|
[ char: \/ = ] trim-tail
|
||||||
] [ dup current char: < = [ advance ] unless drop ] bi ;
|
] [ dup current char: \< = [ advance ] unless drop ] bi ;
|
||||||
|
|
||||||
: read-until-< ( sequence-parser -- string )
|
: read-until-< ( sequence-parser -- string )
|
||||||
[ current char: < = ] take-until ;
|
[ current char: \< = ] take-until ;
|
||||||
|
|
||||||
: parse-text ( sequence-parser -- )
|
: parse-text ( sequence-parser -- )
|
||||||
read-until-< [ text new-tag push-tag ] unless-empty ;
|
read-until-< [ text new-tag push-tag ] unless-empty ;
|
||||||
|
|
|
@ -11,7 +11,7 @@ IN: html.parser.utils
|
||||||
: double-quote ( str -- newstr ) "\"" dup surround ;
|
: double-quote ( str -- newstr ) "\"" dup surround ;
|
||||||
|
|
||||||
: quote ( str -- newstr )
|
: quote ( str -- newstr )
|
||||||
char: ' over member?
|
char: \' over member?
|
||||||
[ double-quote ] [ single-quote ] if ;
|
[ double-quote ] [ single-quote ] if ;
|
||||||
|
|
||||||
: ?quote ( str -- newstr ) dup quoted? [ quote ] unless ;
|
: ?quote ( str -- newstr ) dup quoted? [ quote ] unless ;
|
||||||
|
|
|
@ -52,7 +52,7 @@ IN: xml.autoencoding
|
||||||
! What if first letter of processing instruction is non-ASCII?
|
! What if first letter of processing instruction is non-ASCII?
|
||||||
get-next {
|
get-next {
|
||||||
{ 0 [ next next start-utf16le ] }
|
{ 0 [ next next start-utf16le ] }
|
||||||
{ char: ? [ go-utf8 instruct dup instruct-encoding ] }
|
{ char: \? [ go-utf8 instruct dup instruct-encoding ] }
|
||||||
{ char: \! [ go-utf8 direct ] }
|
{ char: \! [ go-utf8 direct ] }
|
||||||
[ check start<name ]
|
[ check start<name ]
|
||||||
} case ;
|
} case ;
|
||||||
|
@ -75,7 +75,7 @@ IN: xml.autoencoding
|
||||||
|
|
||||||
: start-document ( -- tag )
|
: start-document ( -- tag )
|
||||||
get-char {
|
get-char {
|
||||||
{ char: < [ start< ] }
|
{ char: \< [ start< ] }
|
||||||
{ 0 [ start-utf16be ] }
|
{ 0 [ start-utf16be ] }
|
||||||
{ 0xEF [ skip-utf8-bom ] }
|
{ 0xEF [ skip-utf8-bom ] }
|
||||||
{ 0xFF [ skip-utf16le-bom ] }
|
{ 0xFF [ skip-utf16le-bom ] }
|
||||||
|
|
|
@ -23,7 +23,7 @@ UNION: dtd-acceptable
|
||||||
: take-entity-def ( var -- entity-name entity-def )
|
: take-entity-def ( var -- entity-name entity-def )
|
||||||
[
|
[
|
||||||
take-word pass-blank get-char {
|
take-word pass-blank get-char {
|
||||||
{ char: ' [ parse-quote ] }
|
{ char: \' [ parse-quote ] }
|
||||||
{ char: \" [ parse-quote ] }
|
{ char: \" [ parse-quote ] }
|
||||||
[ drop take-external-id close ]
|
[ drop take-external-id close ]
|
||||||
} case
|
} case
|
||||||
|
|
|
@ -6,17 +6,17 @@ IN: xml.entities
|
||||||
|
|
||||||
CONSTANT: entities-out
|
CONSTANT: entities-out
|
||||||
H{
|
H{
|
||||||
{ char: < "<" }
|
{ char: \< "<" }
|
||||||
{ char: > ">" }
|
{ char: \> ">" }
|
||||||
{ char: & "&" }
|
{ char: \& "&" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
CONSTANT: quoted-entities-out
|
CONSTANT: quoted-entities-out
|
||||||
H{
|
H{
|
||||||
{ char: & "&" }
|
{ char: \& "&" }
|
||||||
{ char: ' "'" }
|
{ char: \' "'" }
|
||||||
{ char: \" """ }
|
{ char: \" """ }
|
||||||
{ char: < "<" }
|
{ char: \< "<" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: escape-string-by ( str table -- escaped )
|
: escape-string-by ( str table -- escaped )
|
||||||
|
@ -31,10 +31,10 @@ CONSTANT: quoted-entities-out
|
||||||
|
|
||||||
CONSTANT: entities
|
CONSTANT: entities
|
||||||
H{
|
H{
|
||||||
{ "lt" char: < }
|
{ "lt" char: \< }
|
||||||
{ "gt" char: > }
|
{ "gt" char: \> }
|
||||||
{ "amp" char: & }
|
{ "amp" char: \& }
|
||||||
{ "apos" char: ' }
|
{ "apos" char: \' }
|
||||||
{ "quot" char: \" }
|
{ "quot" char: \" }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ PRIVATE>
|
||||||
PRIVATE<
|
PRIVATE<
|
||||||
|
|
||||||
: write-quoted ( string -- )
|
: write-quoted ( string -- )
|
||||||
char: " write1 write char: " write1 ;
|
char: \" write1 write char: \" write1 ;
|
||||||
|
|
||||||
: print-attrs ( assoc -- )
|
: print-attrs ( assoc -- )
|
||||||
[
|
[
|
||||||
|
@ -70,7 +70,7 @@ M: string write-xml
|
||||||
] when write ;
|
] when write ;
|
||||||
|
|
||||||
: write-tag ( tag -- )
|
: write-tag ( tag -- )
|
||||||
?indent char: < write1
|
?indent char: \< write1
|
||||||
dup print-name attrs>> print-attrs ;
|
dup print-name attrs>> print-attrs ;
|
||||||
|
|
||||||
: write-start-tag ( tag -- )
|
: write-start-tag ( tag -- )
|
||||||
|
@ -84,7 +84,7 @@ M: contained-tag write-xml
|
||||||
[ write-xml ] each unindent ;
|
[ write-xml ] each unindent ;
|
||||||
|
|
||||||
: write-end-tag ( tag -- )
|
: write-end-tag ( tag -- )
|
||||||
?indent "</" write print-name char: > write1 ;
|
?indent "</" write print-name char: \> write1 ;
|
||||||
|
|
||||||
M: open-tag write-xml
|
M: open-tag write-xml
|
||||||
xml-pprint? get [
|
xml-pprint? get [
|
||||||
|
@ -148,7 +148,7 @@ M: doctype-decl write-xml
|
||||||
">" write ;
|
">" write ;
|
||||||
|
|
||||||
M: directive write-xml
|
M: directive write-xml
|
||||||
"<!" write text>> write char: > write1 nl ;
|
"<!" write text>> write char: \> write1 nl ;
|
||||||
|
|
||||||
M: instruction write-xml
|
M: instruction write-xml
|
||||||
"<?" write text>> write "?>" write ;
|
"<?" write text>> write "?>" write ;
|
||||||
|
|
|
@ -16,18 +16,18 @@ IN: help.html
|
||||||
dup ascii? [
|
dup ascii? [
|
||||||
dup H{
|
dup H{
|
||||||
{ char: \" "__quo__" }
|
{ char: \" "__quo__" }
|
||||||
{ char: * "__star__" }
|
{ char: \* "__star__" }
|
||||||
{ char: \: "__colon__" }
|
{ char: \: "__colon__" }
|
||||||
{ char: < "__lt__" }
|
{ char: \< "__lt__" }
|
||||||
{ char: > "__gt__" }
|
{ char: \> "__gt__" }
|
||||||
{ char: ? "__que__" }
|
{ char: \? "__que__" }
|
||||||
{ char: \\ "__back__" }
|
{ char: \\ "__back__" }
|
||||||
{ char: | "__pipe__" }
|
{ char: \| "__pipe__" }
|
||||||
{ char: / "__slash__" }
|
{ char: \/ "__slash__" }
|
||||||
{ char: , "__comma__" }
|
{ char: \, "__comma__" }
|
||||||
{ char: @ "__at__" }
|
{ char: \@ "__at__" }
|
||||||
{ char: # "__hash__" }
|
{ char: \# "__hash__" }
|
||||||
{ char: % "__percent__" }
|
{ char: \% "__percent__" }
|
||||||
} at [ % ] [ , ] ?if
|
} at [ % ] [ , ] ?if
|
||||||
] [ number>string "__" "__" surround % ] if ;
|
] [ number>string "__" "__" surround % ] if ;
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ PRIVATE<
|
||||||
|
|
||||||
: lookup-type ( string -- object/string ? )
|
: lookup-type ( string -- object/string ? )
|
||||||
"/f" ?tail swap
|
"/f" ?tail swap
|
||||||
"new" ?head drop [ { [ char: ' = ] [ digit? ] } 1|| ] trim-tail
|
"new" ?head drop [ { [ char: \' = ] [ digit? ] } 1|| ] trim-tail
|
||||||
H{
|
H{
|
||||||
{ "object" object }
|
{ "object" object }
|
||||||
{ "obj" object }
|
{ "obj" object }
|
||||||
|
|
Loading…
Reference in New Issue