JS+ parsing

Coordinator
May 11, 2011 at 8:09 AM

About the parsing and preprocessing of our special version of javascript, I found something that looks interesting.

http://www.antlr.org/

Today I will spend my time trying to understand what I can do with this tool... it provides a javascript grammar, so I'm sure I can parse it. Modifying the grammar I can parse our special javascript and build a tree.

Further news this afternoon :)

Lo

Coordinator
May 11, 2011 at 2:06 PM

ok... the parser works. Now I will include it in a small java program and... hope for the best ^^

 

Coordinator
May 16, 2011 at 4:54 PM

as suggested by the professor, I replaced the horrible java preprocessor with a simple python script.

the code to be preprocessed must be between a pair of # chars (eg #someattribute<-somevalue)

now the script is only able to eliminate the '#' chars, but the structure for further expansions has been created.

 

The synthax of the script is "python preprocessor.py file1.jsplus file2.jsplus ... filen.jsplus (the file extension becomes .jsplus)

Coordinator
Jun 22, 2011 at 3:49 PM
Edited Jul 8, 2011 at 2:05 PM

ok, some synthax proposals

SELECTORS

$ //path/to//node[condition] $ is a selector for a set of local nodes: does not contain a *
% //path/to/node[condition] %
selects one local node
? /path//to/node[condition] ? selects the attributes of a local node 

To cross the network and act on the server, the path must contain the special char *: so

$ //path/to//*remote/node[condition] $ is a selector for a set of remote nodes: travels through the //path/to/remote hypernode and search for the /node matching the [condition] on the server

same for the % and @ selectors

NODE ACTIONS

Given the way to select a node, we can do some actions on such node. The synthax is

$ [node-action] selector $

(of course also with %), where node-action can be

on <event> do <function>: executes the function when the event happens on the selected node. Events can be things like "
set <node>:
sets node as unique child of the selected node
set <node> in <position>: sets node as positionth child of the selected node
append <node>: appends node as last child of the selected node 

 

ATTRIBUTE ACTIONS

For attributes, similar synthax with different actions

@ [attr-action] selector @

<name> <- <value>: sets name to value
on <event> do <function>
 same as above

Coordinator
Jun 22, 2011 at 8:31 PM

Syntax of selectors is insufficient: we need an another parameter, the root node of xpath evaluating, for example $rootNode->xPath$.

How this specification is in accordance with proxy nodes concept? Node and attribute actions are unuseful except "on <event> do <function". I propose however a less ambigues syntax: $rootNode->xPath->eventName->function$ where "function" is a function that have the object "event" as first parameter.

The conseguence of using the character * into the path (to spell out the access to an hypernode) is that we must split the path into more selections, for example: the statement $rootNode->//path/to//*remote/node$ (where "remote" is an hypernode) we have to trasform into the equivalent statement $$rootNode->//path/to//remote$->/node$. Note: in this example I suppose that the selector can evaluate the xpath starting from multiple roots (convenient when we have to split a selection).

The selector %rootNode->xPath% is equivalent to $rootNode->xPath$[0] and it can be abolished.

Following an example of using proxy objects together preprocessable selectors.

 

var attrs = @theHypernode->thePath@;
attrs.attributeA = aValue1;
attrs.attributeB = aValue2;
...
attrs.update();

var node = $theHypernode->thePath$;
var newElem = document.createElement ("div");
newElem.innerHTML = "sample text";
newElem.style.color = "red";
node.appendChild(newElem);
node.setAttribute("attributeA", "value1");
node.setAttribute("attributeB", "value2");
...
node.update();

$theHypernode->thePath->DOMNodeInserted->function (event) {event.relatedNode.style.color = "#ff0000";}$

 

Finally I warn you that @ character and * character are valid xpath symbols and we have to find alternative characters for our syntax (otherwise parsing results harder).

Coordinator
Jun 23, 2011 at 9:28 AM
Daveloper wrote:

Syntax of selectors is insufficient: we need an another parameter, the root node of xpath evaluating, for example $rootNode->xPath$

ok, I didn't think about it :)


How this specification is in accordance with proxy nodes concept? Node and attribute actions are unuseful except "on <event> do <function". I propose however a less ambigues syntax: $rootNode->xPath->eventName->function$ where "function" is a function that have the object "event" as first parameter.

I'm not so convinced that the synthax is so clear... it mixes EVENTS and FUNCTIONS with the path itself.
ok for the other actions :) 


The conseguence of using the character * into the path (to spell out the access to an hypernode) is that we must split the path into more selections, for example: the statement $rootNode->//path/to//*remote/node$ (where "remote" is an hypernode) we have to trasform into the equivalent statement $rootNode->//path/to//remote$->/node$. Note: in this example I suppose that the selector can evaluate the xpath starting from multiple roots (convenient when we have to split a selection).

I do not agree. We discussed about that, and we said that the concept that we are "crossing the line" between client and server has to be stressed, so that the programmer *knows* that he is crossing it. Moreover, the synthax I have proposed is more compact.
We could also give both synthax, but the char saying "hey, you are crossing the line!" is in my opinion important.


The selector %rootNode->xPath% is equivalent to $rootNode->xPath$[0] and it can be abolished.

if we had to abolish a synthax construct every time that there is another way to express it, we would still be using Assembler. 


Following an example of using proxy objects together preprocessable selectors.

var attrs = @theHypernode->thePath@;
attrs.attributeA = aValue1;
attrs.attributeB = aValue2;
...
attrs.update();

var node = $theHypernode->thePath$;
var newElem = document.createElement ("div");
newElem.innerHTML = "sample text";
newElem.style.color = "red";
node.appendChild(newElem);
node.setAttribute("attributeA", "value1");
node.setAttribute("attributeB", "value2");
...
node.update();

$theHypernode->thePath->DOMNodeInserted->function (event) {event.relatedNode.style.color = "#ff0000";}$

 

Finally I warn you that @ character and * character are valid xpath symbols and we have to find alternative characters for our syntax (otherwise parsing results harder).

I noticed that after writing this :)

anyway, we will discuss about all this stuff this afternoon. Bring your boxing gloves with you :p 

 

Coordinator
Jun 23, 2011 at 12:07 PM

another problem in your proposal: how to distinguish, for example, between a "double hypernode"

root->/path/to/hypernode->path/to/db->path/into/db

and a setting of an interpolator on a local node

root->/path/to/normalnode->EventHappened->function

they actually share the same syntax, which makes more difficult the parsing work (and it looks also really confusing for the programmer)

Coordinator
Jun 27, 2011 at 4:31 PM

The preprocessor should be ready. Synthax is

python preprocessor.py file1.jsplus [, filen.jsplus]*

the script reads the files and "translate" them in the right format. I've also written two functions to make the translation easier.

 

if you have some time to test it, it would be nice and lovely <3

Coordinator
Jul 8, 2011 at 3:15 PM
some synthax changes

SELECTORS

$+ //path/to//node[condition] $ is a selector for a set of local nodes: does not contain a *
$ //path/to/node[condition] $ 
selects one local node
$a /path//to/node[condition] $ selects the attributes of a local node 

To cross the network and act on the server, the path must contain the special char *: so

$ //path/to//#remote/node[condition] $ is a selector for a set of remote nodes: travels through the //path/to/remote hypernode and search for the /node matching the [condition] on the server. Works in the same way with the + and a modifiers

NODE ACTIONS

Given the way to select a node, we can do some actions on such node. The synthax is

$ [node-action] selector $

(of course also with %: the action will be applied only to the first selected node), where node-action can be

on <event> do <function>: executes the function when the event happens on the selected node. Events can be things like "
set <node>:
sets node as unique child of the selected node
set <node> in <position>: sets node as positionth child of the selected node
append <node>: appends node as last child of the selected node 

 

ATTRIBUTE ACTIONS

For attributes, similar synthax with different actions

@ [attr-action] selector @

<name> <- <value>: sets name to value
on <event> do <function>
 same as above