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

Last change on this file since 3953 was 3953, checked in by yura, 12 years ago
  • Expr.concat(Comparable, Expr) checks if term in array of expr and before it.
  • XML parsing.
File size: 1.4 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 SplitName e = (e) e;
32
33SplitName {
34  e.name ' ' e.attrs = (e.name) e.attrs;
35  e.name = (e.name);
36};
37
38$func? ReadTag s.stream e.tag = t;
39
40ReadTag s.stream e.tag, e.tag : {
41  '<' e.name '/>' =
42    <SplitName e.name> :: (e.name) e.attrs,
43    (<ToWord e.name> <ToWord e.attrs>);
44  '<' e.name '>' =
45    <SplitName e.name> :: (e.name) e.attrs,
46    <GetTag s.stream> $iter e.text <ReadTag s.stream e.tag> <GetTag s.stream> :: e.text (e.tag),
47    e.tag : '</' e.name '>',
48    (<ToWord e.name> <ToWord e.attrs> e.text);
49};
50
51$public $func? Read s = e;
52
53Read s.stream = <GetTag s.stream> : e.text (e.tag), e.text <ReadTag s.stream e.tag>;
54
55$func Main = e;
56
57Main =
58  <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.