Hi Sebastian,

I added support for labelled statements to treegenerator/treecompiler
(ECMAScript grammar [http://www.mozilla.org/js/language/E262-3.pdf],
section 12.12).

We can now write something like:

outer: while(...)
{
   inner: while(...)
   {
       if (...)
         break outer; // exit outer "while"
   }
}

I attach two diff's for you to apply to svn, if you
like them.

Cheers,
Alessandro
--- treegenerator.orig.py       2006-09-26 23:00:54.000000000 +0200
+++ treegenerator.py    2006-09-29 23:05:00.000000000 +0200
@@ -317,15 +317,27 @@
   elif not expressionMode and stream.currIsType("protected", "BREAK"):
     item = createItemNode("break", stream)
     stream.next()
+    # NOTE: The label after the break keyword is optional
+    if not stream.hadEolBefore() and stream.currIsType("name"):
+      item.set("label", stream.currSource())
+      stream.next()
   elif not expressionMode and stream.currIsType("protected", "CONTINUE"):
     item = createItemNode("continue", stream)
     stream.next()
+    # NOTE: The label after the continue keyword is optional
+    if not stream.hadEolBefore() and stream.currIsType("name"):
+      item.set("label", stream.currSource())
+      stream.next()
 
   if not item:
     if stream.currIsType("token", "SEMICOLON") and not expressionMode:
       # This is an empty statement
       item = createItemNode("emptyStatement", stream)
       stream.next()
+    elif stream.currIsType("token", "COLON"):
+      # The previous identifier was a label
+      item = createItemNode("labelTerminator", stream)
+      stream.next()
     else:
       if expressionMode:
         expectedDesc = "expression"
--- treecompiler.orig.py        2006-09-26 23:01:12.000000000 +0200
+++ treecompiler.py     2006-09-29 23:00:04.000000000 +0200
@@ -75,9 +75,15 @@
   elif node.type == "break":
     compString += "break"
 
+    if node.get("label", False):
+      compString += " " + node.get("label", False)
+
   elif node.type == "continue":
     compString += "continue"
 
+    if node.get("label", False):
+      compString += " " + node.get("label", False)
+
   elif node.type == "elseStatement":
     # This was a (if)statement without a block around (a set of {})
     if not node.parent.getChild("statement").hasChild("block"):
@@ -222,6 +228,9 @@
       else:
         print "Unknown third argument... Not a hook"
 
+  elif node.type == "labelTerminator":
+    compString += ":"
+
 
 
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to