diff options
| author | Drahflow <drahflow@gmx.de> | 2014-04-08 01:21:24 +0200 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2014-04-08 01:21:24 +0200 |
| commit | 2eff6f053091983e658557af6c851c2f78725699 (patch) | |
| tree | 52b54dbf66323e2867f6269afadedb6cded00685 /elymas/lib/xml.ey | |
| parent | b9d46d5efded759fe4f45002c057f9bb9a4f79de (diff) | |
Some more library support
Diffstat (limited to 'elymas/lib/xml.ey')
| -rw-r--r-- | elymas/lib/xml.ey | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/elymas/lib/xml.ey b/elymas/lib/xml.ey index b947ff1..3f34b5e 100644 --- a/elymas/lib/xml.ey +++ b/elymas/lib/xml.ey @@ -2,8 +2,9 @@ < txt .consume .|hu "%" defq { "2120" "-" | |le "021" "-" | |ge |and } /in defq + map ==defaultEnts [ { "&" /amp } { "<" /lt } { ">" /gt } { "'" /apos } { "\"" /quot } ] { * defaultEnts =[] } each { "Unconfigured npeek/take/get/set/noErr/snip" die } -000000 =*npeek =*take =*get =*set =*noErr =*snip - { 0 npeek } =*peek + { 0 npeek } =*peek map ==ents # parser generator { _ sys .typed .type 1 eq { ==str { 1 ==r str { peek eq r and =r take } each r _ |noErr rep } } { } ? * } /lit deffd @@ -43,10 +44,11 @@ { { peek [ %20 %9 %D %A ] eq any take } ,+ }==S { "<![CDATA[" Char "]]>" upto "]]>" }==CDSect - { "[^<&]" | "]]>" upto }==CharData - { CharData ,? ,[ [ element Reference CDSect PI Comment ] ",|" | fold CharData ,? ,] ,* }==content - { ,[ "&#" "[0-9]" | ,+ ";" ,] ,[ "&#x" "[0-9a-fA-F]" | ,+ ";" ,] ,| }==CharRef - { "&" Name ";" }==EntityRef + { ( get ) "[^<&]" | "]]>" upto ( get snip text ) }==CharData + { CharData ,? ,[ [ element Reference CDSect PI Comment ] ",|" | fold CharData ,? ,] ,* }==content + { ,[ "&#" ( get ) "[0-9]" | ,+ ( get snip txt .consume .u [ -01 ] str .fromArray text ) ";" ,] + ,[ "&#x" ( get ) "[0-9a-fA-F]" | ,+ ( get snip txt .consume .hu [ -01 ] str .fromArray text ) ";" ,] ,| }==CharRef + { "&" ( get ) Name ( get snip ) ";" ( _ ents .has { ents * text } { ??parse.xml.undeclared-entity } ? * ) }==EntityRef { EntityRef CharRef ,| }==Reference { ,[ "\"" ( get ) "[^<&\"]" | Reference ,| ,* ( get snip ) "\"" ,] ,[ "'" ( get ) "[^<&']" | Reference ,| ,* ( get snip ) "'" ,] ,| }==AttValue @@ -77,12 +79,12 @@ { _ =*s len ==LEN 0 ==i 0 ==last { i add LEN lt { i s } { 1 neg } ? * } =npeek { i 1 add =i } =take { i } =get { =i } =set { i =last } =noErr - { |s str .infix } =snip - document * { - i LEN neq { < last |s str .postfix ==remaining > ???parse.xml.trailing-garbage } rep - } { < last |s str .postfix ==remaining > ???parse.xml } ? * + { |s str .infix } =snip defaultEnts .clone =ents + { document * { i LEN neq { ??parse.xml.trailing-garbage } rep } { ??parse.xml } ? * } + { -- < last |s str .postfix ==remaining > ??!' } ?!parse.xml } + { < "" ==name ==text > } /text deffd { < -01 ==name map ==attr _ len _ ==l dearray l 2 div { -01 attr =[] } rep [ ] ==children { =children } =*setChildren |
