Merge: Some gammar improvements
authorJean Privat <jean@pryen.org>
Wed, 22 Oct 2014 22:45:27 +0000 (18:45 -0400)
committerJean Privat <jean@pryen.org>
Wed, 22 Oct 2014 22:45:27 +0000 (18:45 -0400)
A bunch of unrelated grammar work: bugfixes, a feature and stuff for future work.

The only implemented feature is the use of extended method identifiers in annotation (setters and operators)

~~~nit
class A
   var foo: String is writable(real_foo=)
   fun foo=(f: String) do
      print "Hello!"
      real_foo = f
   end
end
~~~

Some additional syntax for future works are now accepted but are ignored (or will crash at compile-time).

* user defined factories in class (eg. define `new` in interface)

~~~
interface Buffer
   new do return new FlatBuffer
end
var x = new Buffer
~~~

* code-block in attributes. when the default/lazy value is more complex than a single expression

~~~
class A
   var foo: Int do
      print "Hello!"
      return 5
   end
end
~~~

* generalized tuples. eg. for multiple returns, but more word is needed #839

~~~
fun foo(a,b: Int)
do
   return (a/b, a%b)
end
~~~

In fact, generalized tuples accepts anything that annotations accepts... (eventually they will be rejected just after parsing)

~~~
var x = (1, Array[Int], for x in a do print x, toto=, -)
# in order: a literal expression, a type, a statement, a method identifier (setter),
# an other method identifier (the minus operator)
~~~

Pull-Request: #832
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

1  2 
src/modelize/modelize_property.nit
src/nitpretty.nit
src/parser/parser_nodes.nit
src/parser/parser_work.nit
src/semantize/flow.nit
src/semantize/typing.nit

Simple merge
Simple merge
Simple merge
@@@ -237,8 -246,21 +246,19 @@@ private class ComputeProdLocationVisito
                        end
                end
        end
 -
 -      init do end
  end
  
+ private class TextCollectorVisitor
+       super Visitor
+       var text: String = ""
+       redef fun visit(n)
+       do
+               if n isa Token then text += n.text
+               n.visit_all(self)
+       end
+ end
  # Each reduce action has its own class, this one is the root of the hierarchy.
  private abstract class ReduceAction
        fun action(p: Parser) is abstract
Simple merge
Simple merge