| 個人檔案The Unified Era部落格清單 | 說明 |
Redefine operation of '+'The ECMA-262 Spec has said at
section 8.2.6.2, when method [[DefaultValue]] of Object called with no
typeHint, it should behave as if the hint were Number. But ECMA-357 changed the rule upon XML object at section 9.1.1.5 to do always as String. Then, according to defination upon the operator '+' at the section 11.4.1 of ECMA-357(essentially, there is almost no defference between it and the section 11.6.1 of ECMA-262), there is a fact as following: a = <price>8.1</price>; print(a * 5); // -> this got 40.5 print(a + 1); // -> we got not 9.1 but 8.11 Yes, that's sure! The operator '+' doesn't consist with the operator '*' and any other arithmetical operators('/', '-', '%'). I think that maybe a little mistake. So ecmax has redefined the '+' operation for XMLs: if one operand is XML and another operand is Number, and also if the XML object can be converted as Number(but not NaN), then addition operation upon the two Number is applied; otherwise, it behaves as ECMA-357. (proposal) ecmax: ChangeSummary and its XML Format
1, New type: SDO extends XML x = <a id='1' val='a'/>; s = new SDO(x); y = s.copy(); // get a xml copy for current value. print(y.toXMLString()); // -> "<a id='1' val='a'/>" 2, SDO objects consist of context sections and change summary section 2.1 Each modifying operation on SDO object is always recorded into its changeSummary section 2.2 The changeSummary section is read-only and can't be directly modified. 2.3 Initially, the changeSummary section is empty for SDO object 2.4 SDO object has a 'restore()' method to undo all modifications and empty the changeSummary section 3, SDO object internally uses an XMLList to represent both the xml content and its change summary. 3.1 SDO object's toXMLString() method shows the content of the internal XMLList 3.2 the changeSummary with a namespace 'ecmax.sdo' is the last section of the internal XMLList. 3.3 SDO.length() = its XMLList.length() - 1 3.4 By declaring xmlns:x='ecmax.sdo', the following attributes in changeSummary section have given meaning: x:r='ref' -> reference to retrieve current value in content sections x:c='list' -> space-separated list of references, each refers to created element in content sections x:d='list' -> space-separated list of references, each refers to deleted element's copy in summary section x:u='list' -> space-separated list of references, each refers to updated element's copy in summary section <x:text/> -> special element to refer to and/or backup unstructured text ------------------------------------------------------------------------ For example: x = <a id="1" value="a" lock='true'> text in a <b id='b1'>text in b</b> string in a <c:d xmlns:c='foo/core' width='100' height='200'>draw oval here</c:d> </a>; x = new SDO(x); x.@id = 2; delete x.@value; x.@name='A'; x.b.* = 'new text in b'; x.b.@name='b'; x.b.@id='b2'; x.*[2] = 'new string in a'; x.*[3].@width = 200; print(x.copy()); print(x.toXMLString()); ------------------------------------------------------------------------ System.out - <a id="2" lock="true" name="A"> text in a <b id='b2' name='b'>new text in b</b> new string in a <c:d xmlns:c='foo/core' width='200' height='200'>draw oval here</c:d> </a> System.out - <a id="2" lock="true" name="A"> text in a <b id='b2' name='b'>new text in b</b> new string in a <c:d xmlns:c='foo/core' width='200' height='200'>draw oval here</c:d> </a> <x:changeSummary xmlns:x="ecmax.sdo" x:u='*[0]'> <a x:r="*[0]" x:c="@name" x:u="@id *[1] *[2] *[3]" x:d="@value" id="1" value="a"> <x:text x:r='*[0].*[0]'/> <b x:r='*[0].*[1]' x:u='@id *' x:c='@name' id='b1'>text in b</b> <x:text x:r='*[0].*[2]'>string in a</x:text> <c:d x:r="*[0].*[3]" x:u="@width" xmlns:c='foo/core' width='100' /> </a> </x:changeSummary> A cup of Swlet for Firefox/** * * Copyright (c) 2006 Uniera.org. All Rights Reserved. * * Licensed under "Free for Non-commercial Use" License. * */ import java.io.*; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*; import org.uniera.swlet.Swlet; /** * A simple demo Swlet * * @version 1.0A */ public class Demo extends Swlet { public void init(Shell shell) { new Scd(shell, SWT.NORMAL, getClass().getName()); } } /** * Scd means source code displayer. * * @version 1.0A */ class Scd extends Composite { private Text textArea = null; private Font font = null; public Scd(Composite parent, int style, String cn) { super(parent, style); initialize(cn); } public void dispose() { super.dispose(); if (font != null && !font.isDisposed()) { font.dispose(); } } private void initialize(String cn) { this.setLayout(new FillLayout(SWT.VERTICAL)); textArea = new Text(this, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL); // textArea.setEditable(false); font = new Font(null, new FontData("Courier New", 10, SWT.NORMAL)); textArea.setFont(font); LineNumberReader reader = null; try { reader = new LineNumberReader(new InputStreamReader(getClass() .getResourceAsStream(cn.replace('.', '/') + ".java"))); for (String line = reader.readLine(); line != null;) { textArea.append(line); textArea.append("\n"); line = reader.readLine(); } } catch (Exception e) { textArea.append("No source code found :( \n\tclass -> " + cn); e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } } } 2, zip *.class and Demo.java into demo.jar 3, create demo.html and write following html code into it:
4, Open demo.html with Mozilla Firefox(be sure that npswlet.zip has been unzipped into to folder ${Firefox}/plugins, See the directory tree here). About Swlet APISee the current javadoc for
Swlet here. Main features of the Swlet API are: 1, Full Browser Interface
Swlet Container for Firefox 2It seems that I've no spare time to make an XPI installer, so just uploaded a zip package of it here. ------------------------------------- Steps for evaluating: 1, Download and unzip it into plugins folder as: ${Firefox}/plugins 2, Make sure that jre/jdk 1.4.2+ already installed on your machine. | npnul32.dll | npswlet.dll \--swlet | shfolder.dll | swlet.jar | swt-win32-3235.dll \-- swt.jar 3, Open this page: http://h1.ripway.com/uniera/swlet/demo/eval.html 4, Confirm the security prompt, then see the Swlet demo: Newly added syntax in ecmax joinExpr::= expr [left | right | full] join expr filterExpr::= expr.[itemExpr Op itemExpr]; expr.[(string|{expr}) [,(string|{expr})] ]; itemExpr ::= [(left | right).][@][ns::]name|number|string|null|true|false|{expr} Op::= != | == | > | < | >= | <= | like -------------------------------------- Note: 1, If either operand is not an xml object in a joinExpr, then TypeError is thrown. 2, If expr is a deferred xml object in a filterExpr, then the filter() method of this expr will be evaluated to decide whether should enter into the dot-query loop. Goals of ECMAX - 2
a = <a id='1' name='a'> <foo>text in a</foo> </a>; b = <> <b id='1' name='b'> <bar>text in b1</bar> </b> <b id='2' name='a'> <bar>text in b2</bar> </b> </>; c = a left join b; 2. new filter: .[] vs. .() c.[left.@id == right.@id].(@id != null); print(c); Output: System.out - <ab id="1" name="b"> <foo>text in a</foo> <bar>text in b1</bar> </ab> --------------------------- Updated at 2007-3-13 Goals of ECMAX - 1
var b = '%1'; var c = 1871; then: a like b -> true c like b -> true
5.2/0.0000065 -> 800000 (not 800000.0000000001 when using double) About ECMAXA new sub-project, ecmax, is started based on Mozilla Rhino 1.6R5 to achieve goals:
1, add new operator: like 2, BigDecimal instead of double in Floating-Point Arithmetic
1, add new expression for xml objects: Cartesian product 2, add Change Summay for xml objects. |
|
|