Changeset 3974


Ignore:
Timestamp:
Oct 17, 2008, 3:52:59 PM (12 years ago)
Author:
yura
Message:
  • Refactoring.
Location:
to-imperative/trunk/java/refal/refal/plus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/refal/refal/plus/Stream.rf

    r3973 r3974  
    33//$module Stream : IStream;
    44
    5 $use Access Apply Box Class Compare Error StdIO Arithm;
     5$use Access Apply Arithm Box Class Compare Error StdIO;
    66
    77//** $func Stream s.func e.args = stream;
     
    6060//** $func? Getc   stream      = term;
    6161
    62 Getc stream = <Gets stream 1> : term, term;
    63 
     62Getc stream, {
     63  <Get stream> : (e.buf) (s.func e.args) =
     64    e.buf $iter {
     65      <Apply s.func e.args>;
     66      <Store stream () (s.func e.args)> = $fail;
     67    } :: e.buf, e.buf : t.head e.tail =
     68    <Store stream (e.tail) (s.func e.args)>,
     69    t.head;
     70  <Lib_Error (Stream Getc) "Arg 1 is not a Stream"> = $fail;
     71};
    6472
    6573//** $func? Gets   stream s.n  = expr;
     
    115123      };
    116124      (e.str e.buf) () Stop;
    117     } :: (e.str) (e.buf) e.Isstop,
    118     e.Isstop : v =
     125    } :: (e.str) (e.buf) e.isStop, e.isStop : v =
    119126    <Store stream (e.buf) (s.func e.args)>,
    120127    e.str;
     
    130137      (e.str e.buf) (<Apply s.func e.args>);
    131138      (e.str e.buf) () Stop;
    132     } :: (e.str) (e.buf) e.Isstop,
    133     e.Isstop : v =
     139    } :: (e.str) (e.buf) e.isStop, e.isStop : v =
    134140    <Store stream (e.buf) (s.func e.args)>,
    135141    e.str;
     
    157163      (e.str e.buf) (<Apply s.func e.args>);
    158164      (e.str e.buf) () Stop;
    159     } :: (e.str) (e.buf) e.Isstop,
    160     e.Isstop : v =
     165    } :: (e.str) (e.buf) e.isStop, e.isStop : v =
    161166    <Store stream (e.buf) (s.func e.args)>,
    162167    e.str;
     
    170175      (e.str e.buf) (<Apply s.func e.args>);
    171176      (e.str e.buf) () Stop;
    172     } :: (e.str) (e.buf) e.Isstop,
    173     e.Isstop : v =
     177    } :: (e.str) (e.buf) e.isStop, e.isStop : v =
    174178    <Store stream (e.buf) (s.func e.args)>,
    175179    e.str;
  • to-imperative/trunk/java/refal/refal/plus/XML.rf

    r3972 r3974  
    11$module "refal.plus.XML";
    22
    3 $use Convert Stream StdIO;
     3$use Access Convert Stream StdIO;
    44
    55$func? IsBlank t.term = ;
     
    99IsBlankOrDelim t.delim t.term, t.term : \{ ' '; '\n'; '\r'; '\t'; t.delim; };
    1010
    11 $func GetDelims s.stream t.delim = e.expr; // no e.delim at the end
    12 GetDelims s.stream t.delim =
    13   GO $iter {
     11$func GetUntilDelim s.stream t.delim = e.expr; // no e.delim at the end
     12GetUntilDelim s.stream t.delim =
     13  () $iter {
    1414    <Get_While s.stream &IsBlank> :: e, {
    15       <Scanc s.stream t.delim> : v = e.expr STOP;
    16       <Get_Until s.stream &IsBlankOrDelim t.delim> : v.head = e.expr ' ' v.head GO;
    17       e.expr STOP;
     15      <Scanc s.stream t.delim> : v = (e.expr) Stop;
     16      <Get_Until s.stream &IsBlankOrDelim t.delim> : v.head = (e.expr ' ' v.head);
     17      (e.expr) Stop;
    1818    };
    19   } :: e.expr s.flag, s.flag : STOP =
     19  } :: (e.expr) e.isStop, e.isStop : v =
    2020  { e.expr : ' ' e.head = e.head; e.expr; };
    2121
    22 $func? GetXMLFormat s.stream = e.comment;
     22$func? GetXMLFormat s.stream = t.comment;
     23GetXMLFormat s.stream, <Scanc s.stream '?'> : v = ((XML_FORMAT) <Middle 0 2 <Get_Delims s.stream '?>'>>);
    2324
    24 GetXMLFormat s.stream,
    25   <Scans s.stream '<?'> : '<?' =
    26   <Get_Delims s.stream '?>'> : e.format '?>',
    27   '<?' e.format '?>';
     25$func? GetComment s.stream = t.comment;
     26GetComment s.stream, <Scans s.stream '!--'> : v = ((COMMENT) <Middle 0 3 <Get_Delims s.stream '-->'>>);
    2827
     28$func? GetCDATA s.stream = t.cdata;
     29GetCDATA s.stream, <Scans s.stream '![CDATA['> : v = ((CDATA) <Middle 0 3 <Get_Delims s.stream ']]>'>>);
    2930
    30 $func? GetComment s.stream = e.comment;
     31$func FindTag s.stream = e.text (v.tag);
     32FindTag s.stream = <GetUntilDelim s.stream '<'> :: e.text, {
     33  \{ <GetXMLFormat s.stream>; <GetComment s.stream>; <GetCDATA s.stream>; } :: e.text1 = e.text e.text1 <FindTag s.stream>;
     34  e.text ('<' <GetUntilDelim s.stream '>'> '>');
     35};
    3136
    32 GetComment s.stream,
    33   <Scans s.stream '<!--'> : '<!--' =
    34   <Get_Delims s.stream '-->'> : e.comment '-->',
    35   '<!--' e.comment '-->';
    36 
    37 $func? GetCDATA s.stream = e.cdata;
    38 
    39 GetCDATA s.stream,
    40   <Scans s.stream '<![CDATA['> : '<![CDATA[' =
    41   <Get_Delims s.stream ']]>'> : e.cdata ']]>',
    42   '<![CDATA[' e.cdata ']]>';
    43 
    44 $func? SplitTag s.stream = e.text (e.tag);
    45 
    46 SplitTag s.stream =
    47   <GetDelims s.stream '<'> :: e.text,
    48   //<Get_Delim s.stream '<'> : e.text '<',
    49   <Ungets s.stream '<'>, {
    50     <GetXMLFormat s.stream> : '<?' e.format '?>',
    51       e.text ((XML_FORMAT) e.format) <SplitTag s.stream>;
    52     <GetComment s.stream> : '<!--' e.comment '-->',
    53       e.text ((COMMENT) e.comment) <SplitTag s.stream>;
    54     <GetCDATA s.stream> : '<![CDATA[' e.cdata ']]>',
    55       e.text ((CDATA) e.cdata) <SplitTag s.stream>;
    56     e.text (<GetDelims s.stream '>'> '>');
    57     //e.text (<Get_Delim s.stream '>'>);
    58   };
    59 
    60 $func SplitAttrs e = e;
     37$func SplitAttrs e.text = e.attrs;
    6138SplitAttrs e.attrs,
    6239  () (e.attrs) $iter {
    6340    e.attrs : e.key '=' '"' e.value '"' e.tail =
    6441      { e.tail : ' ' e.tail1 = e.tail1; e.tail; } :: e.tail,     
    65       (e.keyvalues (<ToWord e.key> <ToWord e.value> )) (e.tail);
    66   } :: (e.keyvalues) (e.attrs),
    67   e.attrs : /* empty */ =
     42      (e.keyvalues (<ToWord e.key> <ToWord e.value>)) (e.tail);
     43  } :: (e.keyvalues) (e.attrs), e.attrs : /* empty */ =
    6844  e.keyvalues;
    6945
    70 $func SplitName e = (e) e;
    71 
     46$func SplitName e.text = e.name (e.attrs);
    7247SplitName {
    73   e.name ' ' e.attrs = (e.name) <SplitAttrs e.attrs>;
    74   e.name = (e.name);
     48  e.name ' ' e.attrs = e.name (<SplitAttrs e.attrs>);
     49  e.name = e.name ();
    7550};
    7651
    77 $func? ReadTag s.stream e.tag = t;
    78 
    79 ReadTag s.stream e.tag, e.tag : {
     52$func ReadTag s.stream v.tag = t;
     53ReadTag s.stream v.tag, v.tag : {
    8054  '<' e.name '/>' =
    81     <SplitName e.name> :: (e.name) e.attrs,
     55    <SplitName e.name> :: e.name (e.attrs),
    8256    (<ToWord e.name> ((ATTRIBUTES) e.attrs));
    8357  '<' e.name '>' =
    84     <SplitName e.name> :: (e.name) e.attrs,
    85     <SplitTag s.stream> $iter e.text <ReadTag s.stream e.tag> <SplitTag s.stream> :: e.text (e.tag),
    86     e.tag : '</' e.name '>',
     58    <SplitName e.name> :: e.name (e.attrs),
     59    <FindTag s.stream> $iter e.text <ReadTag s.stream v.tag> <FindTag s.stream> :: e.text (v.tag),
     60    v.tag : '</' e.name '>',
    8761    (<ToWord e.name> ((ATTRIBUTES) e.attrs) e.text);
    8862};
    8963
    90 $public $func? Read s.stream = e.text_then_XML_tag;
    91 
    92 Read s.stream = <SplitTag s.stream> : e.text (e.tag), e.text <ReadTag s.stream e.tag>;
     64$public $func Read s.stream = e.text_then_XML_tag;
     65Read s.stream = <FindTag s.stream> : e.text (v.tag), e.text <ReadTag s.stream v.tag>;
    9366
    9467$public $func? GetAttribute t.tag s.attrName = s.attrValue;
    95 
    96 GetAttribute (s ((ATTRIBUTES) e (s.attrName s.attrValue) e) e) s.attrName = s.attrValue;
     68GetAttribute (s (t e (s.attrName s.attrValue) e) e) s.attrName = s.attrValue;
    9769
    9870$public $func? GetTag t.tag t.innerTagName = t.innerTag;
    99 
    100 GetTag (s t e t.tag e) t.tagName, t.tag : (t.tagName e) = t.tag;
     71GetTag (s t e t.innerTag e) t.innerTagName, t.innerTag : (t.innerTagName e) = t.innerTag;
    10172
    10273$public $func? GetValue t.tag = e.value;
    103 
    10474GetValue (s t e.value) = e.value;
    10575
    10676$func Main = e;
    107 
    10877Main =
    10978  <WriteLn <Read <Expr_Open '<Z>as<C/><B>b<!--<Z></Z>--></B><C>c</C></Z>'>>>;
Note: See TracChangeset for help on using the changeset viewer.