source: to-imperative/trunk/java/refal/refal/plus/XML.rf @ 3960

Last change on this file since 3960 was 3960, checked in by yura, 12 years ago
File size: 1.8 KB
Line 
1$module "refal.plus.XML";
2
3$use Convert Stream  StdIO;
4
5$func? GetComment s.stream = e.comment;
6
7GetComment s.stream,
8  <Scans s.stream '<!--'> : '<!--' =
9  <Get_Delims s.stream '-->'> : e.comment '-->',
10  '<!--' e.comment '-->';
11
12
13$func? GetCDATA s.stream = e.cdata;
14
15GetCDATA s.stream,
16  <Scans s.stream '<![CDATA['> : '<![CDATA[' =
17  <Get_Delims s.stream ']]>'> : e.cdata ']]>',
18  '<![CDATA[' e.cdata ']]>';
19
20
21$func? GetTag s.stream = e.text (e.tag);
22
23GetTag s.stream =
24  <Get_Delim s.stream '<'> : e.text '<',
25  <Ungets s.stream '<'>, {
26    <GetComment s.stream> : '<!--' e.comment '-->',
27      e.text ((COMMENT) e.comment) <GetTag s.stream>;
28    <GetCDATA s.stream> : '<![CDATA[' e.cdata ']]>',
29    e.text ((CDATA) e.cdata) <GetTag s.stream>;
30    e.text (<Get_Delim s.stream '>'>);
31  };
32
33$func SplitAttrs e = e;
34SplitAttrs e.attrs,
35  () (e.attrs) $iter {
36    e.attrs : e.key '=' '"' e.value '"' e.tail =
37      { e.tail : ' ' e.tail1 = e.tail1; e.tail; } :: e.tail,     
38      (e.keyvalues (<ToWord e.key> <ToWord e.value> )) (e.tail);
39  } :: (e.keyvalues) (e.attrs),
40  e.attrs : /* empty */ =
41  e.keyvalues;
42
43$func SplitName e = (e) e;
44
45SplitName {
46  e.name ' ' e.attrs = (e.name) <SplitAttrs e.attrs>;
47  e.name = (e.name);
48};
49
50$func? ReadTag s.stream e.tag = t;
51
52ReadTag s.stream e.tag, e.tag : {
53  '<' e.name '/>' =
54    <SplitName e.name> :: (e.name) e.attrs,
55    (<ToWord e.name> ((ATTRIBUTES) e.attrs));
56  '<' e.name '>' =
57    <SplitName e.name> :: (e.name) e.attrs,
58    <GetTag s.stream> $iter e.text <ReadTag s.stream e.tag> <GetTag s.stream> :: e.text (e.tag),
59    e.tag : '</' e.name '>',
60    (<ToWord e.name> ((ATTRIBUTES) e.attrs) e.text);
61};
62
63$public $func? Read s = e;
64
65Read s.stream = <GetTag s.stream> : e.text (e.tag), e.text <ReadTag s.stream e.tag>;
66
67$func Main = e;
68
69Main =
70  <WriteLn <Read <Expr_Open '<Z>as<C/><B>b<!--<Z></Z>--></B><C>c</C></Z>'>>>;
Note: See TracBrowser for help on using the repository browser.