⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml.htm

📁 C-smile OOL is a scripting language with C++-like grammar. It has compiler, VM running bytecodes and
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<HTML>
<HEAD>
<META NAME='GENERATOR' Content='TIL:til2xml'>
<LINK rel='stylesheet' type='text/css' href='codestyle.css'>
</HEAD>
<BODY>
<P>plain text version:<A href='xml.csp'>xml.csp</A></P>
<HR>
<PRE>

<FONT color='gray'>  1| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'>  2| </FONT><FONT color='green'>//| xml package</FONT>
<FONT color='gray'>  3| </FONT><FONT color='green'>//| TIL language (http://terra-informatica.org) </FONT>
<FONT color='gray'>  4| </FONT><FONT color='green'>//| author: Andrew Fedoniuk</FONT>
<FONT color='gray'>  5| </FONT><FONT color='darkblue'><B>package</B></FONT> xml<FONT color='dimgray'>;</FONT>
<FONT color='gray'>  6| </FONT>
<FONT color='gray'>  7| </FONT><FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>escape</FONT><FONT color='dimgray'>(</FONT>t<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'>  8| </FONT>  <FONT color='darkblue'><B>return</B></FONT> t<FONT color='dimgray'>.</FONT><FONT color='purple'>replace</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>'&amp;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;amp;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&lt;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;lt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&gt;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;gt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&quot;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;quot;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'\''</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;apos;&quot;</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> 
<FONT color='gray'>  9| </FONT><FONT color='dimgray'>}</FONT>
<FONT color='gray'> 10| </FONT><FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>t<FONT color='dimgray'>)</FONT> 
<FONT color='gray'> 11| </FONT><FONT color='dimgray'>{</FONT> 
<FONT color='gray'> 12| </FONT>  <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>t<FONT color='dimgray'>.</FONT><FONT color='purple'>like</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>&quot;*&amp;*;*&quot;</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>return</B></FONT> t<FONT color='dimgray'>.</FONT><FONT color='purple'>replace</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>&quot;&amp;lt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&lt;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;gt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&gt;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;quot;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&quot;'</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;apos;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'\''</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>&quot;&amp;amp;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='maroon'>'&amp;'</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'> 13| </FONT>  <FONT color='green'>/* TODO char codes */</FONT>
<FONT color='gray'> 14| </FONT>  <FONT color='darkblue'><B>return</B></FONT> t<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 15| </FONT><FONT color='dimgray'>}</FONT>
<FONT color='gray'> 16| </FONT>
<FONT color='gray'> 17| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'> 18| </FONT><FONT color='green'>//| micro DOM implementation</FONT>
<FONT color='gray'> 19| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'> 20| </FONT>
<FONT color='gray'> 21| </FONT><FONT color='darkblue'><B>class</B></FONT> node <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 22| </FONT>    <FONT color='darkblue'><B>var</B></FONT> _value<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 23| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>node</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT>    <FONT color='dimgray'>{</FONT> _value <FONT color='dimgray'>=</FONT> v<FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 24| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>toString</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> <FONT color='darkblue'><B>return</B></FONT> <FONT color='maroon'>&quot;\n&lt;!--WARNING:toString not defined--&gt;\n&quot;</FONT> <FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>    
<FONT color='gray'> 25| </FONT><FONT color='dimgray'>}</FONT>
<FONT color='gray'> 26| </FONT>
<FONT color='gray'> 27| </FONT><FONT color='darkblue'><B>class</B></FONT> pi<FONT color='dimgray'>:</FONT> node <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 28| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>pi</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT>      <FONT color='dimgray'>{</FONT> <FONT color='purple'>node</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 29| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>toString</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> <FONT color='darkblue'><B>return</B></FONT> string<FONT color='dimgray'>::</FONT><FONT color='purple'>printf</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>&quot;&lt;?%s?&gt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 30| </FONT><FONT color='dimgray'>}</FONT> 
<FONT color='gray'> 31| </FONT><FONT color='darkblue'><B>class</B></FONT> comment<FONT color='dimgray'>:</FONT> node <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 32| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>comment</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> <FONT color='purple'>node</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 33| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>toString</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> <FONT color='darkblue'><B>return</B></FONT> string<FONT color='dimgray'>::</FONT><FONT color='purple'>printf</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>&quot;&lt;!--%s--&gt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 34| </FONT><FONT color='dimgray'>}</FONT> 
<FONT color='gray'> 35| </FONT><FONT color='darkblue'><B>class</B></FONT> cdata<FONT color='dimgray'>:</FONT> node <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 36| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>cdata</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT>   <FONT color='dimgray'>{</FONT> <FONT color='purple'>node</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 37| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>toString</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT> <FONT color='darkblue'><B>return</B></FONT> string<FONT color='dimgray'>::</FONT><FONT color='purple'>printf</FONT><FONT color='dimgray'>(</FONT><FONT color='maroon'>&quot;![CDATA[%s]]&gt;&quot;</FONT><FONT color='dimgray'>,</FONT><FONT color='purple'>unescape</FONT><FONT color='dimgray'>(</FONT>_value<FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 38| </FONT><FONT color='dimgray'>}</FONT> 
<FONT color='gray'> 39| </FONT>
<FONT color='gray'> 40| </FONT><FONT color='green'>//|    </FONT>
<FONT color='gray'> 41| </FONT><FONT color='green'>//| simple element has only text value, no children </FONT>
<FONT color='gray'> 42| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'> 43| </FONT><FONT color='darkblue'><B>class</B></FONT> simple_element<FONT color='dimgray'>:</FONT> node <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 44| </FONT>    <FONT color='darkblue'><B>var</B></FONT>     _name<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 45| </FONT>    <FONT color='darkblue'><B>var</B></FONT>     _attributes<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 46| </FONT>   
<FONT color='gray'> 47| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='purple'>simple_element</FONT><FONT color='dimgray'>(</FONT>name<FONT color='dimgray'>,</FONT>atts<FONT color='dimgray'>,</FONT>content<FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 48| </FONT>      <FONT color='purple'>node</FONT><FONT color='dimgray'>(</FONT>content<FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'> 49| </FONT>      _name <FONT color='dimgray'>=</FONT> name<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 50| </FONT>      _attributes <FONT color='dimgray'>=</FONT> atts<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 51| </FONT>    <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 52| </FONT><FONT color='green'>//|    </FONT>
<FONT color='gray'> 53| </FONT><FONT color='green'>//| access to children in form of property</FONT>
<FONT color='gray'> 54| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'> 55| </FONT>    <FONT color='darkblue'><B>property</B></FONT> <FONT color='purple'>children</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT> <FONT color='dimgray'>{</FONT>  <FONT color='green'>/* nothing here */</FONT> <FONT color='darkblue'><B>return</B></FONT> <FONT color='darkblue'><B>null</B></FONT><FONT color='dimgray'>;</FONT> <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 56| </FONT><FONT color='green'>//| </FONT>
<FONT color='gray'> 57| </FONT><FONT color='green'>//| access to attributes </FONT>
<FONT color='gray'> 58| </FONT><FONT color='green'>//| e.g. :  a = xnode[&quot;name&quot;];  </FONT>
<FONT color='gray'> 59| </FONT><FONT color='green'>//|</FONT>
<FONT color='gray'> 60| </FONT>    <FONT color='darkblue'><B>function</B></FONT> <FONT color='dimgray'>[</FONT><FONT color='dimgray'>]</FONT><FONT color='purple'></FONT><FONT color='dimgray'>(</FONT>n<FONT color='dimgray'>,</FONT>v<FONT color='dimgray'>)</FONT> 
<FONT color='gray'> 61| </FONT>    <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 62| </FONT>      <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>!</FONT><FONT color='purple'>is_undefined</FONT><FONT color='dimgray'>(</FONT>v<FONT color='dimgray'>)</FONT><FONT color='dimgray'>)</FONT> <FONT color='green'>// set </FONT>
<FONT color='gray'> 63| </FONT>      <FONT color='dimgray'>{</FONT>
<FONT color='gray'> 64| </FONT>        <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>!</FONT>_attributes<FONT color='dimgray'>)</FONT> _attributes <FONT color='dimgray'>=</FONT> <FONT color='darkblue'><B>new</B></FONT> <FONT color='purple'>map</FONT><FONT color='dimgray'>(</FONT><FONT color='dimgray'>)</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'> 65| </FONT>        _attributes<FONT color='dimgray'>[</FONT>n<FONT color='dimgray'>]</FONT> <FONT color='dimgray'>=</FONT> v<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 66| </FONT>        <FONT color='darkblue'><B>return</B></FONT> v<FONT color='dimgray'>;</FONT>
<FONT color='gray'> 67| </FONT>      <FONT color='dimgray'>}</FONT> 
<FONT color='gray'> 68| </FONT>      <FONT color='darkblue'><B>if</B></FONT><FONT color='dimgray'>(</FONT>_attributes<FONT color='dimgray'>)</FONT> <FONT color='darkblue'><B>return</B></FONT> _attributes<FONT color='dimgray'>[</FONT>n<FONT color='dimgray'>]</FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'> 69| </FONT>      <FONT color='darkblue'><B>return</B></FONT> <FONT color='darkblue'><B>null</B></FONT><FONT color='dimgray'>;</FONT>
<FONT color='gray'> 70| </FONT>    <FONT color='dimgray'>}</FONT>
<FONT color='gray'> 71| </FONT><FONT color='green'>//|    </FONT>
<FONT color='gray'> 72| </FONT><FONT color='green'>//| value here is just all text children</FONT>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -