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

Last change on this file since 3954 was 3954, checked in by yura, 12 years ago
  • Attributes.
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    e.text ((COMMENT) <GetComment s.stream>) <GetTag s.stream>;
27    e.text ((CDATA) <GetCDATA s.stream>) <GetTag s.stream>;
28    e.text (<Get_Delim s.stream '>'>);
29  };
30
31$func SplitAttrs e = e;
32SplitAttrs e.attrs,
33  () (e.attrs) $iter {
34    e.attrs : e.key '=' '"' e.value '"' e.tail,
35      { e.tail : ' ' e.tail1 = e.tail1; e.tail; } :: e.tail,     
36      (e.keyvalues (<ToWord e.key> <ToWord e.value> )) (e.tail);
37  } :: (e.keyvalues) (e.attrs),
38  e.attrs : /* empty */ =
39  e.keyvalues;
40
41$func SplitName e = (e) e;
42
43SplitName {
44  e.name ' ' e.attrs = (e.name) <SplitAttrs e.attrs>;
45  e.name = (e.name);
46};
47
48$func? ReadTag s.stream e.tag = t;
49
50ReadTag s.stream e.tag, e.tag : {
51  '<' e.name '/>' =
52    <SplitName e.name> :: (e.name) e.attrs,
53    (<ToWord e.name> ((ATTRIBUTES) e.attrs));
54  '<' e.name '>' =
55    <SplitName e.name> :: (e.name) e.attrs,
56    <GetTag s.stream> $iter e.text <ReadTag s.stream e.tag> <GetTag s.stream> :: e.text (e.tag),
57    e.tag : '</' e.name '>',
58    (<ToWord e.name> ((ATTRIBUTES) e.attrs) e.text);
59};
60
61$public $func? Read s = e;
62
63Read s.stream = <GetTag s.stream> : e.text (e.tag), e.text <ReadTag s.stream e.tag>;
64
65$func Main = e;
66
67Main =
68  <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.