Revision: ddb7549d8c
Author: Alex Eagle <alex...@google.com>
Date: Mon Nov 30 08:13:22 2009
Log: Propagate modifiers on parameters from grammar to the model
http://code.google.com/p/noop/source/detail?r=ddb7549d8c
Revision: 3826cff01a
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 21:24:30 2010
Log: merge
http://code.google.com/p/noop/source/detail?r=3826cff01a
Revision: 426d8306e5
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 19:07:04 2010
Log: Convert expressions in the AST to proto-based. Still need to fix
inter...
http://code.google.com/p/noop/source/detail?r=426d8306e5
Revision: 214ef83b9c
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 21:26:33 2010
Log: merge
http://code.google.com/p/noop/source/detail?r=214ef83b9c
Revision: 59da39fe06
Author: Alex Eagle <alex...@google.com>
Date: Sun Feb 21 17:25:15 2010
Log: Don't use proto buffer as the only way to build an AST model. It's
too...
http://code.google.com/p/noop/source/detail?r=59da39fe06
==============================================================================
Revision: ddb7549d8c
Author: Alex Eagle <alex...@google.com>
Date: Mon Nov 30 08:13:22 2009
Log: Propagate modifiers on parameters from grammar to the model
http://code.google.com/p/noop/source/detail?r=ddb7549d8c
Modified:
/core/src/main/antlr3/noop/grammar/antlr/NoopAST.g
/core/src/main/scala/noop/model/Parameter.scala
/core/src/test/scala/noop/grammar/ClassSpec.scala
=======================================
--- /core/src/main/antlr3/noop/grammar/antlr/NoopAST.g Wed Nov 25 15:40:07
2009
+++ /core/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Nov 30 08:13:22
2009
@@ -151,9 +151,12 @@
;
parameter [Buffer<Parameter> parameters]
- : ^(PARAM modifiers? t=qualifiedType v=VariableIdentifier)
+ : ^(PARAM m=modifiers? t=qualifiedType v=VariableIdentifier)
{ Parameter param = new Parameter($v.text, $t.text);
+ if ($m.modifiers != null) {
+ param.modifiers().\$plus\$plus\$eq($m.modifiers);
+ }
$parameters.\$plus\$eq(param);
}
;
=======================================
--- /core/src/main/scala/noop/model/Parameter.scala Fri Nov 13 17:38:34 2009
+++ /core/src/main/scala/noop/model/Parameter.scala Mon Nov 30 08:13:22 2009
@@ -13,12 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import collection.mutable.{ArrayBuffer, Buffer}
+
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
class Parameter(val name:String, var noopType: String) {
+ val modifiers: Buffer[Modifier.Value] = new ArrayBuffer[Modifier.Value];
+
override def toString() = String.format("Param[%s %s]", noopType, name);
}
=======================================
--- /core/src/test/scala/noop/grammar/ClassSpec.scala Fri Nov 13 11:55:04
2009
+++ /core/src/test/scala/noop/grammar/ClassSpec.scala Mon Nov 30 08:13:22
2009
@@ -79,6 +79,17 @@
parser.parseFile(source).toStringTree() should equal (
"(CLASS Bar (PARAMS (PARAM (MOD mutable) A a) (PARAM (MOD
delegate) B b) " +
"(PARAM (MOD mutable delegate) C c)))");
+ val file = parser.file(source);
+ file.classDef.name should be("Bar");
+ file.classDef.parameters should have length(3);
+ file.classDef.parameters(0).modifiers should have length(1);
+ file.classDef.parameters(0).modifiers should
contain(Modifier.mutable);
+ file.classDef.parameters(1).modifiers should have length(1);
+ file.classDef.parameters(1).modifiers should
contain(Modifier.delegate);
+ file.classDef.parameters(2).modifiers should have length(2);
+ file.classDef.parameters(2).modifiers should
contain(Modifier.mutable);
+ file.classDef.parameters(2).modifiers should
contain(Modifier.delegate);
+
}
it("should allow an implements clause with one interface") {
==============================================================================
Revision: 3826cff01a
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 21:24:30 2010
Log: merge
http://code.google.com/p/noop/source/detail?r=3826cff01a
Added:
/grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g
/grammar/src/test/scala/noop/grammar/ClassSpec.scala
Deleted:
/compiler/noop-compiler.iml
/core/noop-core.iml
/core/src/main/antlr3/noop/grammar/antlr/Doc.g
/core/src/main/antlr3/noop/grammar/antlr/Noop.g
/core/src/main/antlr3/noop/grammar/antlr/NoopAST.g
/core/src/main/scala/noop/grammar/ParseException.scala
/core/src/main/scala/noop/grammar/Parser.scala
/core/src/test/scala/noop/grammar/BindingSpec.scala
/core/src/test/scala/noop/grammar/BlockSpec.scala
/core/src/test/scala/noop/grammar/ClassSpec.scala
/core/src/test/scala/noop/grammar/CommentsSpec.scala
/core/src/test/scala/noop/grammar/DocumentationSpec.scala
/core/src/test/scala/noop/grammar/ExpressionsSpec.scala
/core/src/test/scala/noop/grammar/FileSpec.scala
/core/src/test/scala/noop/grammar/IfSpec.scala
/core/src/test/scala/noop/grammar/InterfaceSpec.scala
/core/src/test/scala/noop/grammar/InterpretableSpec.scala
/core/src/test/scala/noop/grammar/LiteralsSpec.scala
/core/src/test/scala/noop/grammar/LoopSpec.scala
/core/src/test/scala/noop/grammar/MethodsSpec.scala
/core/src/test/scala/noop/grammar/ParseExamplesTest.scala
/core/src/test/scala/noop/grammar/ParserSpec.scala
/core/src/test/scala/noop/grammar/PropertiesSpec.scala
/core/src/test/scala/noop/grammar/TestSpec.scala
/core/src/test/scala/noop/grammar/TryCatchSpec.scala
/interpreter/noop-interpreter.iml
/noop.ipr
=======================================
--- /dev/null
+++ /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
21:24:30 2010
@@ -0,0 +1,398 @@
+// Copyright 2009 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+tree grammar NoopAST;
+
+options {
+ tokenVocab = Noop;
+ ASTLabelType = CommonTree;
+}
+
+scope SourceFile {
+ SourceFile file;
+}
+
+scope Block {
+ Block block;
+}
+
+@header {
+ package noop.grammar.antlr;
+
+ import noop.model.*;
+ import noop.model.proto.NoopAst;
+ import noop.model.proto.NoopAst.*;
+ import scala.Enumeration;
+ import scala.collection.mutable.Buffer;
+ import scala.collection.mutable.ArrayBuffer;
+}
+
+@members {
+ Stack paraphrases = new Stack();
+ public boolean hadErrors = false;
+
+ @Override
+ public String getErrorMessage(RecognitionException e, String[]
tokenNames) {
+ hadErrors = true;
+ String msg = super.getErrorMessage(e, tokenNames);
+ if ( paraphrases.size()>0 ) {
+ String paraphrase = (String)paraphrases.peek();
+ msg = msg+" "+paraphrase;
+ }
+ return msg;
+ }
+
+ public String join(String delim, List strings) {
+ if (strings.isEmpty()) {
+ return "";
+ }
+ String first = ((CommonTree) strings.get(0)).getText();
+ if (strings.size() == 1) {
+ return first;
+ }
+ StringBuilder builder = new StringBuilder(first);
+ for (int i=1; i<strings.size(); i++) {
+ builder.append(delim);
+ builder.append(((CommonTree)strings.get(i)).getText());
+ }
+ return builder.toString();
+ }
+
+ //TODO(alexeagle): when we have escape sequences, we need to do more
work here
+ // Probably anything acceping raw strings should take a RawString type
which
+ // knows how to propertly un-escape things.
+ String stripQuotes(String withQuotes) {
+ return (withQuotes.startsWith("\"\"\"") ?
+ withQuotes.substring(3, withQuotes.length() - 3) :
+ withQuotes.substring(1, withQuotes.length() - 1));
+ }
+}
+
+file returns [SourceFile file = new SourceFile()]
+ scope SourceFile;
+ @init { $SourceFile::file = $file;
+ paraphrases.push("at top-level in file"); }
+ @after { paraphrases.pop(); }
+ : namespaceDeclaration? importDeclaration* (classDefinition |
interfaceDefinition | bindingsDefinition | test)
+ ;
+
+namespaceDeclaration
+ : ^('namespace' name=namespace)
+ { $SourceFile::file.namespace_\$eq($name.text); }
+ ;
+
+importDeclaration
+ : ^('import' name=qualifiedType)
+ { $SourceFile::file.imports().\$plus\$eq($name.text); }
+ ;
+
+namespace returns [String text]
+ : v+=VariableIdentifier+
+ { $text = join(".", $v); }
+ ;
+
+qualifiedType returns [String text]
+ : n=namespace? t=TypeIdentifier
+ { $text = ($n.text == null) ? $t.text : $n.text + "." + $t.text; }
+ ;
+
+classDefinition
+@init {
+ paraphrases.push("in class definition");
+ Buffer<Method> methodCollector = new ArrayBuffer<Method>();
+ Buffer<Method> unittestCollector = new ArrayBuffer<Method>();
+ Buffer<String> interfaceCollector = new ArrayBuffer<String>();
+}
+@after {
+ paraphrases.pop();
+}
+ : ^(CLASS m=modifiers? t=TypeIdentifier p=parameters?
+ typeSpecifier[interfaceCollector]*
+ classBlock[methodCollector, unittestCollector]?
+ d=doc?)
+ {
+ ConcreteClassDefinition classDef = new ConcreteClassDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
+ classDef.imports().\$plus\$plus\$eq($SourceFile::file.imports());
+ classDef.methods().\$plus\$plus\$eq(methodCollector);
+ classDef.unittests().\$plus\$plus\$eq(unittestCollector);
+ classDef.interfaces().\$plus\$plus\$eq(interfaceCollector);
+ if ($p.parameters != null) {
+ classDef.parameters().\$plus\$plus\$eq($p.parameters);
+ }
+ if ($m.modifiers != null) {
+ classDef.modifiers().\$plus\$plus\$eq($m.modifiers);
+ }
+ $SourceFile::file.classDef_\$eq(classDef);
+ }
+ ;
+
+interfaceDefinition
+ : ^(INTERFACE m=modifiers? t=TypeIdentifier d=doc?)
+ {
+ InterfaceDefinition classDef = new InterfaceDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
+ if ($m.modifiers != null) {
+ classDef.modifiers().\$plus\$plus\$eq($m.modifiers);
+ }
+ $SourceFile::file.classDef_\$eq(classDef);
+ }
+ ;
+
+parameters returns [Buffer<Parameter> parameters = new
ArrayBuffer<Parameter>() ]
+ : ^(PARAMS parameter[$parameters]*)
+ ;
+
+parameter [Buffer<Parameter> parameters]
+ : ^(PARAM m=modifiers? t=qualifiedType v=VariableIdentifier)
+
+ { Parameter param = new Parameter($v.text, $t.text);
+ if ($m.modifiers != null) {
+ param.modifiers().\$plus\$plus\$eq($m.modifiers);
+ }
+ $parameters.\$plus\$eq(param);
+ }
+ ;
+
+typeSpecifier [Buffer<String> interfaces]
+ : ^(IMPL i=qualifiedType)
+ {
+ $interfaces.\$plus\$eq($i.text);
+ }
+ ;
+
+modifiers returns [Buffer<Enumeration.Value> modifiers ]
+@init { modifiers = new ArrayBuffer<Enumeration.Value>(); }
+ : ^(MOD modifier[modifiers]+)
+ ;
+
+modifier [Buffer<Enumeration.Value> mods]
+ : m=('mutable' | 'delegate' | 'native')
+ { mods.\$plus\$eq(Modifier.valueOf($m.text).get()); }
+ ;
+
+test
+@init {
+ Buffer<Method> unittestCollector = new ArrayBuffer<Method>();
+}
+ : ^(TEST StringLiteral statement* test? unittest[unittestCollector]?)
+ {}
+ ;
+
+unittest [Buffer<Method> unittests]
+ : ^(UNITTEST name=StringLiteral b=block)
+ { Method method = new Method(stripQuotes($name.text), $b.block,
stripQuotes($name.text));
+ $unittests.\$plus\$eq(method);
+ method.returnTypes().\$plus\$eq("Void");
+ }
+ ;
+
+classBlock [Buffer<Method> methods, Buffer<Method> unittests]
+ : (identifierDeclaration | methodDefinition[methods] |
unittest[unittests])+
+ ;
+
+methodDefinition [Buffer<Method> methods]
+@init { paraphrases.push("in method definition"); }
+@after { paraphrases.pop(); }
+ : ^(METHOD d=doc? m=modifiers? r=returnType name=VariableIdentifier
p=parameters? b=block)
+ { Method method = new Method($name.text, $b.block, $d.doc);
+ method.returnTypes().\$plus\$plus\$eq($r.types);
+ if ($p.parameters != null) {
+ method.parameters().\$plus\$plus\$eq($p.parameters);
+ }
+ if ($m.modifiers != null) {
+ method.modifiers().\$plus\$plus\$eq($m.modifiers);
+ }
+ $methods.\$plus\$eq(method);
+ }
+ ;
+
+returnType returns [Buffer<String> types = new ArrayBuffer<String>() ]
+ : ^(RETURN_TYPE type[$types]+)
+ ;
+
+type [Buffer<String> types]
+ : t=TypeIdentifier {
+ $types.\$plus\$eq($t.text);
+ }
+ ;
+
+bindingsDefinition
+ : ^(BINDING t=TypeIdentifier d=doc? b=bindings)
+ {
+ BindingDefinition classDef = new BindingDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
+ classDef.bindings().\$plus\$plus\$eq($b.bindings);
+ classDef.imports().\$plus\$plus\$eq($SourceFile::file.imports());
+ $SourceFile::file.classDef_\$eq(classDef);
+ }
+ ;
+
+bindingsDeclaration returns [Buffer<BindingDeclaration> bindings]
+ : ^(BINDING b=bindings)
+ { $bindings = $b.bindings; }
+ ;
+
+bindingsReference returns [String text]
+ : ^(BINDING t=qualifiedType)
+ { $text = $t.text; }
+ ;
+
+bindings returns [Buffer<BindingDeclaration> bindings]
+ @init{ $bindings = new ArrayBuffer<BindingDeclaration>(); }
+ : binding[bindings]*
+ ;
+
+binding[Buffer<BindingDeclaration> bindings]
+ : ^(BIND t=qualifiedType exp=expression)
+ { $bindings.\$plus\$eq(new BindingDeclaration($t.text, $exp.exp)); }
+ ;
+
+block returns [Block block]
+ scope Block;
+ @init { $block = new Block();
+ $Block::block = $block; }
+ : (anonBind=bindingsDeclaration | namedBind=bindingsReference)?
statement*
+ {
+ if ($namedBind.text != null) {
+ $block.namedBinding_\$eq(new scala.Some($namedBind.text));
+ }
+ if ($anonBind.bindings != null) {
+ $block.anonymousBindings().\$plus\$plus\$eq($anonBind.bindings);
+ }
+ }
+ ;
+
+statement
+@init { paraphrases.push("in statement"); }
+@after { paraphrases.pop(); }
+ : returnStatement
+ | w=whileStatement
+ { $Block::block.statements().\$plus\$eq($w.exp); }
+ | identifierDeclaration
+ | should=shouldStatement
+ { $Block::block.statements().\$plus\$eq($should.exp); }
+ | exp=expression
+ { $Block::block.statements().\$plus\$eq($exp.exp); }
+ ;
+
+shouldStatement returns [Expression exp]
+ : ^('should' left=expression right=expression)
+ { $exp = new ShouldExpression($left.exp, $right.exp); }
+ ;
+
+whileStatement returns [Expression exp]
+ : ^(WHILE term=expression b=block)
+ { $exp = new WhileLoop($term.exp, $b.block); }
+ ;
+
+returnStatement
+ : ^('return' ex=expression)
+ { $Block::block.statements().\$plus\$eq(new ReturnExpression($ex.exp)); }
+ ;
+
+identifierDeclaration
+ : ^(VAR t=TypeIdentifier (^('=' v=VariableIdentifier exp=expression) |
v=VariableIdentifier))
+ { IdentifierDeclarationExpression identifierDeclaration = new
IdentifierDeclarationExpression($t.text, $v.text);
+ $Block::block.statements().\$plus\$eq(identifierDeclaration);
+ if ($exp.exp != null) {
+ identifierDeclaration.initialValue_\$eq(new scala.Some($exp.exp));
+ }
+ }
+ ;
+
+assignment returns [Expression exp]
+ : ^('=' lhs=expression rhs=expression)
+ { $exp = new AssignmentExpression($lhs.exp, $rhs.exp); }
+ ;
+
+expression returns [Expression exp]
+ : l=literal
+ { $exp = new ExpressionWrapper($l.exp); }
+ | d=dereference
+ { $exp = $d.exp; }
+ | o=operatorExpression
+ { $exp = $o.exp; }
+ | ass=assignment
+ { $exp = $ass.exp; }
+ | c=conditionalExpression
+ { $exp = $c.exp; }
+ | right=(VariableIdentifier|TypeIdentifier) a=arguments?
+ { if ($a.args != null) {
+ Expression left = new IdentifierExpression("this");
+ $exp = new MethodInvocationExpression(left, $right.text, $a.args);
+ } else {
+ $exp = new IdentifierExpression($right.text);
+ }
+ }
+ ;
+
+conditionalExpression returns [Expression exp]
+ : ^(cond=('||' | '&&') left=expression right=expression)
+ {
+ if ($cond.text.equals("||")) {
+ $exp = new ConditionalOrExpression($left.exp, $right.exp);
+ } else if ($cond.text.equals("&&")) {
+ $exp = new ConditionalAndExpression($left.exp, $right.exp);
+ }
+ }
+ ;
+
+operatorExpression returns [Expression exp]
+ : ^(op=('+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '<' | '>='
| '<=') left=expression right=expression)
+ { $exp = new OperatorExpression($left.exp, $op.text, $right.exp); }
+ ;
+
+dereference returns [Expression exp]
+ : ^('.' left=expression right=VariableIdentifier a=arguments?)
+ {
+ if ($a.args != null) {
+ $exp = new MethodInvocationExpression($left.exp, $right.text,
$a.args);
+ } else {
+ $exp = new DereferenceExpression($left.exp, new
IdentifierExpression($right.text));
+ }
+ }
+ ;
+
+arguments returns [Buffer<Expression> args]
+@init { $args = new ArrayBuffer<Expression>(); }
+ : ^(ARGS argument[args]*)
+ ;
+
+argument[Buffer<Expression> args]
+ : exp=expression
+ {
+ $args.\$plus\$eq($exp.exp);
+ }
+ ;
+
+literal returns [Expr exp]
+ : i=INT
+ { $exp = Expr.newBuilder()
+ .setType(Expr.Type.INT_LITERAL)
+ .setIntLiteral(IntLiteral.newBuilder().setValue(Integer.valueOf($i.text)))
+ .build(); }
+ | s=StringLiteral
+ { $exp = Expr.newBuilder()
+ .setType(Expr.Type.STRING_LITERAL)
+ .setStringLiteral(NoopAst.StringLiteral.newBuilder().setValue(stripQuotes($s.text)))
+ .build(); }
+ | b=('true' | 'false')
+ { $exp = Expr.newBuilder()
+ .setType(Expr.Type.BOOLEAN_LITERAL)
+ .setBooleanLiteral(NoopAst.BooleanLiteral.newBuilder().setValue(Boolean.valueOf($b.text)))
+ .build(); }
+ ;
+
+doc returns [String doc]
+ : ^(DOC s=StringLiteral)
+ { $doc = stripQuotes($s.text); }
+ ;
=======================================
--- /dev/null
+++ /grammar/src/test/scala/noop/grammar/ClassSpec.scala Mon Feb 1
21:24:30 2010
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package noop.grammar;
+
+import org.scalatest.matchers.ShouldMatchers
+import noop.model.{ConcreteClassDefinition, Modifier};
+import org.scalatest.Spec;
+
+
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
+ */
+class ClassSpec extends Spec with ShouldMatchers {
+
+ val parser = new Parser();
+
+ describe("parser") {
+
+ it("should fail to parse a class with no parenthesis") {
+ val source = "class Bar {}";
+ intercept[ParseException] {
+ parser.parseFile(source);
+ }
+ }
+
+ it("should parse a class with no parameters") {
+ val source = "class Bar() {}";
+ val commonTree = parser.parseFile(source);
+
+ commonTree.toStringTree() should equal ("(CLASS Bar)");
+ }
+
+ it("should parse a class with one parameter") {
+ val source = "class Bar(String a) {}";
+ val commonTree = parser.parseFile(source);
+
+ commonTree.toStringTree() should equal ("(CLASS Bar (PARAMS (PARAM
String a)))");
+
+ val file = parser.file(source);
+ file.classDef.name should be ("Bar");
+ val concreteClass =
file.classDef.asInstanceOf[ConcreteClassDefinition];
+ concreteClass.parameters(0).name should be ("a");
+ concreteClass.parameters(0).noopType should be ("String");
+ }
+
+ it("should parse a class with a fully-qualified type in a parameter") {
+ val source = "class Bar(noop.String a) {}";
+ val commonTree = parser.parseFile(source);
+
+ commonTree.toStringTree() should equal ("(CLASS Bar (PARAMS (PARAM
noop String a)))");
+
+ val file = parser.file(source);
+ val concreteClass =
file.classDef.asInstanceOf[ConcreteClassDefinition];
+ concreteClass.parameters(0).noopType should be ("noop.String");
+ }
+
+ it("should parse a class with multiple parameters") {
+ val source = "class Bar(A a, B b, C c) {}";
+ val commonTree = parser.parseFile(source);
+
+ commonTree.toStringTree() should equal (
+ "(CLASS Bar (PARAMS (PARAM A a) (PARAM B b) (PARAM C c)))");
+ }
+
+ it("should allow modifiers on the parameters") {
+ val source = "class Bar(mutable A a, delegate B b, mutable delegate
C c) {}";
+ parser.parseFile(source).toStringTree() should equal (
+ "(CLASS Bar (PARAMS (PARAM (MOD mutable) A a) (PARAM (MOD
delegate) B b) " +
+ "(PARAM (MOD mutable delegate) C c)))");
+ val file = parser.file(source);
+ file.classDef.name should be("Bar");
+ file.classDef.parameters should have length(3);
+ file.classDef.parameters(0).modifiers should have length(1);
+ file.classDef.parameters(0).modifiers should
contain(Modifier.mutable);
+ file.classDef.parameters(1).modifiers should have length(1);
+ file.classDef.parameters(1).modifiers should
contain(Modifier.delegate);
+ file.classDef.parameters(2).modifiers should have length(2);
+ file.classDef.parameters(2).modifiers should
contain(Modifier.mutable);
+ file.classDef.parameters(2).modifiers should
contain(Modifier.delegate);
+
+ }
+
+ it("should allow an implements clause with one interface") {
+ val source = "class Foo() implements Bar {}";
+
+ parser.parseFile(source).toStringTree() should equal (
+ "(CLASS Foo (IMPL Bar))");
+ }
+
+ it("should allow an implements clause with several interfaces") {
+ val source = "class Foo() implements A, a.b.C, d.E {}";
+ parser.parseFile(source).toStringTree() should equal (
+ "(CLASS Foo (IMPL A) (IMPL a b C) (IMPL d E))");
+ val file = parser.file(source);
+ file.classDef.name should be ("Foo");
+ val concreteDef =
file.classDef.asInstanceOf[ConcreteClassDefinition];
+ concreteDef.interfaces(0) should be("A");
+ concreteDef.interfaces(1) should be ("a.b.C");
+ concreteDef.interfaces(2) should be ("d.E");
+ }
+
+ it("should allow the native modifier on a class") {
+ val source = "native class Foo() {}";
+ parser.parseFile(source).toStringTree() should equal (
+ "(CLASS (MOD native) Foo)");
+ val file = parser.file(source);
+ file.classDef.modifiers should contain(Modifier.native);
+ }
+ }
+}
=======================================
--- /compiler/noop-compiler.iml Wed Nov 25 15:29:16 2009
+++ /dev/null
@@ -1,120 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module relativePaths="false" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="Scala" name="Scala">
- <configuration />
- </facet>
- </component>
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/target/classes" />
- <output-test url="file://$MODULE_DIR$/target/test-classes" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/stringtemplate"
isTestSource="false" />
- </content>
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="module" module-name="noop-core" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr/3.1.1/antlr-3.1.1.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr/3.1.1/antlr-3.1.1-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- </component>
-</module>
-
=======================================
--- /core/noop-core.iml Wed Nov 25 15:29:16 2009
+++ /dev/null
@@ -1,121 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module relativePaths="false" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="Scala" name="Scala">
- <configuration />
- </facet>
- </component>
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/target/classes" />
- <output-test url="file://$MODULE_DIR$/target/test-classes" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/scala"
isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/target/generated/antlr"
isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/scala"
isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/target/classes" />
- </content>
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr/3.1.1/antlr-3.1.1.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr/3.1.1/antlr-3.1.1-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- </component>
-</module>
-
=======================================
--- /core/src/main/antlr3/noop/grammar/antlr/Doc.g Mon Oct 19 04:42:14 2009
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2009 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-grammar Doc;
-
-options {
- backtrack = true;
- output = AST;
- ASTLabelType = CommonTree;
-}
-
-@header {
- package noop.grammar.antlr;
-}
-
-@lexer::header {
- package noop.grammar.antlr;
-}
-
-@lexer::rulecatch {
- catch (RecognitionException e) {
- reportError(e);
- throw new RuntimeException(e);
- }
-}
-
-@rulecatch {
- catch (RecognitionException e) {
- reportError(e);
- throw e;
- }
-}
-
-doc
- : DocLine* docCommandDeclaration*
- ;
-
-docCommandDeclaration
- : docCommand DocLine*
- ;
-
-docCommand
- : '@param'
-// TODO(gabe) : '@param' VariableIdentifier
- | CustomCommand
- ;
-
-CustomCommand
- : '@' 'a' .. 'z' ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9')*
- ;
-
-VariableIdentifier
- : 'a' .. 'z' ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9')*
- ;
-
-DocLine
- : ~'@' ~('\n'|'\r')* '\r'? '\n'
- ;
-
-WS : (' '|'\t'|'\n')+
- ;
-
=======================================
--- /core/src/main/antlr3/noop/grammar/antlr/Noop.g Wed Nov 25 15:56:45 2009
+++ /dev/null
@@ -1,349 +0,0 @@
-// Copyright 2009 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-grammar Noop;
-
-options {
- backtrack = true;
- output = AST;
- ASTLabelType = CommonTree;
-}
-
-tokens {
- DOC;
- CLASS;
- INTERFACE;
- PARAMS;
- PARAM;
- METHOD;
- MOD;
- ARGS;
- VAR;
- IMPL;
- IF;
- WHILE;
- FOREACH;
- FOR;
- TEST;
- UNITTEST;
- BINDING;
- BIND;
- RETURN_TYPE;
- TRY;
- CATCH;
- FINALLY;
-}
-
-@header {
- package noop.grammar.antlr;
-}
-
-@lexer::header {
- package noop.grammar.antlr;
-}
-
-@members {
- public boolean hadErrors = false;
-
- @Override
- public String getErrorMessage(RecognitionException e, String[]
tokenNames) {
- hadErrors = true;
- return super.getErrorMessage(e, tokenNames);
- }
-}
-
-@lexer::members {
- public boolean hadErrors = false;
-
- @Override
- public String getErrorMessage(RecognitionException e, String[]
tokenNames) {
- hadErrors = true;
- return super.getErrorMessage(e, tokenNames);
- }
-}
-
-// A line of user input in the interactive interpreter
-interpretable
- : (importDeclaration
- | classDefinition
- | statement)+
- ;
-
-file
- : namespaceDeclaration? importDeclaration* (classDefinition |
interfaceDefinition | bindingDefinition | test)
- ;
-
-namespaceDeclaration
- : 'namespace'^ namespace ';'!
- ;
-
-importDeclaration
- : 'import'^ qualifiedType ';'!
- ;
-
-ifExpression
- : 'if' '(' expression ')' block* ('else' block*)?
- -> ^(IF expression* block*)
- ;
-
-methodDefinition
- : methodSignature block
- -> ^(METHOD methodSignature block?)
- ;
-
-namespace
- : VariableIdentifier ('.'! VariableIdentifier)*
- ;
-
-qualifiedType
- : (namespace '.'!)? TypeIdentifier
- ;
-
-classDefinition
- : doc? modifiers? 'class' TypeIdentifier parameterList typeSpecifiers?
classBlock
- -> ^(CLASS modifiers? TypeIdentifier parameterList? typeSpecifiers?
classBlock? doc?)
- ;
-
-doc
- : StringLiteral -> ^(DOC StringLiteral)
- ;
-
-typeSpecifiers
- : 'implements' qualifiedType (',' qualifiedType)*
- -> ^(IMPL qualifiedType)*
- ;
-
-interfaceDefinition
- : doc? 'interface' TypeIdentifier interfaceBlock
- -> ^(INTERFACE TypeIdentifier interfaceBlock? doc?)
- ;
-
-modifiers
- : modifier+
- -> ^(MOD modifier+)
- ;
-
-modifier
- : 'mutable' | 'delegate' | 'native'
- ;
-
-classBlock
- : '{'! (identifierDeclaration ';'!)* methodDefinition* unittest* '}'!
- ;
-
-interfaceBlock
- : '{'! methodDeclaration* '}'!
- ;
-
-test
- : 'test' StringLiteral '{' (statement* | test | unittest) '}'
- -> ^(TEST StringLiteral statement* test? unittest?)
- ;
-
-unittest
- : 'unittest' StringLiteral bindingDeclaration? block
- -> ^(UNITTEST StringLiteral bindingDeclaration? block?)
- ;
-
-methodSignature
- : doc? modifiers? returnType VariableIdentifier parameterList
throwsDeclaration?
- ;
-
-throwsDeclaration
- : 'throws' qualifiedType
- -> ^('throws' qualifiedType)
- ;
-
-returnType
- : TypeIdentifier -> ^(RETURN_TYPE TypeIdentifier)
- | '(' typeList ')' -> ^(RETURN_TYPE typeList)
- ;
-
-typeList
- : TypeIdentifier (','! TypeIdentifier)*
- ;
-
-methodDeclaration
- : methodSignature ';'
- -> ^(METHOD methodSignature)
- ;
-
-
-identifierDeclaration
- : TypeIdentifier identifierDeclarator
- -> ^(VAR TypeIdentifier identifierDeclarator)
- ;
-
-identifierDeclarator
- : VariableIdentifier ('='^ expression)?
- ;
-
-block
- : '{'! statement* '}'!
- ;
-
-statement
- : identifierDeclaration ';'!
- | whileLoop
- | forLoop
- | 'return'^ expression ';'!
- | expression ';'!
- | ifExpression
- | shouldStatement ';'!
- | bindingsBlock
- | tryCatchBlock
- ;
-
-tryCatchBlock
- : 'try' block 'catch' block ('finally' block)?
- -> ^(TRY block CATCH block (FINALLY block)?)
- | 'try' block 'finally' block
- -> ^(TRY block FINALLY block)
- ;
-
-//TODO(alex): The binding syntax seems a little scattered. Sometimes
semicolon, sometimes comma?
-bindingDefinition
- : doc? 'binding' qualifiedType '{' ((binding | typealias) ';')* '}'
- -> ^(BINDING qualifiedType doc? binding* typealias*)
- ;
-
-bindingDeclaration
- : 'binding' (bindings | qualifiedType)
- -> ^(BINDING bindings? qualifiedType?)
- ;
-
-bindingsBlock
- : 'binding' (bindings | qualifiedType) block
- -> ^(BINDING bindings? qualifiedType? block?)
- ;
-
-bindings
- : '('! binding? (','! binding)* ')'!
- ;
-
-binding
- : qualifiedType '->' expression
- -> ^(BIND qualifiedType expression)
- ;
-
-typealias
- : 'alias'^ qualifiedType TypeIdentifier
- ;
-
-shouldStatement
- : expression 'should'^ expression
- ;
-
-forLoop
- : 'for' '(' (identifierDeclaration|VariableIdentifier) 'in'
expression ')' block
- -> ^(FOREACH identifierDeclaration? VariableIdentifier? expression block?)
- | 'for' '(' identifierDeclaration ';' conditionalExpression ';'
expression ')' block
- -> ^(FOR identifierDeclaration conditionalExpression expression block?)
- ;
-
-whileLoop
- : 'while' '(' expression ')' block
- -> ^(WHILE expression block?)
- ;
-
-expression
- : additiveExpression ('='^ expression)?
- ;
-
-additiveExpression
- : multiplicativeExpression ( ('+' | '-')^ multiplicativeExpression )*
- ;
-
-multiplicativeExpression
- : conditionalExpression ( ( '*' | '/' | '%' )^ conditionalExpression )*
- ;
-
-conditionalExpression
- : (conditionalOrExpression | conditionalAndExpression)+
- ;
-
-conditionalOrExpression
- : conditionalAndExpression ('||'^ conditionalAndExpression)*
- ;
-
-conditionalAndExpression
- : finalConditionalExpression ('&&'^ finalConditionalExpression)*
- ;
-
-finalConditionalExpression
- : primary (('==' | '!=' | '>' | '<' | '>=' | '<=')^ primary)*
- ;
-
-primary
- : '('! expression ')'!
- | (VariableIdentifier|TypeIdentifier|literal) (arguments | ('.'^
(VariableIdentifier|TypeIdentifier) arguments?)*)
- ;
-
-arguments
- : '(' expressionList? ')'
- -> ^(ARGS expressionList?)
- ;
-
-expressionList
- : expression (','! expression)*
- ;
-
-parameterList
- : '('! parameters? ')'!
- ;
-
-parameters
- : parameter (',' parameter)*
- -> ^(PARAMS parameter*)
- ;
-
-parameter
- : modifiers? qualifiedType VariableIdentifier
- -> ^(PARAM modifiers? qualifiedType VariableIdentifier)
- ;
-
-literal
- : INT | StringLiteral | 'true' | 'false'
- ;
-
-/* Lexer rules */
-
-TypeIdentifier
- : 'A' .. 'Z' ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9')*
- ;
-
-VariableIdentifier
- : 'a' .. 'z' ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9')*
- ;
-
-StringLiteral
- : '"' ~('"'|'\\'|'\n'|'\r')* '"'
- | '"""' (options {greedy=false;}:.)* '"""'
- ;
-
-WS
- : (' '|'\r'|'\n'|'\t')+ {$channel = HIDDEN;}
- ;
-
-COMMENT
- : '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
- ;
-
-LINE_COMMENT
- : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
- ;
-
-INT
- : '-'? '0'..'9'+
- ;
=======================================
--- /core/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Nov 30 08:13:22
2009
+++ /dev/null
@@ -1,373 +0,0 @@
-// Copyright 2009 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-tree grammar NoopAST;
-
-options {
- tokenVocab = Noop;
- ASTLabelType = CommonTree;
-}
-
-scope SourceFile {
- SourceFile file;
-}
-
-scope Block {
- Block block;
-}
-
-@header {
- package noop.grammar.antlr;
-
- import noop.model.*;
- import scala.Enumeration;
- import scala.collection.mutable.Buffer;
- import scala.collection.mutable.ArrayBuffer;
-}
-
-@members {
- Stack paraphrases = new Stack();
- public boolean hadErrors = false;
-
- @Override
- public String getErrorMessage(RecognitionException e, String[]
tokenNames) {
- hadErrors = true;
- String msg = super.getErrorMessage(e, tokenNames);
- if ( paraphrases.size()>0 ) {
- String paraphrase = (String)paraphrases.peek();
- msg = msg+" "+paraphrase;
- }
- return msg;
- }
-
- public String join(String delim, List strings) {
- if (strings.isEmpty()) {
- return "";
- }
- String first = ((CommonTree) strings.get(0)).getText();
- if (strings.size() == 1) {
- return first;
- }
- StringBuilder builder = new StringBuilder(first);
- for (int i=1; i<strings.size(); i++) {
- builder.append(delim);
- builder.append(((CommonTree)strings.get(i)).getText());
- }
- return builder.toString();
- }
-
- //TODO(alexeagle): when we have escape sequences, we need to do more
work here
- // Probably anything acceping raw strings should take a RawString type
which
- // knows how to propertly un-escape things.
- String stripQuotes(String withQuotes) {
- return (withQuotes.startsWith("\"\"\"") ?
- withQuotes.substring(3, withQuotes.length() - 3) :
- withQuotes.substring(1, withQuotes.length() - 1));
- }
-}
-
-file returns [SourceFile file = new SourceFile()]
- scope SourceFile;
- @init { $SourceFile::file = $file;
- paraphrases.push("at top-level in file"); }
- @after { paraphrases.pop(); }
- : namespaceDeclaration? importDeclaration* (classDefinition |
interfaceDefinition | bindingsDefinition | test)
- ;
-
-namespaceDeclaration
- : ^('namespace' name=namespace)
- { $SourceFile::file.namespace_\$eq($name.text); }
- ;
-
-importDeclaration
- : ^('import' name=qualifiedType)
- { $SourceFile::file.imports().\$plus\$eq($name.text); }
- ;
-
-namespace returns [String text]
- : v+=VariableIdentifier+
- { $text = join(".", $v); }
- ;
-
-qualifiedType returns [String text]
- : n=namespace? t=TypeIdentifier
- { $text = ($n.text == null) ? $t.text : $n.text + "." + $t.text; }
- ;
-
-classDefinition
-@init {
- paraphrases.push("in class definition");
- Buffer<Method> methodCollector = new ArrayBuffer<Method>();
- Buffer<Method> unittestCollector = new ArrayBuffer<Method>();
- Buffer<String> interfaceCollector = new ArrayBuffer<String>();
-}
-@after {
- paraphrases.pop();
-}
- : ^(CLASS m=modifiers? t=TypeIdentifier p=parameters?
- typeSpecifier[interfaceCollector]*
- classBlock[methodCollector, unittestCollector]?
- d=doc?)
- {
- ClassDefinition classDef = new ClassDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
- classDef.imports().\$plus\$plus\$eq($SourceFile::file.imports());
- classDef.methods().\$plus\$plus\$eq(methodCollector);
- classDef.unittests().\$plus\$plus\$eq(unittestCollector);
- classDef.interfaces().\$plus\$plus\$eq(interfaceCollector);
- if ($p.parameters != null) {
- classDef.parameters().\$plus\$plus\$eq($p.parameters);
- }
- if ($m.modifiers != null) {
- classDef.modifiers().\$plus\$plus\$eq($m.modifiers);
- }
- $SourceFile::file.classDef_\$eq(classDef);
- }
- ;
-
-interfaceDefinition
- : ^(INTERFACE m=modifiers? t=TypeIdentifier d=doc?)
- {
- ClassDefinition classDef = new ClassDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
- if ($m.modifiers != null) {
- classDef.modifiers().\$plus\$plus\$eq($m.modifiers);
- }
- $SourceFile::file.classDef_\$eq(classDef);
- }
- ;
-
-parameters returns [Buffer<Parameter> parameters = new
ArrayBuffer<Parameter>() ]
- : ^(PARAMS parameter[$parameters]*)
- ;
-
-parameter [Buffer<Parameter> parameters]
- : ^(PARAM m=modifiers? t=qualifiedType v=VariableIdentifier)
-
- { Parameter param = new Parameter($v.text, $t.text);
- if ($m.modifiers != null) {
- param.modifiers().\$plus\$plus\$eq($m.modifiers);
- }
- $parameters.\$plus\$eq(param);
- }
- ;
-
-typeSpecifier [Buffer<String> interfaces]
- : ^(IMPL i=qualifiedType)
- {
- $interfaces.\$plus\$eq($i.text);
- }
- ;
-
-modifiers returns [Buffer<Enumeration.Value> modifiers ]
-@init { modifiers = new ArrayBuffer<Enumeration.Value>(); }
- : ^(MOD modifier[modifiers]+)
- ;
-
-modifier [Buffer<Enumeration.Value> mods]
- : m=('mutable' | 'delegate' | 'native')
- { mods.\$plus\$eq(Modifier.valueOf($m.text).get()); }
- ;
-
-test
-@init {
- Buffer<Method> unittestCollector = new ArrayBuffer<Method>();
-}
- : ^(TEST StringLiteral statement* test? unittest[unittestCollector]?)
- {}
- ;
-
-unittest [Buffer<Method> unittests]
- : ^(UNITTEST name=StringLiteral b=block)
- { Method method = new Method(stripQuotes($name.text), $b.block,
stripQuotes($name.text));
- $unittests.\$plus\$eq(method);
- method.returnTypes().\$plus\$eq("Void");
- }
- ;
-
-classBlock [Buffer<Method> methods, Buffer<Method> unittests]
- : (identifierDeclaration | methodDefinition[methods] |
unittest[unittests])+
- ;
-
-methodDefinition [Buffer<Method> methods]
-@init { paraphrases.push("in method definition"); }
-@after { paraphrases.pop(); }
- : ^(METHOD d=doc? m=modifiers? r=returnType name=VariableIdentifier
p=parameters? b=block)
- { Method method = new Method($name.text, $b.block, $d.doc);
- method.returnTypes().\$plus\$plus\$eq($r.types);
- if ($p.parameters != null) {
- method.parameters().\$plus\$plus\$eq($p.parameters);
- }
- if ($m.modifiers != null) {
- method.modifiers().\$plus\$plus\$eq($m.modifiers);
- }
- $methods.\$plus\$eq(method);
- }
- ;
-
-returnType returns [Buffer<String> types = new ArrayBuffer<String>() ]
- : ^(RETURN_TYPE type[$types]+)
- ;
-
-type [Buffer<String> types]
- : t=TypeIdentifier {
- $types.\$plus\$eq($t.text);
- }
- ;
-
-bindingsDefinition
- : ^(BINDING t=TypeIdentifier d=doc? b=bindings)
- {
- ClassDefinition classDef = new ClassDefinition($t.text,
$SourceFile::file.namespace(), $d.doc);
- classDef.bindings().\$plus\$plus\$eq($b.bindings);
- $SourceFile::file.classDef_\$eq(classDef);
- }
- ;
-
-bindingsDeclaration returns [Buffer<BindingDeclaration> bindings]
- : ^(BINDING b=bindings)
- { $bindings = $b.bindings; }
- ;
-
-bindingsReference returns [String text]
- : ^(BINDING t=qualifiedType)
- { $text = $t.text; }
- ;
-
-bindings returns [Buffer<BindingDeclaration> bindings]
- @init{ $bindings = new ArrayBuffer<BindingDeclaration>(); }
- : binding[bindings]*
- ;
-
-binding[Buffer<BindingDeclaration> bindings]
- : ^(BIND t=qualifiedType exp=expression)
- { $bindings.\$plus\$eq(new BindingDeclaration($t.text, $exp.exp)); }
- ;
-
-block returns [Block block]
- scope Block;
- @init { $block = new Block();
- $Block::block = $block; }
- : (anonBind=bindingsDeclaration | namedBind=bindingsReference)?
statement*
- {
- if ($namedBind.text != null) {
- $block.namedBinding_\$eq(new scala.Some($namedBind.text));
- }
- if ($anonBind.bindings != null) {
- $block.anonymousBindings().\$plus\$plus\$eq($anonBind.bindings);
- }
- }
- ;
-
-statement
-@init { paraphrases.push("in statement"); }
-@after { paraphrases.pop(); }
- : returnStatement
- | w=whileStatement
- { $Block::block.statements().\$plus\$eq($w.exp); }
- | identifierDeclaration
- | should=shouldStatement
- { $Block::block.statements().\$plus\$eq($should.exp); }
- | exp=expression
- { $Block::block.statements().\$plus\$eq($exp.exp); }
- ;
-
-shouldStatement returns [Expression exp]
- : ^('should' left=expression right=expression)
- { $exp = new ShouldExpression($left.exp, $right.exp); }
- ;
-
-whileStatement returns [Expression exp]
- : ^(WHILE term=expression b=block)
- { $exp = new WhileLoop($term.exp, $b.block); }
- ;
-
-returnStatement
- : ^('return' ex=expression)
- { $Block::block.statements().\$plus\$eq(new ReturnExpression($ex.exp)); }
- ;
-
-identifierDeclaration
- : ^(VAR t=TypeIdentifier (^('=' v=VariableIdentifier exp=expression) |
v=VariableIdentifier))
- { IdentifierDeclarationExpression identifierDeclaration = new
IdentifierDeclarationExpression($t.text, $v.text);
- $Block::block.statements().\$plus\$eq(identifierDeclaration);
- if ($exp.exp != null) {
- identifierDeclaration.initialValue_\$eq(new scala.Some($exp.exp));
- }
- }
- ;
-
-assignment returns [Expression exp]
- : ^('=' lhs=expression rhs=expression)
- { $exp = new AssignmentExpression($lhs.exp, $rhs.exp); }
- ;
-
-expression returns [Expression exp]
- : l=literal
- { $exp = $l.exp; }
- | d=dereference
- { $exp = $d.exp; }
- | o=operatorExpression
- { $exp = $o.exp; }
- | ass=assignment
- { $exp = $ass.exp; }
- | right=(VariableIdentifier|TypeIdentifier) a=arguments?
- { Expression left = new IdentifierExpression("this");
- if ($a.args != null) {
- $exp = new MethodInvocationExpression(left, $right.text, $a.args);
- } else {
- $exp = new IdentifierExpression($right.text);
- }
- }
- ;
-
-operatorExpression returns [Expression exp]
- : ^(op=('+'|'-'|'*'|'/'|'%') left=expression right=expression)
- { $exp = new OperatorExpression($left.exp, $op.text, $right.exp); }
- ;
-
-dereference returns [Expression exp]
- : ^('.' left=expression right=VariableIdentifier a=arguments?)
- {
- if ($a.args != null) {
- $exp = new MethodInvocationExpression($left.exp, $right.text,
$a.args);
- } else {
- $exp = new DereferenceExpression($left.exp, new
IdentifierExpression($right.text));
- }
- }
- ;
-
-arguments returns [Buffer<Expression> args]
-@init { $args = new ArrayBuffer<Expression>(); }
- : ^(ARGS argument[args]*)
- ;
-
-argument[Buffer<Expression> args]
- : exp=expression
- {
- $args.\$plus\$eq($exp.exp);
- }
- ;
-
-literal returns [Expression exp]
- : i=INT
- { $exp = new IntLiteralExpression(Integer.valueOf($i.text)); }
- | s=StringLiteral
- { $exp = new StringLiteralExpression(stripQuotes($s.text)); }
- | b=('true' | 'false')
- { $exp = new BooleanLiteralExpression(Boolean.valueOf($b.text)); }
- ;
-
-doc returns [String doc]
- : ^(DOC s=StringLiteral)
- { $doc = stripQuotes($s.text); }
- ;
=======================================
--- /core/src/main/scala/noop/grammar/ParseException.scala Thu Oct 8
10:25:57 2009
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-/**
- * Thrown by our parser when ANTLR reports some errors while lexing or
parsing.
- *
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class ParseException(val message: String) extends RuntimeException(message)
=======================================
--- /core/src/main/scala/noop/grammar/Parser.scala Fri Nov 13 17:38:34 2009
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import java.io.InputStream;
-
-import org.antlr.runtime.{ANTLRInputStream, ANTLRStringStream,
CommonTokenStream};
-import org.antlr.runtime.tree.{CommonTree, CommonTreeNodeStream};
-
-import model.SourceFile;
-import grammar.antlr.{DocLexer, DocParser, NoopAST, NoopParser, NoopLexer};
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class Parser() {
-
- def buildParser(input: ANTLRStringStream): (NoopLexer, NoopParser) = {
- val lexer = new NoopLexer(input);
-
- return (lexer, new NoopParser(new CommonTokenStream(lexer)));
- }
-
- def buildDocParser(input: ANTLRStringStream): (DocLexer, DocParser) = {
- val lexer = new DocLexer(input);
-
- return (lexer, new DocParser(new CommonTokenStream(lexer)));
- }
-
- def parseFile(source: InputStream): CommonTree = {
- val (lexer, parser) = buildParser(new ANTLRInputStream(source));
-
- return parseFile(lexer, parser);
- }
-
- def parseFile(source: String): CommonTree = {
- val (lexer, parser) = buildParser(new ANTLRStringStream(source));
-
- return parseFile(lexer, parser);
- }
-
- def parseFile(lexer: NoopLexer, parser: NoopParser): CommonTree = {
- val file = parser.file();
-
- if (parser.hadErrors || lexer.hadErrors) {
- throw new ParseException("Source failed to parse");
- }
- return file.getTree().asInstanceOf[CommonTree];
- }
-
- def parseInterpretable(source: String): CommonTree = {
- val (lexer, parser) = buildParser(new ANTLRStringStream(source));
- val interpretable = parser.interpretable();
-
- if (parser.hadErrors || lexer.hadErrors) {
- throw new ParseException("Source failed to parse");
- }
- return interpretable.getTree().asInstanceOf[CommonTree];
- }
-
- def parseBlock(source: String): CommonTree = {
- val (lexer, parser) = buildParser(new ANTLRStringStream(source));
- val block = parser.block();
-
- if (parser.hadErrors || lexer.hadErrors) {
- throw new ParseException("Source failed to parse");
- }
- return block.getTree().asInstanceOf[CommonTree];
- }
-
- def parseDoc(source: String): CommonTree = {
- val (lexer, parser) = buildDocParser(new ANTLRStringStream(source));
- val doc = parser.doc();
-
- return doc.getTree().asInstanceOf[CommonTree];
- }
-
- def buildTreeParser(ast: CommonTree): NoopAST = {
- return new NoopAST(new CommonTreeNodeStream(ast));
- }
-
- def file(ast: CommonTree): SourceFile = {
- val treeParser = buildTreeParser(ast);
- val file = treeParser.file();
-
- if (treeParser.hadErrors) {
- throw new ParseException("Syntax errors");
- }
- return file;
- }
-
- def file(source: String): SourceFile = file(parseFile(source));
-
- def file(source: InputStream): SourceFile = file(parseFile(source));
-}
=======================================
--- /core/src/test/scala/noop/grammar/BindingSpec.scala Wed Nov 25 15:56:45
2009
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar
-
-import noop.model.{StringLiteralExpression, IdentifierExpression};
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class BindingSpec extends Spec with ShouldMatchers {
- val parser = new Parser();
-
- describe("the binding keyword") {
-
- it("allows the binding operator in a binding") {
- val source = "binding Something { " +
- "BankService -> BankServiceImpl; " +
- "Port -> 9876; " +
- "Max -> firstThing;" +
- "}";
- parser.parseFile(source).toStringTree() should be(
- "(BINDING Something (BIND BankService BankServiceImpl) (BIND Port
9876) (BIND Max firstThing))");
- val file = parser.buildTreeParser(parser.parseFile(source)).file;
- file.classDef.bindings should have length(3);
- file.classDef.bindings.first.noopType should be("BankService");
- file.classDef.bindings.first.binding.getClass() should
be(classOf[IdentifierExpression]);
-
file.classDef.bindings.first.binding.asInstanceOf[IdentifierExpression].identifier
should be ("BankServiceImpl");
- }
-
- it("can appear as an anonymous binding block") {
- val source = "class Foo() { Int thing() { binding(A -> B) {} } }";
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (METHOD (RETURN_TYPE Int) thing (BINDING (BIND A
B))))");
- val file = parser.buildTreeParser(parser.parseFile(source)).file;
- val method = file.classDef.methods.first;
- method.block.anonymousBindings should have length(1);
- method.block.namedBinding should be(None);
- val firstBinding = method.block.anonymousBindings.first;
- firstBinding.noopType should be("A");
- firstBinding.binding.getClass() should
be(classOf[IdentifierExpression]);
- firstBinding.binding.asInstanceOf[IdentifierExpression].identifier
should be ("B");
-
- }
-
- it("can appear as a named binding block") {
- val source = "class Foo() { Int thing() { binding MyBinding {} } }";
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (METHOD (RETURN_TYPE Int) thing (BINDING
MyBinding)))");
- val file = parser.buildTreeParser(parser.parseFile(source)).file;
- val method = file.classDef.methods.first;
- method.block.anonymousBindings should be('empty);
- method.block.namedBinding should be(Some("MyBinding"));
- }
-
- it("can not appear in a method declaration with a name") {
- val source = "class Foo() { Int thing() binding MyBinding {} }";
- intercept[ParseException] {
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (METHOD (RETURN_TYPE Int) thing (BINDING
MyBinding)))");
- }
- }
-
- it("can not appear anonymously in a method declaration") {
- val source = "class Foo() { Int thing() binding(This -> that) {} }";
- intercept[ParseException] {
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (METHOD (RETURN_TYPE Int) thing (BINDING (BIND This
that))))");
- }
- }
-
- it("can appear in a unittest declaration with a name") {
- val source = "class Foo() { unittest \"test this\" binding MyBinding
{} }";
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (UNITTEST \"test this\" (BINDING MyBinding)))");
- val file = parser.buildTreeParser(parser.parseFile(source)).file;
- val method = file.classDef.unittests.first;
- method.block.anonymousBindings should be('empty);
- method.block.namedBinding should be(Some("MyBinding"));
- }
-
- it("can appear anonymously in a unittest declaration") {
- val source = "class Foo() { unittest \"test this\" binding(String ->
\"foo\") {} }";
- parser.parseFile(source).toStringTree() should be(
- "(CLASS Foo (UNITTEST \"test this\" (BINDING (BIND String
\"foo\"))))");
- val file = parser.buildTreeParser(parser.parseFile(source)).file;
- val method = file.classDef.unittests.first;
- method.block.anonymousBindings should have length(1);
- val firstBinding = method.block.anonymousBindings.first;
- firstBinding.noopType should be("String");
- firstBinding.binding.getClass() should
be(classOf[StringLiteralExpression]);
- firstBinding.binding.asInstanceOf[StringLiteralExpression].value
should be ("foo");
- }
- }
-
- describe("the type alias") {
- it("should parse") {
- val source = "binding App { alias Int Port; }";
- parser.parseFile(source).toStringTree() should be(
- "(BINDING App (alias Int Port))");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/BlockSpec.scala Thu Oct 8 10:25:57
2009
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package noop.grammar;
-
-import collection.mutable.ArrayBuffer;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import model._;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class BlockSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("a block") {
-
- it("should allow a return statement") {
- val blockAst = parser.parseBlock("{ return 0; }");
-
- blockAst.toStringTree() should be("(return 0)");
- val block = parser.buildTreeParser(blockAst).block();
-
- block.statements.size should be(1);
- block.statements(0).getClass() should be(classOf[ReturnExpression]);
- val returnExpression =
block.statements(0).asInstanceOf[ReturnExpression];
-
- returnExpression.expr.getClass() should
be(classOf[IntLiteralExpression]);
- returnExpression.expr.asInstanceOf[IntLiteralExpression].value
should be(0);
- }
-
- it("should allow chained property access on properties") {
- val source = "{ b.c.d; }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be("(. (. b c) d)");
- val block = parser.buildTreeParser(blockAst).block();
-
- block.statements.size should be(1);
- block.statements(0).getClass() should
be(classOf[DereferenceExpression]);
- val deref1 = block.statements(0).asInstanceOf[DereferenceExpression];
- deref1.left.getClass() should be(classOf[DereferenceExpression]);
- deref1.right.getClass() should be(classOf[IdentifierExpression]);
- deref1.right.asInstanceOf[IdentifierExpression].identifier should
be("d");
-
- val deref2 = deref1.left.asInstanceOf[DereferenceExpression];
- deref2.left.getClass() should be(classOf[IdentifierExpression]);
- deref2.right.getClass() should be(classOf[IdentifierExpression]);
- deref2.left.asInstanceOf[IdentifierExpression].identifier should
be("b");
- deref2.right.asInstanceOf[IdentifierExpression].identifier should
be("c");
- }
-
- it("should allow a method call on implicit 'this'") {
- val source = "{ a(); }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be ("a ARGS");
- val block = parser.buildTreeParser(blockAst).block();
- block.statements.size should be(1);
- block.statements(0).getClass() should
be(classOf[MethodInvocationExpression]);
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("this");
- methodInvocation.name should be("a");
- methodInvocation.arguments should be ('empty);
- }
-
- it("should allow calling a method on an identifier") {
- val source = "{ a.b(); }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be("(. a b ARGS)");
- val block = parser.buildTreeParser(blockAst).block();
- block.statements.size should be(1);
-
- block.statements(0).getClass() should
be(classOf[MethodInvocationExpression]);
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
- methodInvocation.name should be("b");
- methodInvocation.arguments should be(new ArrayBuffer[Expression]);
- methodInvocation.arguments.isEmpty should be (true);
- }
-
- it("should allow method chaining") {
- val source = "{ a.b().c(); }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be("(. (. a b ARGS) c ARGS)");
- val block = parser.buildTreeParser(blockAst).block();
- block.statements should have length (1);
-
- val method1 =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- method1.left.getClass() should
be(classOf[MethodInvocationExpression]);
- val method2 = method1.left.asInstanceOf[MethodInvocationExpression];
-
- method2.left.getClass() should be(classOf[IdentifierExpression]);
- method2.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
- method2.name should be("b");
- method2.arguments should be ('empty);
-
- method1.name should be("c");
- method1.arguments should be('empty);
- }
-
- it("should allow a method call on a property") {
- val source = "{ a.b.c(); }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be("(. (. a b) c ARGS)");
- val block = parser.buildTreeParser(blockAst).block();
- block.statements should have length (1);
-
- val method =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- method.left.getClass() should be(classOf[DereferenceExpression]);
- val deref = method.left.asInstanceOf[DereferenceExpression];
-
- deref.left.getClass() should be(classOf[IdentifierExpression]);
- deref.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
- deref.right.getClass() should be(classOf[IdentifierExpression]);
- deref.right.asInstanceOf[IdentifierExpression].identifier should
be("b");
-
- method.name should be("c");
- method.arguments should be('empty);
- }
-
- it("should allow a method call with arguments") {
- val source = "{ a.b(c, \"d\"); }";
- val blockAst = parser.parseBlock(source);
-
- blockAst.toStringTree() should be ("(. a b (ARGS c \"d\"))");
-
- val block = parser.buildTreeParser(blockAst).block();
- block.statements.size should be(1);
-
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
- methodInvocation.name should be("b");
- methodInvocation.arguments should have length(2);
- methodInvocation.arguments(0).getClass() should
be(classOf[IdentifierExpression]);
-
methodInvocation.arguments(0).asInstanceOf[IdentifierExpression].identifier
should be("c");
- methodInvocation.arguments(1).getClass() should
be(classOf[StringLiteralExpression]);
-
methodInvocation.arguments(1).asInstanceOf[StringLiteralExpression].value
should be ("d");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/ClassSpec.scala Mon Nov 30 08:13:22
2009
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import noop.model.Modifier;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class ClassSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("parser") {
-
- it("should fail to parse a class with no parenthesis") {
- val source = "class Bar {}";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
-
- it("should parse a class with no parameters") {
- val source = "class Bar() {}";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar)");
- }
-
- it("should parse a class with one parameter") {
- val source = "class Bar(String a) {}";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar (PARAMS (PARAM
String a)))");
-
- val file = parser.file(source);
- file.classDef.name should be ("Bar");
- file.classDef.parameters(0).name should be ("a");
- file.classDef.parameters(0).noopType should be ("String");
- }
-
- it("should parse a class with a fully-qualified type in a parameter") {
- val source = "class Bar(noop.String a) {}";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar (PARAMS (PARAM
noop String a)))");
-
- val file = parser.file(source);
- file.classDef.parameters(0).noopType should be ("noop.String");
- }
-
- it("should parse a class with multiple parameters") {
- val source = "class Bar(A a, B b, C c) {}";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal (
- "(CLASS Bar (PARAMS (PARAM A a) (PARAM B b) (PARAM C c)))");
- }
-
- it("should allow modifiers on the parameters") {
- val source = "class Bar(mutable A a, delegate B b, mutable delegate
C c) {}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Bar (PARAMS (PARAM (MOD mutable) A a) (PARAM (MOD
delegate) B b) " +
- "(PARAM (MOD mutable delegate) C c)))");
- val file = parser.file(source);
- file.classDef.name should be("Bar");
- file.classDef.parameters should have length(3);
- file.classDef.parameters(0).modifiers should have length(1);
- file.classDef.parameters(0).modifiers should
contain(Modifier.mutable);
- file.classDef.parameters(1).modifiers should have length(1);
- file.classDef.parameters(1).modifiers should
contain(Modifier.delegate);
- file.classDef.parameters(2).modifiers should have length(2);
- file.classDef.parameters(2).modifiers should
contain(Modifier.mutable);
- file.classDef.parameters(2).modifiers should
contain(Modifier.delegate);
-
- }
-
- it("should allow an implements clause with one interface") {
- val source = "class Foo() implements Bar {}";
-
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Foo (IMPL Bar))");
- }
-
- it("should allow an implements clause with several interfaces") {
- val source = "class Foo() implements A, a.b.C, d.E {}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Foo (IMPL A) (IMPL a b C) (IMPL d E))");
- val file = parser.file(source);
- file.classDef.name should be ("Foo");
- file.classDef.interfaces(0) should be("A");
- file.classDef.interfaces(1) should be ("a.b.C");
- file.classDef.interfaces(2) should be ("d.E");
- }
-
- it("should allow the native modifier on a class") {
- val source = "native class Foo() {}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS (MOD native) Foo)");
- val file = parser.file(source);
- file.classDef.modifiers should contain(Modifier.native);
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/CommentsSpec.scala Thu Oct 8
10:25:57 2009
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class CommentsSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("parser") {
-
- it("should be able to parse a single line comment") {
- val source = "// a comment\n class Foo() {}\n";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Foo)");
- }
-
- it("should be able to parse a multi-line comment") {
- val source = """
- /** hello
- bonjour
- */class Foo() {}
- """;
- var commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Foo)");
- }
-
- it("should be able to parse nested comments") {
- val source = """
- /** hello
- // bonjour
- *
- class Foo() {} */class Foo() {}
- """;
- var commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Foo)");
- }
-
- // Note: this makes Alex sad.
- it("should allow tab characters to appear in the source") {
- val source = "\tclass\tFoo() {\t}";
- parser.parseFile(source).toStringTree() should equal ("(CLASS Foo)");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/DocumentationSpec.scala Wed Nov 25
15:40:07 2009
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class DocumentationSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("documentation") {
-
- it("should appear before a class definition, in a string literal") {
- val source = "\"This class is awesome\" class Awesome() {}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Awesome (DOC \"This class is awesome\"))");
- val file = parser.file(source);
- file.classDef.documentation should equal("This class is awesome");
- }
-
- it("should appear before a method declaration") {
- val source = "class Foo() { \"Here is my great method\" Int doIt()
{}}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Foo (METHOD (DOC \"Here is my great method\")
(RETURN_TYPE Int) doIt))");
- val file = parser.file(source);
- file.classDef.methods(0).documentation should equal ("Here is my
great method");
- }
-
- it("can use the triple-quoted string literal and appear on an
interface") {
- val source = "\"\"\"\nMulti-line\ndocumentation\n\"\"\" interface
Bar {}";
- parser.parseFile(source).toStringTree() should equal (
- "(INTERFACE Bar (DOC
\"\"\"\nMulti-line\ndocumentation\n\"\"\"))");
- val file = parser.file(source);
- file.classDef.documentation should equal
("\nMulti-line\ndocumentation\n");
- }
-
- it("should appear before a bindings definition") {
- val source = "\"Stuff you need bound\" binding Stuff {}";
- parser.parseFile(source).toStringTree() should equal (
- "(BINDING Stuff (DOC \"Stuff you need bound\"))");
- val file = parser.file(source);
- file.classDef.documentation should equal("Stuff you need bound");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/ExpressionsSpec.scala Thu Nov 12
22:16:59 2009
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import noop.model.{OperatorExpression, IntLiteralExpression,
IdentifierDeclarationExpression};
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class ExpressionsSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("the parser") {
-
- it("should parse a variable assignment") {
- val source = "{ Int a = 3; }";
- parser.parseBlock(source).toStringTree() should equal ("(VAR Int (=
a 3))");
- }
-
- it("should parse arithmetic") {
- val source = "{ Float a = 3 + 4 / (5 * (6 + 7)) % 8; }";
- parser.parseBlock(source).toStringTree() should equal (
- "(VAR Float (= a (+ 3 (% (/ 4 (* 5 (+ 6 7))) 8))))");
- val block =
parser.buildTreeParser(parser.parseBlock(source)).block();
- block.statements should have length(1);
- block.statements(0).getClass should
be(classOf[IdentifierDeclarationExpression]);
- val declaration =
block.statements(0).asInstanceOf[IdentifierDeclarationExpression];
- declaration.initialValue should be ('defined);
- val expression1 =
declaration.initialValue.get().asInstanceOf[OperatorExpression];
- expression1.operator should be ("+");
- expression1.left.asInstanceOf[IntLiteralExpression].value should be
(3);
- val expression2 = expression1.asInstanceOf[OperatorExpression].right;
- expression2.asInstanceOf[OperatorExpression].operator should be
("%");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/FileSpec.scala Thu Oct 8 10:25:57
2009
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class FileSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("parser") {
-
- it("should allow the word 'test' as a package name") {
- // TODO(alexeagle)
- }
-
- it("should parse namespace declaration") {
- val source = "namespace noop.demo; class Foo() {}";
- parser.parseFile(source).toStringTree() should equal (
- "(namespace noop demo) (CLASS Foo)");
- }
-
- it("should allow import in default namespace") {
- val source = "import Foo; class B(){}";
- parser.parseFile(source).toStringTree() should equal (
- "(import Foo) (CLASS B)");
- }
-
- it("should parse import statements") {
- val source = "import noop.demo.Test; class Foo() {}";
- parser.parseFile(source).toStringTree() should equal (
- "(import noop demo Test) (CLASS Foo)");
- }
-
- it("should not allow import without a type on the end") {
- val source = "import noop.demo;";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
-
- it("should parse a realistic looking file header") {
- val source = """
- namespace noop.grammar;
- // TODO: it should fail when a semicolon is missing, but the test
still passes
- import org.antlr.runtime.RecognitionException;
- import org.scalatest.Spec;
- import org.scalatest.matchers.ShouldMatchers;
-
- class FileSpec() {
- }
- """;
- parser.parseFile(source).toStringTree() should equal (
- "(namespace noop grammar) (import org antlr runtime
RecognitionException) " +
- "(import org scalatest Spec) (import org scalatest matchers
ShouldMatchers) " +
- "(CLASS FileSpec)");
- val file = parser.file(source);
- file.namespace should be ("noop.grammar");
- file.imports(0) should be ("org.antlr.runtime.RecognitionException");
- file.imports(1) should be ("org.scalatest.Spec");
- file.imports(2) should be ("org.scalatest.matchers.ShouldMatchers");
- }
-
- it ("should not allow extra stuff after the class definition") {
- val source = "class Foo() {} extra stuff";
- //intercept[ParseException] {
- // parser.parseFile(source);
- //}
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/IfSpec.scala Thu Oct 8 10:25:57 2009
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class IfSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("an if expression") {
-
- it("should parse correctly equality expression on two literals") {
- val source = "{ if (1 == 1) { } }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (== 1 1))");
- }
-
- it("should parse correctly an inequality expression on two literals") {
- val source = "{ if (1 != 2) { } }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (!= 1 2))");
- }
-
- it("should parse correctly an inequality expression followed by an
or'ed equality expression on literals") {
- val source = "{ if (1 != 2 || 1 == 1) { } }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (|| (!= 1 2) (== 1 1)))");
- }
-
- it("should parse correctly an inequality expression followed by an
and'ed equality expression on literals") {
- val source = "{ if (1 != 2 && 1 == 1) { } }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (&& (!= 1 2) (== 1 1)))");
- }
-
- it("should parse correctly complex conditional with or and and
primaries") {
- val source = "{ if (1 != a.getValue() && \"hello\" != \"wolrd\" ||
50 == myVar) { } }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (|| (&& (!= 1 (. a getValue
ARGS)) (!= \"hello\" \"wolrd\")) (== 50 myVar)))");
- }
-
- it("should parse correctly greater than conditional") {
- val source = "{ if (1 > 3) {} }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (> 1 3))");
- }
-
- it("should parse correctly lesser than conditional") {
- val source = "{ if (1 < 3) {} }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (< 1 3))");
- }
-
- it("should parse correctly greater than or equal conditional") {
- val source = "{ if (1 >= 3) {} }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (>= 1 3))");
- }
-
- it("should parse correctly lesser than or equal conditional") {
- val source = "{ if (1 <= 3) {} }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(IF (<= 1 3))");
- }
-
- it("should parse regular expression") {
- val source = "{ boolean b = false; if (b = true) {} }";
- val ifBlock = parser.parseBlock(source);
-
- ifBlock.toStringTree() should be("(= boolean b false) (IF (= b
true))");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/InterfaceSpec.scala Mon Oct 19
22:50:22 2009
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class InterfaceSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("interface") {
-
- it("should parse an interface with no methods") {
- val source = "interface MyInterface {}";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(INTERFACE MyInterface)");
- }
-
- it("should parse an interface with one method") {
- val source = "interface MyInterface { Int helloWorld(); }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(INTERFACE MyInterface
(METHOD (RETURN_TYPE Int) helloWorld))");
- }
-
- it("should not parse an interface with a method having a body") {
- val source = "interface MyInterface { Int helloWorld() { Int i = 0;
} }";
-
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/InterpretableSpec.scala Thu Oct 8
10:25:57 2009
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class InterpretableSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("the parser") {
-
- it("should parse an import as interpretable") {
- val source = "import noop.Foo;";
- parser.parseInterpretable(source).toStringTree() should equal (
- "(import noop Foo)");
- }
-
- it("should parse a class definition as interpretable") {
- val source = "class F() {}";
- parser.parseInterpretable(source).toStringTree() should equal (
- "(CLASS F)");
- }
-
- it("should parse a variable declaratian as interpretable") {
- val source = "Int a = 3;";
- parser.parseInterpretable(source).toStringTree() should equal (
- "(VAR Int (= a 3))");
- }
-
- it("should parse several statements at once") {
- val source = """Int a = 3; import foo.Foo; String b = "poop"; class
F() {}""";
- parser.parseInterpretable(source).toStringTree() should equal (
- """(VAR Int (= a 3)) (import foo Foo) (VAR String (= b "poop"))
(CLASS F)""");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/LiteralsSpec.scala Thu Oct 8
10:25:57 2009
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import model.{BooleanLiteralExpression, IdentifierDeclarationExpression};
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class LiteralsSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("the parser") {
-
- it("should parse integer literals") {
- val source = "{ Int a = 123; Int b = -123; } ";
- parser.parseBlock(source).toStringTree() should equal (
- "(VAR Int (= a 123)) (VAR Int (= b -123))");
- }
-
- it("should parse a string literal") {
- val source = " { a = \"hello, world!\"; } ";
- parser.parseBlock(source).toStringTree() should equal (
- "(= a \"hello, world!\")");
- }
-
- it("should parse a multi-line string literal") {
- val source = "{ String a = \"\"\"Line1\n\"Line2\"\n\"\"\"; }";
- parser.parseBlock(source).toStringTree() should equal(
- "(VAR String (= a \"\"\"Line1\n\"Line2\"\n\"\"\"))");
- }
-
- it("should not allow a single-double-quoted string to span lines") {
- val source = """{ a = "Line 1
- "; }""";
- intercept[ParseException] (parser.parseBlock(source));
- }
-
- it("should parse boolean literals") {
- val source = "{ Boolean a = true; }";
- parser.parseBlock(source).toStringTree() should equal ("(VAR Boolean
(= a true))");
- val statement =
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0)
- .asInstanceOf[IdentifierDeclarationExpression];
- statement.initialValue match {
- case Some(b) => {
- b.getClass() should be (classOf[BooleanLiteralExpression]);
- b.asInstanceOf[BooleanLiteralExpression].value should be (true);
- }
- case None => fail();
- }
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/LoopSpec.scala Thu Oct 8 10:25:57
2009
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import model.{BooleanLiteralExpression, WhileLoop};
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class LoopSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("a while loop") {
-
- it("should be formed with a while statement") {
- val source = "{ while(true) {} }";
- parser.parseBlock(source).toStringTree() should be ("(WHILE true)");
- val block =
parser.buildTreeParser(parser.parseBlock(source)).block();
- block.statements(0).getClass() should be (classOf[WhileLoop]);
- val whileLoop = block.statements(0).asInstanceOf[WhileLoop];
-
whileLoop.continueCondition.asInstanceOf[BooleanLiteralExpression].value
should be(true);
- }
- }
-
- describe("a for loop") {
-
- it("should be formed with a for-in statement") {
- val source = "{ for (Int i in 1.to(10)) {} }";
- parser.parseBlock(source).toStringTree() should be("(FOREACH (VAR
Int i) (. 1 to (ARGS 10)))");
- }
-
- it("should allow an existing identifier to be the loop variable") {
- val source = "{ Int i; for (i in 1.to(10)) {} }";
- parser.parseBlock(source).toStringTree() should be("(VAR Int i)
(FOREACH i (. 1 to (ARGS 10)))");
- }
-
- it("should allow a c-style loop with explicit initialization,
termination, and iteration expressions") {
- val source = "{ for (Int i = 1; i < 3; i = i + 1) {} }";
- parser.parseBlock(source).toStringTree() should be("(FOR (VAR Int (=
i 1)) (< i 3) (= i (+ i 1)))");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/MethodsSpec.scala Sat Oct 24 14:47:55
2009
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import model.{IdentifierDeclarationExpression, Modifier};
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class MethodsSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("the parser") {
-
- it("should parse a method with no parameters") {
- val source = "class Bar() { String helloWorld() { Int i = 1; } }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar (METHOD
(RETURN_TYPE String) helloWorld " +
- "(VAR Int (= i 1))))");
- }
-
- it("should parse a method with parameters") {
- val source = "class Bar() { String helloWorld(String s, Int n) { Int
i = 1; } }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar (METHOD
(RETURN_TYPE String) helloWorld " +
- "(PARAMS (PARAM String s) (PARAM Int n)) (VAR Int (= i 1))))");
-
- val file = parser.file(source);
- file.classDef.methods.size should be (1);
- val firstMethod = file.classDef.methods(0)
- firstMethod.name should be ("helloWorld");
- firstMethod.returnTypes.size should be (1);
- firstMethod.returnTypes(0) should be ("String");
- firstMethod.parameters.size should be (2);
- firstMethod.parameters(0).name should be ("s");
- firstMethod.parameters(0).noopType should be ("String");
- firstMethod.parameters(1).name should be ("n");
- firstMethod.parameters(1).noopType should be ("Int");
- firstMethod.block.statements.size should be (1);
- firstMethod.block.statements(0).getClass() should be
(classOf[IdentifierDeclarationExpression]);
- val firstStatement =
firstMethod.block.statements(0).asInstanceOf[IdentifierDeclarationExpression];
- firstStatement.noopType should be ("Int");
- firstStatement.name should be ("i");
- // firstStatement.initialValue should be (Some(new
IntLiteralExpression(1)));
- }
-
- it("should allow variable declaration without an initial value") {
- val source = "class Bar() { String helloWorld() { Int i; } }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal ("(CLASS Bar (METHOD
(RETURN_TYPE String) helloWorld " +
- "(VAR Int i)))");
-
- val file = parser.file(source);
- file.classDef.methods.size should be (1);
- val firstMethod = file.classDef.methods(0)
- val firstStatement =
firstMethod.block.statements(0).asInstanceOf[IdentifierDeclarationExpression];
-
- firstStatement.noopType should be ("Int");
- firstStatement.name should be ("i");
- firstStatement.initialValue should be (None);
- }
-
- it("should parse a method invocation on a parameter reference") {
- val source = """class HelloWorld() { Int hello() {
console.println("Hello, World!"); }}""";
- parser.parseFile(source).toStringTree() should equal(
- """(CLASS HelloWorld (METHOD (RETURN_TYPE Int) hello (. console
println (ARGS "Hello, World!"))))""");
- }
-
- it("should parse a method with a return statement") {
- val source = "class Foo() { Void do() { return 4; } }";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Foo (METHOD (RETURN_TYPE Void) do (return 4)))");
- }
-
- it("should allow the native modifier on a method") {
- val source = "class Foo() { native Void do() { Int i; }}";
- parser.parseFile(source).toStringTree() should equal (
- "(CLASS Foo (METHOD (MOD native) (RETURN_TYPE Void) do (VAR Int
i)))");
- val file = parser.file(source);
- file.classDef.methods(0).modifiers should contain(Modifier.native);
- }
-
- it("should parse a method with one return type (no parentheses)") {
- val source = "class Math() { Int calculate() {} }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal (
- "(CLASS Math (METHOD (RETURN_TYPE Int) calculate))");
-
- val file = parser.file(source);
- file.classDef.methods.size should be (1);
- val firstMethod = file.classDef.methods(0);
- firstMethod.name should be ("calculate");
- firstMethod.returnTypes.size should be (1);
- firstMethod.returnTypes(0) should be ("Int");
- firstMethod.parameters.size should be (0);
- firstMethod.block.statements.size should be (0);
- }
-
- it("should parse a method with one return type (parentheses)") {
- val source = "class Math() { (Int) calculate() {} }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal (
- "(CLASS Math (METHOD (RETURN_TYPE Int) calculate))");
-
- val file = parser.file(source);
- file.classDef.methods.size should be (1);
- val firstMethod = file.classDef.methods(0);
- firstMethod.name should be ("calculate");
- firstMethod.returnTypes.size should be (1);
- firstMethod.returnTypes(0) should be ("Int");
- firstMethod.parameters.size should be (0);
- firstMethod.block.statements.size should be (0);
- }
-
- it("should parse a method with multiple return types") {
- val source = "class Math() { (Int, Int) calculate() {} }";
- val commonTree = parser.parseFile(source);
-
- commonTree.toStringTree() should equal (
- "(CLASS Math (METHOD (RETURN_TYPE Int Int) calculate))");
-
- val file = parser.file(source);
- file.classDef.methods.size should be (1);
- val firstMethod = file.classDef.methods(0);
- firstMethod.name should be ("calculate");
- firstMethod.returnTypes.size should be (2);
- firstMethod.returnTypes(0) should be ("Int");
- firstMethod.returnTypes(1) should be ("Int");
- firstMethod.parameters.size should be (0);
- firstMethod.block.statements.size should be (0);
- }
-
- it ("should NOT parse a method with one named return parameter (no
parentheses)") {
- val source = "class Math() { Int a calculate() {} }";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
-
- it ("should NOT parse a method with one named return parameter
(parentheses)") {
- val source = "class Math() { (Int a) calculate() {} }";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
-
- it ("should NOT parse a method with a mixture of named and unnamed
return parameters") {
- val source = "class Math() { (Int, Int b, Int) calculate() {} }";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
-
- it ("should NOT parse a method with multiple named return parameters")
{
- val source = "class Math() { (Int a, Int b) calcualte() {} }";
- intercept[ParseException] {
- parser.parseFile(source);
- }
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/ParseExamplesTest.scala Tue Nov 17
20:37:51 2009
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar
-
-import org.scalatest.Spec
-import org.scalatest.matchers.ShouldMatchers
-import java.io.{FileInputStream, File}
-
-class ParseExamplesTest extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("the parser") {
- it("should parse all the .noop files found under the /examples
directory") {
- val examplesDir = new File(new
File(System.getProperty("user.dir")), "examples");
- parseAllFilesInDirectory(examplesDir);
- }
- }
-
- def parseAllFilesInDirectory(dir: File): Unit = {
- for (file: File <- dir.listFiles) {
- if (file.isDirectory) {
- parseAllFilesInDirectory(file);
- } else {
- if (file.getName.endsWith(".noop")) {
- try {
- parser.parseFile(new FileInputStream(file));
- } catch {
- case e: ParseException => fail("failed to parse " +
file.getAbsolutePath());
- }
- }
- }
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/ParserSpec.scala Mon Oct 19 22:50:22
2009
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class ParserSpec extends Spec with ShouldMatchers {
-
- describe("our parser") {
-
- it("should throw an exception if there's an error parsing the AST") {
- val source = "class MyClass() { Int foo() { Int result =
List.List(List()); } }";
- val parser = new Parser();
- parser.parseFile(source).toStringTree() should be (
- "(CLASS MyClass (METHOD (RETURN_TYPE Int) foo (VAR Int (= result
(. List List (ARGS List ARGS))))))");
- intercept[ParseException] {
- val classDef = parser.file(source);
- }
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/PropertiesSpec.scala Thu Oct 8
10:25:57 2009
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- * @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
- */
-class PropertiesSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("parser") {
-
- it("should parse a single property declaration") {
- val source = """
- class Foo() {
- Int a = 4;
- Int i;
- }
- """;
-
- parser.parseFile(source).toStringTree() should equal ("(CLASS Foo
(VAR Int (= a 4)) (VAR Int i))");
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/TestSpec.scala Thu Oct 8 10:25:57
2009
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
-
-import model.ShouldExpression;
-
-/**
- * @author alex...@google.com (Alex Eagle)
- */
-class TestSpec extends Spec with ShouldMatchers {
-
- val parser = new Parser();
-
- describe("test block declarations") {
-
- it("should allow a unittest block in a class") {
- val source = "class Foo() { unittest \"testing 123\" {} }";
- parser.parseFile(source).toStringTree() should equal(
- "(CLASS Foo (UNITTEST \"testing 123\"))");
- val classDef = parser.file(source).classDef;
- classDef.methods should have length(0);
- classDef.unittests should have length(1);
- classDef.unittests(0).name should be("testing 123");
- }
-
- it("should not allow a unittest block in a method") {
- val source = "class Foo() { Int do() { unittest \"testing 123\" {} }
}";
- intercept[ParseException] (
- parser.parseFile(source)
- );
- }
-
- it("should not allow a test block in a class") {
- val source = "class Foo() { test \"testing 123\" {} }";
- intercept[ParseException] (
- parser.parseFile(source)
- );
- }
-
- it("should allow a test block in a file") {
- val source = "test \"testing 123\" {}";
- parser.parseFile(source).toStringTree() should equal("(TEST
\"testing 123\")");
- }
-
- it("should allow a unittest block in a test block") {
- val source = "test \"testing 123\" { unittest \"it should work\" {}
}";
- parser.parseFile(source).toStringTree() should equal(
- "(TEST \"testing 123\" (UNITTEST \"it should work\"))");
- }
-
- it("should allow a test block in a test block") {
- val source = "test \"testing 123\" { test \"it should work\" {} }";
- parser.parseFile(source).toStringTree() should equal(
- "(TEST \"testing 123\" (TEST \"it should work\"))");
- }
-
- it("should not allow a unittest block in a unittest block") {
- val source = "unittest \"testing 123\" { unittest \"it should work\"
{} }";
- intercept[ParseException] (
- parser.parseFile(source)
- );
- }
- }
-
- describe("the testing DSL") {
-
- it("should have a 'should' operator") {
- val source = "{ 1 should equal(1); }";
- parser.parseBlock(source).toStringTree() should be("(should 1 equal
(ARGS 1))");
- val statement =
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0);
- statement.getClass() should be(classOf[ShouldExpression]);
- }
- }
-}
=======================================
--- /core/src/test/scala/noop/grammar/TryCatchSpec.scala Tue Nov 17
20:37:51 2009
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package noop.grammar
-
-import org.scalatest.matchers.ShouldMatchers
-import org.scalatest.Spec
-
-class TryCatchSpec extends Spec with ShouldMatchers {
- val parser = new Parser();
-
- describe("the parser") {
- it("should parse a try-catch block") {
- val source = "{ try { parseInt(\"1\"); } catch { println(\"oops\");
} }";
- parser.parseBlock(source).toStringTree() should equal (
- "(TRY parseInt (ARGS \"1\") CATCH println (ARGS \"oops\"))");
- }
-
- it("should parse a try-finally block") {
- val source = "{ try { parseInt(\"1\"); } finally { cleanup(); } }";
- parser.parseBlock(source).toStringTree() should equal (
- "(TRY parseInt (ARGS \"1\") FINALLY cleanup ARGS)");
- }
-
- it("should parse a try-catch-finally block") {
- val source = "{ try { parseInt(\"1\"); } catch { println(\"oops\");
} finally { cleanup(); } }";
- parser.parseBlock(source).toStringTree() should equal (
- "(TRY parseInt (ARGS \"1\") CATCH println (ARGS \"oops\")
FINALLY cleanup ARGS)");
- }
- }
-
-}
=======================================
--- /interpreter/noop-interpreter.iml Wed Nov 25 15:29:16 2009
+++ /dev/null
@@ -1,158 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module relativePaths="false" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="Scala" name="Scala">
- <configuration />
- </facet>
- </component>
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/target/classes" />
- <output-test url="file://$MODULE_DIR$/target/test-classes" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/scala"
isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/target/resources"
isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/scala"
isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/noop"
isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/../examples/noop"
isTestSource="false" />
- <excludeFolder url="file://$MODULE_DIR$/target/classes" />
- </content>
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="module" module-name="noop-core" />
- <orderEntry type="inheritedJdk" />
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.5/scala-library-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-lang/scala-compiler/2.7.5/scala-compiler-2.7.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr-runtime/3.1.1/antlr-runtime-3.1.1.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr-runtime/3.1.1/antlr-runtime-3.1.1-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-nop/1.5.6/slf4j-nop-1.5.6-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/aopalliance/aopalliance/1.0/aopalliance-1.0.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/2.0/guice-2.0.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/com/google/inject/guice/2.0/guice-2.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/com/google/inject/extensions/guice-assisted-inject/2.0/guice-assisted-inject-2.0.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/com/google/inject/extensions/guice-assisted-inject/2.0/guice-assisted-inject-2.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalacheck/1.5/scalacheck-1.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/jmock/jmock/1.2.0/jmock-1.2.0-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library">
- <library>
- <CLASSES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5.jar!/"
/>
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root
url="jar://$MAVEN_REPOSITORY$/org/scala-tools/testing/scalatest/0.9.5/scalatest-0.9.5-sources.jar!/"
/>
- </SOURCES>
- </library>
- </orderEntry>
- </component>
-</module>
-
=======================================
--- /noop.ipr Wed Nov 25 12:28:55 2009
+++ /dev/null
@@ -1,262 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="AntConfiguration">
- <defaultAnt bundledAnt="true" />
- </component>
- <component name="BuildJarProjectSettings">
- <option name="BUILD_JARS_ON_MAKE" value="false" />
- </component>
- <component name="CodeStyleManager">
- <option name="USE_DEFAULT_CODE_STYLE_SCHEME" value="true" />
- <option name="CODE_STYLE_SCHEME" value="" />
- </component>
- <component name="CodeStyleProjectProfileManger">
- <option name="PROJECT_PROFILE" />
- <option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
- </component>
- <component name="CompilerConfiguration">
- <option name="DEFAULT_COMPILER" value="Javac" />
- <resourceExtensions />
- <wildcardResourcePatterns>
- <entry name="!?*.java" />
- </wildcardResourcePatterns>
- <annotationProcessing enabled="false" useClasspath="true" />
- </component>
- <component name="CopyrightManager" default="">
- <module2copyright />
- </component>
- <component name="DependenciesAnalyzeManager">
- <option name="myForwardDirection" value="false" />
- </component>
- <component name="DependencyValidationManager">
- <option name="SKIP_IMPORT_STATEMENTS" value="false" />
- </component>
- <component name="EclipseCompilerSettings">
- <option name="DEBUGGING_INFO" value="true" />
- <option name="GENERATE_NO_WARNINGS" value="true" />
- <option name="DEPRECATION" value="false" />
- <option name="ADDITIONAL_OPTIONS_STRING" value="" />
- <option name="MAXIMUM_HEAP_SIZE" value="128" />
- </component>
- <component name="EclipseEmbeddedCompilerSettings">
- <option name="DEBUGGING_INFO" value="true" />
- <option name="GENERATE_NO_WARNINGS" value="true" />
- <option name="DEPRECATION" value="false" />
- <option name="ADDITIONAL_OPTIONS_STRING" value="" />
- <option name="MAXIMUM_HEAP_SIZE" value="128" />
- </component>
- <component name="Encoding" useUTFGuessing="true"
native2AsciiForPropertiesFiles="false" />
- <component name="EntryPointsManager">
- <entry_points />
- </component>
- <component name="ExportToHTMLSettings">
- <option name="PRINT_LINE_NUMBERS" value="false" />
- <option name="OPEN_IN_BROWSER" value="false" />
- <option name="OUTPUT_DIRECTORY" />
- </component>
- <component name="IdProvider"
IDEtalkID="0246D33576B8D4BC3331F9A5BB848389" />
- <component name="ImportConfiguration">
- <option name="VENDOR" />
- <option name="RELEASE_TAG" />
- <option name="LOG_MESSAGE" />
- <option name="CHECKOUT_AFTER_IMPORT" value="true" />
- </component>
- <component name="JUnitProjectSettings">
- <option name="TEST_RUNNER" value="UI" />
- </component>
- <component name="JavacSettings">
- <option name="DEBUGGING_INFO" value="true" />
- <option name="GENERATE_NO_WARNINGS" value="false" />
- <option name="DEPRECATION" value="true" />
- <option name="ADDITIONAL_OPTIONS_STRING" value="" />
- <option name="MAXIMUM_HEAP_SIZE" value="128" />
- </component>
- <component name="JavadocGenerationManager">
- <option name="OUTPUT_DIRECTORY" />
- <option name="OPTION_SCOPE" value="protected" />
- <option name="OPTION_HIERARCHY" value="false" />
- <option name="OPTION_NAVIGATOR" value="false" />
- <option name="OPTION_INDEX" value="false" />
- <option name="OPTION_SEPARATE_INDEX" value="false" />
- <option name="OPTION_DOCUMENT_TAG_USE" value="false" />
- <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
- <option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
- <option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="false" />
- <option name="OPTION_DEPRECATED_LIST" value="false" />
- <option name="OTHER_OPTIONS" />
- <option name="HEAP_SIZE" />
- <option name="LOCALE" />
- <option name="OPEN_IN_BROWSER" value="false" />
- </component>
- <component name="JikesSettings">
- <option name="JIKES_PATH" value="" />
- <option name="DEBUGGING_INFO" value="true" />
- <option name="DEPRECATION" value="true" />
- <option name="GENERATE_NO_WARNINGS" value="false" />
- <option name="IS_EMACS_ERRORS_MODE" value="true" />
- <option name="ADDITIONAL_OPTIONS_STRING" value="" />
- </component>
- <component name="LogConsolePreferences">
- <option name="FILTER_ERRORS" value="false" />
- <option name="FILTER_WARNINGS" value="false" />
- <option name="FILTER_INFO" value="true" />
- <option name="CUSTOM_FILTER" />
- </component>
- <component name="Palette2">
- <group name="Swing">
- <item class="com.intellij.uiDesigner.HSpacer"
tooltip-text="Horizontal Spacer"
icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="1" hsize-policy="6" anchor="0"
fill="1" />
- </item>
- <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical
Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="1" anchor="0"
fill="2" />
- </item>
- <item class="javax.swing.JPanel"
icon="/com/intellij/uiDesigner/icons/panel.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0"
fill="3" />
- </item>
- <item class="javax.swing.JScrollPane"
icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false"
auto-create-binding="false" can-attach-label="true">
- <default-constraints vsize-policy="7" hsize-policy="7" anchor="0"
fill="3" />
- </item>
- <item class="javax.swing.JButton"
icon="/com/intellij/uiDesigner/icons/button.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="0"
fill="1" />
- <initial-values>
- <property name="text" value="Button" />
- </initial-values>
- </item>
- <item class="javax.swing.JRadioButton"
icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="8"
fill="0" />
- <initial-values>
- <property name="text" value="RadioButton" />
- </initial-values>
- </item>
- <item class="javax.swing.JCheckBox"
icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="8"
fill="0" />
- <initial-values>
- <property name="text" value="CheckBox" />
- </initial-values>
- </item>
- <item class="javax.swing.JLabel"
icon="/com/intellij/uiDesigner/icons/label.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="0" anchor="8"
fill="0" />
- <initial-values>
- <property name="text" value="Label" />
- </initial-values>
- </item>
- <item class="javax.swing.JTextField"
icon="/com/intellij/uiDesigner/icons/textField.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8"
fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JPasswordField"
icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8"
fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JFormattedTextField"
icon="/com/intellij/uiDesigner/icons/formattedTextField.png"
removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8"
fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTextArea"
icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTextPane"
icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JEditorPane"
icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JComboBox"
icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="2" anchor="8"
fill="1" />
- </item>
- <item class="javax.swing.JTable"
icon="/com/intellij/uiDesigner/icons/table.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JList"
icon="/com/intellij/uiDesigner/icons/list.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="2" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTree"
icon="/com/intellij/uiDesigner/icons/tree.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTabbedPane"
icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0"
fill="3">
- <preferred-size width="200" height="200" />
- </default-constraints>
- </item>
- <item class="javax.swing.JSplitPane"
icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0"
fill="3">
- <preferred-size width="200" height="200" />
- </default-constraints>
- </item>
- <item class="javax.swing.JSpinner"
icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false"
auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8"
fill="1" />
- </item>
- <item class="javax.swing.JSlider"
icon="/com/intellij/uiDesigner/icons/slider.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8"
fill="1" />
- </item>
- <item class="javax.swing.JSeparator"
icon="/com/intellij/uiDesigner/icons/separator.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0"
fill="3" />
- </item>
- <item class="javax.swing.JProgressBar"
icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="0"
fill="1" />
- </item>
- <item class="javax.swing.JToolBar"
icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false"
auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="0"
fill="1">
- <preferred-size width="-1" height="20" />
- </default-constraints>
- </item>
- <item class="javax.swing.JToolBar$Separator"
icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png"
removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="0" anchor="0"
fill="1" />
- </item>
- <item class="javax.swing.JScrollBar"
icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false"
auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="0" anchor="0"
fill="2" />
- </item>
- </group>
- </component>
- <component name="ProjectDetails">
- <option name="projectName" value="noop" />
- </component>
- <component name="ProjectModuleManager">
- <modules>
- <module fileurl="file://$PROJECT_DIR$/examples/examples.iml"
filepath="$PROJECT_DIR$/examples/examples.iml" />
- <module fileurl="file://$PROJECT_DIR$/compiler/noop-compiler.iml"
filepath="$PROJECT_DIR$/compiler/noop-compiler.iml" />
- <module fileurl="file://$PROJECT_DIR$/core/noop-core.iml"
filepath="$PROJECT_DIR$/core/noop-core.iml" />
- <module
fileurl="file://$PROJECT_DIR$/interpreter/noop-interpreter.iml"
filepath="$PROJECT_DIR$/interpreter/noop-interpreter.iml" />
- </modules>
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6"
assert-keyword="true" jdk-15="true" project-jdk-name="1.6"
project-jdk-type="JavaSDK" />
- <component name="RmicSettings">
- <option name="IS_EANABLED" value="false" />
- <option name="DEBUGGING_INFO" value="true" />
- <option name="GENERATE_NO_WARNINGS" value="false" />
- <option name="GENERATE_IIOP_STUBS" value="false" />
- <option name="ADDITIONAL_OPTIONS_STRING" value="" />
- </component>
- <component name="SvnBranchConfigurationManager">
- <option name="mySupportsUserInfoFilter" value="true" />
- </component>
- <component name="VcsDirectoryMappings">
- <mapping directory="" vcs="hg4idea" />
- </component>
- <component name="com.intellij.jsf.UserDefinedFacesConfigs">
- <option name="USER_DEFINED_CONFIGS">
- <value>
- <list size="0" />
- </value>
- </option>
- </component>
- <component name="hg4idea.settings">
- <option name="checkIncoming" value="false" />
- </component>
-</project>
-
==============================================================================
Revision: 426d8306e5
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 19:07:04 2010
Log: Convert expressions in the AST to proto-based. Still need to fix
interpreter tests.
http://code.google.com/p/noop/source/detail?r=426d8306e5
Added:
/core/src/main/scala/noop/model/StatementWrapper.scala
Modified:
/core/src/main/java/noop/model/proto/NoopAst.java
/core/src/main/proto/noop_ast.proto
/core/src/main/scala/noop/model/AssignmentExpression.scala
/core/src/main/scala/noop/model/BindingDeclaration.scala
/core/src/main/scala/noop/model/ConditionalAndExpression.scala
/core/src/main/scala/noop/model/ConditionalOrExpression.scala
/core/src/main/scala/noop/model/DereferenceExpression.scala
/core/src/main/scala/noop/model/ExpressionWrapper.scala
/core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
/core/src/main/scala/noop/model/MethodInvocationExpression.scala
/core/src/main/scala/noop/model/OperatorExpression.scala
/core/src/main/scala/noop/model/ReturnExpression.scala
/core/src/main/scala/noop/model/ShouldExpression.scala
/grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g
/grammar/src/test/scala/noop/grammar/BindingSpec.scala
/grammar/src/test/scala/noop/grammar/BlockSpec.scala
/grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala
/grammar/src/test/scala/noop/grammar/LiteralsSpec.scala
/grammar/src/test/scala/noop/grammar/TestSpec.scala
=======================================
--- /dev/null
+++ /core/src/main/scala/noop/model/StatementWrapper.scala Mon Feb 1
19:07:04 2010
@@ -0,0 +1,22 @@
+package noop.model
+
+import proto.NoopAst.Stmt
+import proto.NoopAst.Stmt.Type
+
+/**
+ * @author alex...@google.com (Alex Eagle)
+ */
+
+class StatementWrapper(data: Stmt) extends Expression {
+ def accept(visitor: Visitor): Unit = {
+ getTypedExpression.accept(visitor);
+ }
+
+ def getTypedExpression: Expression = {
+ data.getType match {
+ case Type.SHOULD => {
+ new ShouldExpression(data.getShould)
+ }
+ }
+ }
+}
=======================================
--- /core/src/main/java/noop/model/proto/NoopAst.java Fri Dec 18 10:05:00
2009
+++ /core/src/main/java/noop/model/proto/NoopAst.java Mon Feb 1 19:07:04
2010
@@ -7,6 +7,1199 @@
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
}
+ public static final class Stmt extends
+ com.google.protobuf.GeneratedMessage {
+ // Use Stmt.newBuilder() to construct.
+ private Stmt() {}
+
+ private static final Stmt defaultInstance = new Stmt();
+ public static Stmt getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public Stmt getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return noop.model.proto.NoopAst.internal_static_Stmt_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return
noop.model.proto.NoopAst.internal_static_Stmt_fieldAccessorTable;
+ }
+
+ public enum Type
+ implements com.google.protobuf.ProtocolMessageEnum {
+ RETURN(0, 1),
+ SHOULD(1, 2),
+ EXPRESSION(2, 3),
+ ;
+
+
+ public final int getNumber() { return value; }
+
+ public static Type valueOf(int value) {
+ switch (value) {
+ case 1: return RETURN;
+ case 2: return SHOULD;
+ case 3: return EXPRESSION;
+ default: return null;
+ }
+ }
+
+ public static com.google.protobuf.Internal.EnumLiteMap<Type>
+ internalGetValueMap() {
+ return internalValueMap;
+ }
+ private static com.google.protobuf.Internal.EnumLiteMap<Type>
+ internalValueMap =
+ new com.google.protobuf.Internal.EnumLiteMap<Type>() {
+ public Type findValueByNumber(int number) {
+ return Type.valueOf(number)
+ ; }
+ };
+
+ public final com.google.protobuf.Descriptors.EnumValueDescriptor
+ getValueDescriptor() {
+ return getDescriptor().getValues().get(index);
+ }
+ public final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptorForType() {
+ return getDescriptor();
+ }
+ public static final com.google.protobuf.Descriptors.EnumDescriptor
+ getDescriptor() {
+ return
noop.model.proto.NoopAst.Stmt.getDescriptor().getEnumTypes().get(0);
+ }
+
+ private static final Type[] VALUES = {
+ RETURN, SHOULD, EXPRESSION,
+ };
+ public static Type valueOf(
+ com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+ if (desc.getType() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "EnumValueDescriptor is not for this type.");
+ }
+ return VALUES[desc.getIndex()];
+ }
+ private final int index;
+ private final int value;
+ private Type(int index, int value) {
+ this.index = index;
+ this.value = value;
+ }
+
+ static {
+ noop.model.proto.NoopAst.getDescriptor();
+ }
+ }
+
+ // required .Stmt.Type type = 1;
+ public static final int TYPE_FIELD_NUMBER = 1;
+ private boolean hasType;
+ private noop.model.proto.NoopAst.Stmt.Type type_ =
noop.model.proto.NoopAst.Stmt.Type.RETURN;
+ public boolean hasType() { return hasType; }
+ public noop.model.proto.NoopAst.Stmt.Type getType() { return type_; }
+
+ // optional .ReturnStatement return = 2;
+ public static final int RETURN_FIELD_NUMBER = 2;
+ private boolean hasReturn;
+ private noop.model.proto.NoopAst.ReturnStatement return_ =
noop.model.proto.NoopAst.ReturnStatement.getDefaultInstance();
+ public boolean hasReturn() { return hasReturn; }
+ public noop.model.proto.NoopAst.ReturnStatement getReturn() { return
return_; }
+
+ // optional .ShouldStatement should = 3;
+ public static final int SHOULD_FIELD_NUMBER = 3;
+ private boolean hasShould;
+ private noop.model.proto.NoopAst.ShouldStatement should_ =
noop.model.proto.NoopAst.ShouldStatement.getDefaultInstance();
+ public boolean hasShould() { return hasShould; }
+ public noop.model.proto.NoopAst.ShouldStatement getShould() { return
should_; }
+
+ // optional .Expr expression = 4;
+ public static final int EXPRESSION_FIELD_NUMBER = 4;
+ private boolean hasExpression;
+ private noop.model.proto.NoopAst.Expr expression_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ public boolean hasExpression() { return hasExpression; }
+ public noop.model.proto.NoopAst.Expr getExpression() { return
expression_; }
+
+ public final boolean isInitialized() {
+ if (!hasType) return false;
+ if (hasReturn()) {
+ if (!getReturn().isInitialized()) return false;
+ }
+ if (hasShould()) {
+ if (!getShould().isInitialized()) return false;
+ }
+ if (hasExpression()) {
+ if (!getExpression().isInitialized()) return false;
+ }
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (hasType()) {
+ output.writeEnum(1, getType().getNumber());
+ }
+ if (hasReturn()) {
+ output.writeMessage(2, getReturn());
+ }
+ if (hasShould()) {
+ output.writeMessage(3, getShould());
+ }
+ if (hasExpression()) {
+ output.writeMessage(4, getExpression());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasType()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeEnumSize(1, getType().getNumber());
+ }
+ if (hasReturn()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(2, getReturn());
+ }
+ if (hasShould()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(3, getShould());
+ }
+ if (hasExpression()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(4, getExpression());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt
parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt
parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.Stmt parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(noop.model.proto.NoopAst.Stmt
prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder> {
+ private noop.model.proto.NoopAst.Stmt result;
+
+ // Construct using noop.model.proto.NoopAst.Stmt.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new noop.model.proto.NoopAst.Stmt();
+ return builder;
+ }
+
+ protected noop.model.proto.NoopAst.Stmt internalGetResult() {
+ return result;
+ }
+
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new noop.model.proto.NoopAst.Stmt();
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return noop.model.proto.NoopAst.Stmt.getDescriptor();
+ }
+
+ public noop.model.proto.NoopAst.Stmt getDefaultInstanceForType() {
+ return noop.model.proto.NoopAst.Stmt.getDefaultInstance();
+ }
+
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ public noop.model.proto.NoopAst.Stmt build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private noop.model.proto.NoopAst.Stmt buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ public noop.model.proto.NoopAst.Stmt buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ noop.model.proto.NoopAst.Stmt returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof noop.model.proto.NoopAst.Stmt) {
+ return mergeFrom((noop.model.proto.NoopAst.Stmt)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(noop.model.proto.NoopAst.Stmt other) {
+ if (other == noop.model.proto.NoopAst.Stmt.getDefaultInstance())
return this;
+ if (other.hasType()) {
+ setType(other.getType());
+ }
+ if (other.hasReturn()) {
+ mergeReturn(other.getReturn());
+ }
+ if (other.hasShould()) {
+ mergeShould(other.getShould());
+ }
+ if (other.hasExpression()) {
+ mergeExpression(other.getExpression());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 8: {
+ int rawValue = input.readEnum();
+ noop.model.proto.NoopAst.Stmt.Type value =
noop.model.proto.NoopAst.Stmt.Type.valueOf(rawValue);
+ if (value == null) {
+ unknownFields.mergeVarintField(1, rawValue);
+ } else {
+ setType(value);
+ }
+ break;
+ }
+ case 18: {
+ noop.model.proto.NoopAst.ReturnStatement.Builder subBuilder
= noop.model.proto.NoopAst.ReturnStatement.newBuilder();
+ if (hasReturn()) {
+ subBuilder.mergeFrom(getReturn());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setReturn(subBuilder.buildPartial());
+ break;
+ }
+ case 26: {
+ noop.model.proto.NoopAst.ShouldStatement.Builder subBuilder
= noop.model.proto.NoopAst.ShouldStatement.newBuilder();
+ if (hasShould()) {
+ subBuilder.mergeFrom(getShould());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setShould(subBuilder.buildPartial());
+ break;
+ }
+ case 34: {
+ noop.model.proto.NoopAst.Expr.Builder subBuilder =
noop.model.proto.NoopAst.Expr.newBuilder();
+ if (hasExpression()) {
+ subBuilder.mergeFrom(getExpression());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setExpression(subBuilder.buildPartial());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // required .Stmt.Type type = 1;
+ public boolean hasType() {
+ return result.hasType();
+ }
+ public noop.model.proto.NoopAst.Stmt.Type getType() {
+ return result.getType();
+ }
+ public Builder setType(noop.model.proto.NoopAst.Stmt.Type value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasType = true;
+ result.type_ = value;
+ return this;
+ }
+ public Builder clearType() {
+ result.hasType = false;
+ result.type_ = noop.model.proto.NoopAst.Stmt.Type.RETURN;
+ return this;
+ }
+
+ // optional .ReturnStatement return = 2;
+ public boolean hasReturn() {
+ return result.hasReturn();
+ }
+ public noop.model.proto.NoopAst.ReturnStatement getReturn() {
+ return result.getReturn();
+ }
+ public Builder setReturn(noop.model.proto.NoopAst.ReturnStatement
value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasReturn = true;
+ result.return_ = value;
+ return this;
+ }
+ public Builder
setReturn(noop.model.proto.NoopAst.ReturnStatement.Builder builderForValue)
{
+ result.hasReturn = true;
+ result.return_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeReturn(noop.model.proto.NoopAst.ReturnStatement
value) {
+ if (result.hasReturn() &&
+ result.return_ !=
noop.model.proto.NoopAst.ReturnStatement.getDefaultInstance()) {
+ result.return_ =
+
noop.model.proto.NoopAst.ReturnStatement.newBuilder(result.return_).mergeFrom(value).buildPartial();
+ } else {
+ result.return_ = value;
+ }
+ result.hasReturn = true;
+ return this;
+ }
+ public Builder clearReturn() {
+ result.hasReturn = false;
+ result.return_ =
noop.model.proto.NoopAst.ReturnStatement.getDefaultInstance();
+ return this;
+ }
+
+ // optional .ShouldStatement should = 3;
+ public boolean hasShould() {
+ return result.hasShould();
+ }
+ public noop.model.proto.NoopAst.ShouldStatement getShould() {
+ return result.getShould();
+ }
+ public Builder setShould(noop.model.proto.NoopAst.ShouldStatement
value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasShould = true;
+ result.should_ = value;
+ return this;
+ }
+ public Builder
setShould(noop.model.proto.NoopAst.ShouldStatement.Builder builderForValue)
{
+ result.hasShould = true;
+ result.should_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeShould(noop.model.proto.NoopAst.ShouldStatement
value) {
+ if (result.hasShould() &&
+ result.should_ !=
noop.model.proto.NoopAst.ShouldStatement.getDefaultInstance()) {
+ result.should_ =
+
noop.model.proto.NoopAst.ShouldStatement.newBuilder(result.should_).mergeFrom(value).buildPartial();
+ } else {
+ result.should_ = value;
+ }
+ result.hasShould = true;
+ return this;
+ }
+ public Builder clearShould() {
+ result.hasShould = false;
+ result.should_ =
noop.model.proto.NoopAst.ShouldStatement.getDefaultInstance();
+ return this;
+ }
+
+ // optional .Expr expression = 4;
+ public boolean hasExpression() {
+ return result.hasExpression();
+ }
+ public noop.model.proto.NoopAst.Expr getExpression() {
+ return result.getExpression();
+ }
+ public Builder setExpression(noop.model.proto.NoopAst.Expr value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasExpression = true;
+ result.expression_ = value;
+ return this;
+ }
+ public Builder setExpression(noop.model.proto.NoopAst.Expr.Builder
builderForValue) {
+ result.hasExpression = true;
+ result.expression_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeExpression(noop.model.proto.NoopAst.Expr value) {
+ if (result.hasExpression() &&
+ result.expression_ !=
noop.model.proto.NoopAst.Expr.getDefaultInstance()) {
+ result.expression_ =
+
noop.model.proto.NoopAst.Expr.newBuilder(result.expression_).mergeFrom(value).buildPartial();
+ } else {
+ result.expression_ = value;
+ }
+ result.hasExpression = true;
+ return this;
+ }
+ public Builder clearExpression() {
+ result.hasExpression = false;
+ result.expression_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ return this;
+ }
+ }
+
+ static {
+ noop.model.proto.NoopAst.getDescriptor();
+ }
+
+ static {
+ noop.model.proto.NoopAst.internalForceInit();
+ }
+ }
+
+ public static final class ReturnStatement extends
+ com.google.protobuf.GeneratedMessage {
+ // Use ReturnStatement.newBuilder() to construct.
+ private ReturnStatement() {}
+
+ private static final ReturnStatement defaultInstance = new
ReturnStatement();
+ public static ReturnStatement getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public ReturnStatement getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return
noop.model.proto.NoopAst.internal_static_ReturnStatement_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return
noop.model.proto.NoopAst.internal_static_ReturnStatement_fieldAccessorTable;
+ }
+
+ // required .Expr returned = 1;
+ public static final int RETURNED_FIELD_NUMBER = 1;
+ private boolean hasReturned;
+ private noop.model.proto.NoopAst.Expr returned_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ public boolean hasReturned() { return hasReturned; }
+ public noop.model.proto.NoopAst.Expr getReturned() { return returned_;
}
+
+ public final boolean isInitialized() {
+ if (!hasReturned) return false;
+ if (!getReturned().isInitialized()) return false;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (hasReturned()) {
+ output.writeMessage(1, getReturned());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasReturned()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, getReturned());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement
parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement
parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement
parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement
parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ReturnStatement parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder
newBuilder(noop.model.proto.NoopAst.ReturnStatement prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder> {
+ private noop.model.proto.NoopAst.ReturnStatement result;
+
+ // Construct using
noop.model.proto.NoopAst.ReturnStatement.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new noop.model.proto.NoopAst.ReturnStatement();
+ return builder;
+ }
+
+ protected noop.model.proto.NoopAst.ReturnStatement
internalGetResult() {
+ return result;
+ }
+
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new noop.model.proto.NoopAst.ReturnStatement();
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return noop.model.proto.NoopAst.ReturnStatement.getDescriptor();
+ }
+
+ public noop.model.proto.NoopAst.ReturnStatement
getDefaultInstanceForType() {
+ return
noop.model.proto.NoopAst.ReturnStatement.getDefaultInstance();
+ }
+
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ public noop.model.proto.NoopAst.ReturnStatement build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private noop.model.proto.NoopAst.ReturnStatement buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ public noop.model.proto.NoopAst.ReturnStatement buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ noop.model.proto.NoopAst.ReturnStatement returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof noop.model.proto.NoopAst.ReturnStatement) {
+ return
mergeFrom((noop.model.proto.NoopAst.ReturnStatement)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(noop.model.proto.NoopAst.ReturnStatement
other) {
+ if (other ==
noop.model.proto.NoopAst.ReturnStatement.getDefaultInstance()) return this;
+ if (other.hasReturned()) {
+ mergeReturned(other.getReturned());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 10: {
+ noop.model.proto.NoopAst.Expr.Builder subBuilder =
noop.model.proto.NoopAst.Expr.newBuilder();
+ if (hasReturned()) {
+ subBuilder.mergeFrom(getReturned());
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ setReturned(subBuilder.buildPartial());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // required .Expr returned = 1;
+ public boolean hasReturned() {
+ return result.hasReturned();
+ }
+ public noop.model.proto.NoopAst.Expr getReturned() {
+ return result.getReturned();
+ }
+ public Builder setReturned(noop.model.proto.NoopAst.Expr value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasReturned = true;
+ result.returned_ = value;
+ return this;
+ }
+ public Builder setReturned(noop.model.proto.NoopAst.Expr.Builder
builderForValue) {
+ result.hasReturned = true;
+ result.returned_ = builderForValue.build();
+ return this;
+ }
+ public Builder mergeReturned(noop.model.proto.NoopAst.Expr value) {
+ if (result.hasReturned() &&
+ result.returned_ !=
noop.model.proto.NoopAst.Expr.getDefaultInstance()) {
+ result.returned_ =
+
noop.model.proto.NoopAst.Expr.newBuilder(result.returned_).mergeFrom(value).buildPartial();
+ } else {
+ result.returned_ = value;
+ }
+ result.hasReturned = true;
+ return this;
+ }
+ public Builder clearReturned() {
+ result.hasReturned = false;
+ result.returned_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ return this;
+ }
+ }
+
+ static {
+ noop.model.proto.NoopAst.getDescriptor();
+ }
+
+ static {
+ noop.model.proto.NoopAst.internalForceInit();
+ }
+ }
+
+ public static final class ShouldStatement extends
+ com.google.protobuf.GeneratedMessage {
+ // Use ShouldStatement.newBuilder() to construct.
+ private ShouldStatement() {}
+
+ private static final ShouldStatement defaultInstance = new
ShouldStatement();
+ public static ShouldStatement getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public ShouldStatement getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return
noop.model.proto.NoopAst.internal_static_ShouldStatement_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return
noop.model.proto.NoopAst.internal_static_ShouldStatement_fieldAccessorTable;
+ }
+
+ // required .Expr lhs = 1;
+ public static final int LHS_FIELD_NUMBER = 1;
+ private boolean hasLhs;
+ private noop.model.proto.NoopAst.Expr lhs_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ public boolean hasLhs() { return hasLhs; }
+ public noop.model.proto.NoopAst.Expr getLhs() { return lhs_; }
+
+ // required .Expr rhs = 2;
+ public static final int RHS_FIELD_NUMBER = 2;
+ private boolean hasRhs;
+ private noop.model.proto.NoopAst.Expr rhs_ =
noop.model.proto.NoopAst.Expr.getDefaultInstance();
+ public boolean hasRhs() { return hasRhs; }
+ public noop.model.proto.NoopAst.Expr getRhs() { return rhs_; }
+
+ public final boolean isInitialized() {
+ if (!hasLhs) return false;
+ if (!hasRhs) return false;
+ if (!getLhs().isInitialized()) return false;
+ if (!getRhs().isInitialized()) return false;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ if (hasLhs()) {
+ output.writeMessage(1, getLhs());
+ }
+ if (hasRhs()) {
+ output.writeMessage(2, getRhs());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasLhs()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(1, getLhs());
+ }
+ if (hasRhs()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeMessageSize(2, getRhs());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement
parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement
parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement
parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement
parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeDelimitedFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static noop.model.proto.NoopAst.ShouldStatement parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder
newBuilder(noop.model.proto.NoopAst.ShouldStatement prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder> {
+ private noop.model.proto.NoopAst.ShouldStatement result;
+
+ // Construct using
noop.model.proto.NoopAst.ShouldStatement.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new noop.model.proto.NoopAst.ShouldStatement();
+ return builder;
+ }
+
+ protected noop.model.proto.NoopAst.ShouldStatement
internalGetResult() {
+ return result;
+ }
+
+ public Builder clear() {
+ if (result == null) {
***The diff for this file has been truncated for email.***
=======================================
--- /core/src/main/proto/noop_ast.proto Fri Dec 18 09:39:36 2009
+++ /core/src/main/proto/noop_ast.proto Mon Feb 1 19:07:04 2010
@@ -16,22 +16,86 @@
// Generate the java file with:
// protoc core/src/main/proto/noop_ast.proto --java_out=core/src/main/java
-// TODO(alexeagle): have buildr run the proto compiler
+// TODO(alexeagle): have buildr run the proto compiler -
https://issues.apache.org/jira/browse/BUILDR-368
option java_package = "noop.model.proto";
+message Stmt {
+ enum Type {
+ RETURN = 1;
+ SHOULD = 2;
+ EXPRESSION = 3;
+ }
+
+ // identifies what sort of statement this is
+ required Type type = 1;
+
+ optional ReturnStatement return = 2;
+ optional ShouldStatement should = 3;
+ optional Expr expression = 4;
+}
+
+message ReturnStatement {
+ required Expr returned = 1;
+}
+
+message ShouldStatement {
+ required Expr lhs = 1;
+ required Expr rhs = 2;
+}
+
message Expr {
enum Type {
BOOLEAN_LITERAL = 1;
STRING_LITERAL = 2;
INT_LITERAL = 3;
+ DEREFERENCE = 4;
+ METHOD_INVOCATION = 5;
+ ASSIGNMENT = 6;
+ OPERATION = 7;
+ IDENTIFIER = 8;
+ CONDITIONAL = 9;
}
// identifies what sort of expression this is
required Type type = 1;
- optional BooleanLiteral booleanLiteral = 2;
- optional StringLiteral stringLiteral = 3;
- optional IntLiteral intLiteral = 4;
+ optional BooleanLiteral boolean_literal = 2;
+ optional StringLiteral string_literal = 3;
+ optional IntLiteral int_literal = 4;
+ optional Dereference deref = 5;
+ optional MethodInvocation method_invocation = 6;
+ optional Assignment assignment = 7;
+ optional Operation operation = 8;
+ optional string identifier = 9;
+ optional Conditional conditional = 10;
+}
+
+message Conditional {
+ required Expr lhs = 1;
+ required string operator = 2;
+ required Expr rhs = 3;
+}
+
+message Operation {
+ required Expr lhs = 1;
+ required string operator = 2;
+ required Expr rhs = 3;
+}
+
+message Assignment {
+ required Expr lhs = 1;
+ required Expr rhs = 2;
+}
+
+message MethodInvocation {
+ required Expr target = 1;
+ required string method_name = 2;
+ repeated Expr argument = 3;
+}
+
+message Dereference {
+ required Expr lhs = 1;
+ required Expr rhs = 2;
}
message IntLiteral {
=======================================
--- /core/src/main/scala/noop/model/AssignmentExpression.scala Thu Oct 8
10:25:57 2009
+++ /core/src/main/scala/noop/model/AssignmentExpression.scala Mon Feb 1
19:07:04 2010
@@ -13,16 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Assignment
+import proto.NoopAst.Expr.Type;
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class AssignmentExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+class AssignmentExpression(val data: Assignment) extends Expression {
+
+ def lhs = new ExpressionWrapper(data.getLhs)
+ def rhs = new ExpressionWrapper(data.getRhs)
def accept(visitor: Visitor) = {
- if (!lhs.isInstanceOf[IdentifierExpression]) {
+ if (data.getLhs.getType != Type.IDENTIFIER) {
throw new RuntimeException("Oops, I only know how to assign to
identifiers");
}
lhs.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/BindingDeclaration.scala Thu Dec 3
21:26:31 2009
+++ /core/src/main/scala/noop/model/BindingDeclaration.scala Mon Feb 1
19:07:04 2010
@@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Expr;
/**
* AST model element which represents a declaration of a binding from a
type to an expression.
* @author alex...@google.com (Alex Eagle)
*/
-class BindingDeclaration(val noopType: String, val boundTo: Expression)
extends Expression {
+class BindingDeclaration(val noopType: String, val boundTo: Expr) extends
Expression {
def accept(visitor: Visitor) = {
- boundTo.accept(visitor);
+ new ExpressionWrapper(boundTo).accept(visitor);
visitor.visit(this);
}
=======================================
--- /core/src/main/scala/noop/model/ConditionalAndExpression.scala Thu Dec
3 18:36:36 2009
+++ /core/src/main/scala/noop/model/ConditionalAndExpression.scala Mon Feb
1 19:07:04 2010
@@ -13,12 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Conditional;
/**
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ConditionalAndExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+class ConditionalAndExpression(val data: Conditional) extends Expression {
+ def lhs = new ExpressionWrapper(data.getLhs)
+ def rhs = new ExpressionWrapper(data.getRhs)
def accept(visitor: Visitor) = {
lhs.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/ConditionalOrExpression.scala Thu Dec
3 18:36:36 2009
+++ /core/src/main/scala/noop/model/ConditionalOrExpression.scala Mon Feb
1 19:07:04 2010
@@ -13,12 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Conditional;
/**
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ConditionalOrExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+class ConditionalOrExpression(val data: Conditional) extends Expression {
+ def lhs = new ExpressionWrapper(data.getLhs)
+ def rhs = new ExpressionWrapper(data.getRhs)
def accept(visitor: Visitor) = {
lhs.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/DereferenceExpression.scala Sat Nov 7
12:07:39 2009
+++ /core/src/main/scala/noop/model/DereferenceExpression.scala Mon Feb 1
19:07:04 2010
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Dereference;
/**
* An AST model element for a dereference, expressed syntactically as a
dot.
@@ -23,7 +25,10 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class DereferenceExpression(val left: Expression, val right: Expression)
extends Expression {
+class DereferenceExpression(val data: Dereference) extends Expression {
+
+ def left = new ExpressionWrapper(data.getLhs)
+ def right = new ExpressionWrapper(data.getRhs)
def accept(visitor: Visitor) = {
left.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/ExpressionWrapper.scala Mon Feb 1
12:11:10 2010
+++ /core/src/main/scala/noop/model/ExpressionWrapper.scala Mon Feb 1
19:07:04 2010
@@ -7,7 +7,7 @@
* Converts proto buffer "inheritance", which is done by enum, into typed
expressions.
* @author alex...@google.com (Alex Eagle)
*/
-class ExpressionWrapper(data: Expr) extends Expression {
+class ExpressionWrapper(val data: Expr) extends Expression {
def accept(visitor: Visitor): Unit = {
getTypedExpression.accept(visitor);
}
@@ -23,6 +23,27 @@
case Type.BOOLEAN_LITERAL => {
new BooleanLiteralExpression(data.getBooleanLiteral)
}
+ case Type.ASSIGNMENT => {
+ new AssignmentExpression(data.getAssignment)
+ }
+ case Type.IDENTIFIER => {
+ new IdentifierExpression(data.getIdentifier)
+ }
+ case Type.CONDITIONAL => {
+ data.getConditional.getOperator match {
+ case "||" => new ConditionalOrExpression(data.getConditional)
+ case "&&" => new ConditionalAndExpression(data.getConditional)
+ }
+ }
+ case Type.DEREFERENCE => {
+ new DereferenceExpression(data.getDeref)
+ }
+ case Type.METHOD_INVOCATION => {
+ new MethodInvocationExpression(data.getMethodInvocation)
+ }
+ case Type.OPERATION => {
+ new OperatorExpression(data.getOperation)
+ }
}
}
}
=======================================
--- /core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
Thu Oct 8 10:25:57 2009
+++ /core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
Mon Feb 1 19:07:04 2010
@@ -13,18 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Expr;
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
class IdentifierDeclarationExpression(val noopType: String, val name:
String) extends Expression {
- var initialValue: Option[Expression] = None;
+ var initialValue: Option[Expr] = None;
def accept(visitor: Visitor) = {
val value = initialValue match {
- case Some(v) => v;
+ case Some(v) => new ExpressionWrapper(v);
case None => new EvaluatedExpression(null);
}
value.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/MethodInvocationExpression.scala Thu
Oct 8 10:25:57 2009
+++ /core/src/main/scala/noop/model/MethodInvocationExpression.scala Mon
Feb 1 19:07:04 2010
@@ -13,14 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.MethodInvocation
+import collection.jcl.Buffer;
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class MethodInvocationExpression(val left: Expression, val name: String,
- val arguments: Seq[Expression]) extends Expression {
+class MethodInvocationExpression(val data: MethodInvocation) extends
Expression {
+
+ def left = new ExpressionWrapper(data.getTarget)
+ def name = data.getMethodName
+ def arguments: Seq[Expression] = Buffer(data.getArgumentList) map (new
ExpressionWrapper(_))
def accept(visitor: Visitor) = {
left.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/OperatorExpression.scala Thu Dec 3
18:36:36 2009
+++ /core/src/main/scala/noop/model/OperatorExpression.scala Mon Feb 1
19:07:04 2010
@@ -13,14 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.{Operation, MethodInvocation}
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class OperatorExpression(val left: Expression, val operator: String, val
right: Expression)
- extends Expression {
+class OperatorExpression(val data: Operation) extends Expression {
+ def left = new ExpressionWrapper(data.getLhs)
+ def right = new ExpressionWrapper(data.getRhs)
+ def operator = data.getOperator
def accept(visitor: Visitor) = {
val methodName = operator match {
@@ -37,7 +41,12 @@
case "<=" => "lesserOrEqualThan";
}
- new MethodInvocationExpression(left, methodName,
List(right)).accept(visitor);
+ new MethodInvocationExpression(MethodInvocation.newBuilder()
+ .setTarget(data.getLhs)
+ .setMethodName(data.getOperator)
+ .addArgument(data.getRhs)
+ .build())
+ .accept(visitor);
visitor.visit(this);
}
}
=======================================
--- /core/src/main/scala/noop/model/ReturnExpression.scala Thu Oct 8
10:25:57 2009
+++ /core/src/main/scala/noop/model/ReturnExpression.scala Mon Feb 1
19:07:04 2010
@@ -13,16 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
+
+import proto.NoopAst.Expr;
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ReturnExpression(val expr: Expression) extends Expression {
+class ReturnExpression(val expr: Expr) extends Expression {
def accept(visitor: Visitor) = {
- expr.accept(visitor);
+ new ExpressionWrapper(expr).accept(visitor);
visitor.visit(this);
}
}
=======================================
--- /core/src/main/scala/noop/model/ShouldExpression.scala Thu Oct 8
10:25:57 2009
+++ /core/src/main/scala/noop/model/ShouldExpression.scala Mon Feb 1
19:07:04 2010
@@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package noop.model;
+package noop.model
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ShouldExpression(left: Expression, right: Expression) extends
Expression {
+class ShouldExpression(data: proto.NoopAst.ShouldStatement) extends
Expression {
+
+ def left = new ExpressionWrapper(data.getLhs)
+ def right = new ExpressionWrapper(data.getRhs)
def accept(visitor: Visitor) = {
left.accept(visitor);
=======================================
--- /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
12:11:10 2010
+++ /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
19:07:04 2010
@@ -33,9 +33,12 @@
import noop.model.*;
import noop.model.proto.NoopAst;
import noop.model.proto.NoopAst.*;
+ import static noop.model.proto.NoopAst.Expr.Type.*;
+ import static noop.model.proto.NoopAst.Stmt.Type.*;
import scala.Enumeration;
import scala.collection.mutable.Buffer;
import scala.collection.mutable.ArrayBuffer;
+ import java.util.LinkedList;
}
@members {
@@ -276,19 +279,25 @@
{ $Block::block.statements().\$plus\$eq($w.exp); }
| identifierDeclaration
| should=shouldStatement
- { $Block::block.statements().\$plus\$eq($should.exp); }
+ { $Block::block.statements().\$plus\$eq(new
StatementWrapper($should.stmt)); }
| exp=expression
- { $Block::block.statements().\$plus\$eq($exp.exp); }
+ { $Block::block.statements().\$plus\$eq(new ExpressionWrapper($exp.exp));
}
;
-shouldStatement returns [Expression exp]
+shouldStatement returns [Stmt stmt]
: ^('should' left=expression right=expression)
- { $exp = new ShouldExpression($left.exp, $right.exp); }
+ { $stmt = Stmt.newBuilder()
+ .setType(SHOULD)
+ .setShould(ShouldStatement.newBuilder()
+ .setLhs($left.exp)
+ .setRhs($right.exp))
+ .build();
+ }
;
whileStatement returns [Expression exp]
: ^(WHILE term=expression b=block)
- { $exp = new WhileLoop($term.exp, $b.block); }
+ { $exp = new WhileLoop(new ExpressionWrapper($term.exp), $b.block); }
;
returnStatement
@@ -306,14 +315,9 @@
}
;
-assignment returns [Expression exp]
- : ^('=' lhs=expression rhs=expression)
- { $exp = new AssignmentExpression($lhs.exp, $rhs.exp); }
- ;
-
-expression returns [Expression exp]
+expression returns [Expr exp]
: l=literal
- { $exp = new ExpressionWrapper($l.exp); }
+ { $exp = $l.exp; }
| d=dereference
{ $exp = $d.exp; }
| o=operatorExpression
@@ -324,68 +328,112 @@
{ $exp = $c.exp; }
| right=(VariableIdentifier|TypeIdentifier) a=arguments?
{ if ($a.args != null) {
- Expression left = new IdentifierExpression("this");
- $exp = new MethodInvocationExpression(left, $right.text, $a.args);
+ Expr left = Expr.newBuilder()
+ .setType(IDENTIFIER)
+ .setIdentifier("this").build();
+ $exp = Expr.newBuilder()
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder()
+ .setTarget(left)
+ .setMethodName($right.text)
+ .addAllArgument($a.args))
+ .build();
} else {
- $exp = new IdentifierExpression($right.text);
+ $exp = Expr.newBuilder()
+ .setType(IDENTIFIER)
+ .setIdentifier($right.text)
+ .build();
}
}
;
-conditionalExpression returns [Expression exp]
+assignment returns [Expr exp]
+ : ^('=' lhs=expression rhs=expression)
+ { $exp = Expr.newBuilder()
+ .setType(ASSIGNMENT)
+ .setAssignment(Assignment.newBuilder()
+ .setLhs($lhs.exp)
+ .setRhs($rhs.exp))
+ .build(); }
+ ;
+
+conditionalExpression returns [Expr exp]
: ^(cond=('||' | '&&') left=expression right=expression)
{
- if ($cond.text.equals("||")) {
- $exp = new ConditionalOrExpression($left.exp, $right.exp);
- } else if ($cond.text.equals("&&")) {
- $exp = new ConditionalAndExpression($left.exp, $right.exp);
- }
+ $exp = Expr.newBuilder()
+ .setType(CONDITIONAL)
+ .setConditional(Conditional.newBuilder()
+ .setLhs($left.exp)
+ .setOperator($cond.text)
+ .setRhs($right.exp))
+ .build();
}
;
-operatorExpression returns [Expression exp]
+operatorExpression returns [Expr exp]
: ^(op=('+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '<' | '>='
| '<=') left=expression right=expression)
- { $exp = new OperatorExpression($left.exp, $op.text, $right.exp); }
+ { $exp = Expr.newBuilder()
+ .setType(OPERATION)
+ .setOperation(Operation.newBuilder()
+ .setLhs($left.exp)
+ .setOperator($op.text)
+ .setRhs($right.exp))
+ .build(); }
;
-dereference returns [Expression exp]
+dereference returns [Expr exp]
: ^('.' left=expression right=VariableIdentifier a=arguments?)
{
if ($a.args != null) {
- $exp = new MethodInvocationExpression($left.exp, $right.text,
$a.args);
+ $exp = Expr.newBuilder()
+ .setType(Expr.Type.METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder()
+ .setTarget($left.exp)
+ .setMethodName($right.text)
+ .addAllArgument($a.args)
+ )
+ .build();
} else {
- $exp = new DereferenceExpression($left.exp, new
IdentifierExpression($right.text));
+ $exp = Expr.newBuilder()
+ .setType(Expr.Type.DEREFERENCE)
+ .setDeref(Dereference.newBuilder()
+ .setLhs($left.exp)
+ .setRhs(Expr.newBuilder().setType(IDENTIFIER).setIdentifier($right.text)))
+ .build();
}
}
;
-arguments returns [Buffer<Expression> args]
-@init { $args = new ArrayBuffer<Expression>(); }
+arguments returns [List<Expr> args]
+@init { $args = new LinkedList<Expr>(); }
: ^(ARGS argument[args]*)
;
-argument[Buffer<Expression> args]
+argument[List<Expr> args]
: exp=expression
{
- $args.\$plus\$eq($exp.exp);
+ $args.add($exp.exp);
}
;
literal returns [Expr exp]
: i=INT
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.INT_LITERAL)
- .setIntLiteral(IntLiteral.newBuilder().setValue(Integer.valueOf($i.text)))
+ .setType(INT_LITERAL)
+ .setIntLiteral(IntLiteral.newBuilder()
+ .setValue(Integer.valueOf($i.text)))
.build(); }
| s=StringLiteral
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.STRING_LITERAL)
- .setStringLiteral(NoopAst.StringLiteral.newBuilder().setValue(stripQuotes($s.text)))
+ .setType(STRING_LITERAL)
+ .setStringLiteral(NoopAst.StringLiteral.newBuilder()
+ .setValue(stripQuotes($s.text)))
.build(); }
| b=('true' | 'false')
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.BOOLEAN_LITERAL)
- .setBooleanLiteral(NoopAst.BooleanLiteral.newBuilder().setValue(Boolean.valueOf($b.text)))
+ .setType(BOOLEAN_LITERAL)
+ .setBooleanLiteral(NoopAst.BooleanLiteral.newBuilder()
+ .setValue(Boolean.valueOf($b.text)))
.build(); }
;
=======================================
--- /grammar/src/test/scala/noop/grammar/BindingSpec.scala Mon Feb 1
12:11:10 2010
+++ /grammar/src/test/scala/noop/grammar/BindingSpec.scala Mon Feb 1
19:07:04 2010
@@ -18,7 +18,9 @@
import org.scalatest.matchers.ShouldMatchers
import noop.model.{ExpressionWrapper, BindingDefinition,
StringLiteralExpression, IdentifierExpression}
-import org.scalatest.Spec;
+import org.scalatest.Spec
+import noop.model.proto.NoopAst.Expr;
+import Expr.Type.IDENTIFIER;
/**
* @author alex...@google.com (Alex Eagle)
@@ -40,8 +42,8 @@
val bindingDef = file.classDef.asInstanceOf[BindingDefinition];
bindingDef.bindings should have length(3);
bindingDef.bindings.first.noopType should be("BankService");
- bindingDef.bindings.first.boundTo.getClass() should
be(classOf[IdentifierExpression]);
-
bindingDef.bindings.first.boundTo.asInstanceOf[IdentifierExpression].identifier
should be ("BankServiceImpl");
+ val expectedBoundTo =
Expr.newBuilder().setType(IDENTIFIER).setIdentifier("BankServiceImpl").build();
+ bindingDef.bindings.first.boundTo should be(expectedBoundTo);
}
it("can appear as an anonymous binding block") {
@@ -54,9 +56,7 @@
method.block.namedBinding should be(None);
val firstBinding = method.block.anonymousBindings.first;
firstBinding.noopType should be("A");
- firstBinding.boundTo.getClass() should
be(classOf[IdentifierExpression]);
- firstBinding.boundTo.asInstanceOf[IdentifierExpression].identifier
should be ("B");
-
+ firstBinding.boundTo should
be(Expr.newBuilder().setType(IDENTIFIER).setIdentifier("B").build());
}
it("can appear as a named binding block") {
@@ -104,7 +104,7 @@
method.block.anonymousBindings should have length(1);
val firstBinding = method.block.anonymousBindings.first;
firstBinding.noopType should be("String");
- val typedExpression =
firstBinding.boundTo.asInstanceOf[ExpressionWrapper].getTypedExpression;
+ val typedExpression = new
ExpressionWrapper(firstBinding.boundTo.asInstanceOf[Expr]).getTypedExpression;
typedExpression.asInstanceOf[StringLiteralExpression].value should
be ("foo");
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/BlockSpec.scala Mon Feb 1
12:11:10 2010
+++ /grammar/src/test/scala/noop/grammar/BlockSpec.scala Mon Feb 1
19:07:04 2010
@@ -16,10 +16,12 @@
package noop.grammar;
-import collection.mutable.ArrayBuffer;
-
-import org.scalatest.matchers.ShouldMatchers;
-import org.scalatest.Spec;
+import collection.mutable.ArrayBuffer
+import org.scalatest.matchers.ShouldMatchers
+import java.io.InputStream
+import org.scalatest.Spec
+import noop.model.proto.NoopAst._
+import noop.model.proto.NoopAst.Expr.Type._
import noop.model._;
@@ -42,9 +44,10 @@
block.statements(0).getClass() should be(classOf[ReturnExpression]);
val returnExpression =
block.statements(0).asInstanceOf[ReturnExpression];
- val typedExpression =
returnExpression.expr.asInstanceOf[ExpressionWrapper].getTypedExpression
- typedExpression.getClass should be(classOf[IntLiteralExpression]);
- typedExpression.asInstanceOf[IntLiteralExpression].value should
be(0);
+ returnExpression.expr should be(Expr.newBuilder
+ .setType(INT_LITERAL)
+ .setIntLiteral(IntLiteral.newBuilder
+ .setValue(0)).build());
}
it("should allow chained property access on properties") {
@@ -55,17 +58,15 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- block.statements(0).getClass() should
be(classOf[DereferenceExpression]);
- val deref1 = block.statements(0).asInstanceOf[DereferenceExpression];
- deref1.left.getClass() should be(classOf[DereferenceExpression]);
- deref1.right.getClass() should be(classOf[IdentifierExpression]);
- deref1.right.asInstanceOf[IdentifierExpression].identifier should
be("d");
-
- val deref2 = deref1.left.asInstanceOf[DereferenceExpression];
- deref2.left.getClass() should be(classOf[IdentifierExpression]);
- deref2.right.getClass() should be(classOf[IdentifierExpression]);
- deref2.left.asInstanceOf[IdentifierExpression].identifier should
be("b");
- deref2.right.asInstanceOf[IdentifierExpression].identifier should
be("c");
+ val expectedExpr: Expr =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
+ expectedExpr.getType should be (DEREFERENCE);
+ expectedExpr.getDeref.getRhs.getType should be (IDENTIFIER);
+ expectedExpr.getDeref.getRhs.getIdentifier should be ("d");
+ expectedExpr.getDeref.getLhs.getType should be (DEREFERENCE);
+ expectedExpr.getDeref.getLhs.getDeref.getLhs.getType should be
(IDENTIFIER);
+ expectedExpr.getDeref.getLhs.getDeref.getLhs.getIdentifier should be
("b");
+ expectedExpr.getDeref.getLhs.getDeref.getRhs.getType should be
(IDENTIFIER);
+ expectedExpr.getDeref.getLhs.getDeref.getRhs.getIdentifier should be
("c");
}
it("should allow a method call on implicit 'this'") {
@@ -75,12 +76,14 @@
blockAst.toStringTree() should be ("a ARGS");
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- block.statements(0).getClass() should
be(classOf[MethodInvocationExpression]);
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("this");
- methodInvocation.name should be("a");
- methodInvocation.arguments should be ('empty);
+ block.statements(0).asInstanceOf[ExpressionWrapper].data should be
+ (Expr.newBuilder
+ .setType(Expr.Type.METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(Expr.Type.IDENTIFIER)
+ .setIdentifier("this"))
+ .setMethodName("a")).build());
}
it("should allow calling a method on an identifier") {
@@ -91,13 +94,14 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- block.statements(0).getClass() should
be(classOf[MethodInvocationExpression]);
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
- methodInvocation.name should be("b");
- methodInvocation.arguments should be(new ArrayBuffer[Expression]);
- methodInvocation.arguments.isEmpty should be (true);
+ val methodInvocation =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
+ methodInvocation should be (Expr.newBuilder
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("a"))
+ .setMethodName("b")).build())
}
it("should allow method chaining") {
@@ -108,17 +112,18 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements should have length (1);
- val method1 =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- method1.left.getClass() should
be(classOf[MethodInvocationExpression]);
- val method2 = method1.left.asInstanceOf[MethodInvocationExpression];
-
- method2.left.getClass() should be(classOf[IdentifierExpression]);
- method2.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
- method2.name should be("b");
- method2.arguments should be ('empty);
-
- method1.name should be("c");
- method1.arguments should be('empty);
+ val method = block.statements(0).asInstanceOf[ExpressionWrapper];
+ method.data should be (Expr.newBuilder
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("a"))
+ .setMethodName("b")))
+ .setMethodName("c")).build());
}
it("should allow a method call on a property") {
@@ -129,17 +134,20 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements should have length (1);
- val method =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- method.left.getClass() should be(classOf[DereferenceExpression]);
- val deref = method.left.asInstanceOf[DereferenceExpression];
-
- deref.left.getClass() should be(classOf[IdentifierExpression]);
- deref.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
- deref.right.getClass() should be(classOf[IdentifierExpression]);
- deref.right.asInstanceOf[IdentifierExpression].identifier should
be("b");
-
- method.name should be("c");
- method.arguments should be('empty);
+ val method = block.statements(0).asInstanceOf[ExpressionWrapper];
+ method.data should be(Expr.newBuilder
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(DEREFERENCE)
+ .setDeref(Dereference.newBuilder
+ .setLhs(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("a"))
+ .setRhs(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("b"))))
+ .setMethodName("c")).build());
}
it("should allow a method call with arguments") {
@@ -151,16 +159,20 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
- methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
- methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
- methodInvocation.name should be("b");
- methodInvocation.arguments should have length(2);
- methodInvocation.arguments(0).getClass() should
be(classOf[IdentifierExpression]);
-
methodInvocation.arguments(0).asInstanceOf[IdentifierExpression].identifier
should be("c");
- val typedExpression =
methodInvocation.arguments(1).asInstanceOf[ExpressionWrapper].getTypedExpression
- typedExpression.getClass() should
be(classOf[StringLiteralExpression]);
- typedExpression.asInstanceOf[StringLiteralExpression].value should
be ("d");
+ val methodInvocation =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
+ methodInvocation should be(Expr.newBuilder
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder
+ .setTarget(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("a"))
+ .setMethodName("b")
+ .addArgument(Expr.newBuilder
+ .setType(IDENTIFIER)
+ .setIdentifier("c"))
+ .addArgument(Expr.newBuilder
+ .setType(STRING_LITERAL)
+ .setStringLiteral(StringLiteral.newBuilder.setValue("d")))).build());
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala Mon Feb 1
12:11:10 2010
+++ /grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala Mon Feb 1
19:07:04 2010
@@ -16,8 +16,10 @@
package noop.grammar;
import org.scalatest.matchers.ShouldMatchers
-import noop.model.{ExpressionWrapper, OperatorExpression,
IntLiteralExpression, IdentifierDeclarationExpression};
-import org.scalatest.Spec;
+import noop.model.{ExpressionWrapper, OperatorExpression,
IntLiteralExpression, IdentifierDeclarationExpression}
+import org.scalatest.Spec
+import noop.model.proto.NoopAst.{IntLiteral, Operation, Expr};
+import noop.model.proto.NoopAst.Expr.Type.{OPERATION,INT_LITERAL}
/**
* @author alex...@google.com (Alex Eagle)
@@ -43,12 +45,13 @@
block.statements(0).getClass should
be(classOf[IdentifierDeclarationExpression]);
val declaration =
block.statements(0).asInstanceOf[IdentifierDeclarationExpression];
declaration.initialValue should be ('defined);
- val expression1 =
declaration.initialValue.get().asInstanceOf[OperatorExpression];
- expression1.operator should be ("+");
- val typedExpression =
expression1.left.asInstanceOf[ExpressionWrapper].getTypedExpression
- typedExpression.asInstanceOf[IntLiteralExpression].value should be
(3);
- val expression2 = expression1.asInstanceOf[OperatorExpression].right;
- expression2.asInstanceOf[OperatorExpression].operator should be
("%");
+ val expr:Expr = declaration.initialValue.get().asInstanceOf[Expr];
+ expr.getType should be (OPERATION);
+ expr.getOperation.getLhs.getType should be (INT_LITERAL);
+ expr.getOperation.getLhs.getIntLiteral.getValue should be (3);
+ expr.getOperation.getOperator should be ("+");
+ expr.getOperation.getRhs.getType should be (OPERATION);
+ expr.getOperation.getRhs.getOperation.getOperator should be ("%")
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/LiteralsSpec.scala Mon Feb 1
12:11:10 2010
+++ /grammar/src/test/scala/noop/grammar/LiteralsSpec.scala Mon Feb 1
19:07:04 2010
@@ -16,8 +16,10 @@
package noop.grammar;
import org.scalatest.matchers.ShouldMatchers
-import noop.model.{ExpressionWrapper, BooleanLiteralExpression,
IdentifierDeclarationExpression};
-import org.scalatest.Spec;
+import noop.model.{ExpressionWrapper, BooleanLiteralExpression,
IdentifierDeclarationExpression}
+import org.scalatest.Spec
+import noop.model.proto.NoopAst.Expr.Type.BOOLEAN_LITERAL
+import noop.model.proto.NoopAst.{Expr, BooleanLiteral};
/**
* @author alex...@google.com (Alex Eagle)
@@ -56,14 +58,14 @@
it("should parse boolean literals") {
val source = "{ Boolean a = true; }";
parser.parseBlock(source).toStringTree() should equal ("(VAR Boolean
(= a true))");
- val statement =
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0)
- .asInstanceOf[IdentifierDeclarationExpression];
- statement.initialValue match {
- case Some(b) => {
-
b.asInstanceOf[ExpressionWrapper].getTypedExpression.asInstanceOf[BooleanLiteralExpression].value
should be (true);
- }
- case None => fail();
- }
+ val statement: IdentifierDeclarationExpression =
+
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0).asInstanceOf[IdentifierDeclarationExpression];
+ statement.initialValue should be('defined);
+ statement.initialValue.get should be (Expr.newBuilder
+ .setType(BOOLEAN_LITERAL)
+ .setBooleanLiteral(BooleanLiteral.newBuilder
+ .setValue(true))
+ .build());
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/TestSpec.scala Mon Feb 1 12:11:10
2010
+++ /grammar/src/test/scala/noop/grammar/TestSpec.scala Mon Feb 1 19:07:04
2010
@@ -15,10 +15,12 @@
*/
package noop.grammar;
-import org.scalatest.matchers.ShouldMatchers;
+import org.scalatest.matchers.ShouldMatchers
+import noop.model.{StatementWrapper, ShouldExpression}
+import noop.model.proto.NoopAst.Stmt;
import org.scalatest.Spec;
-import model.ShouldExpression;
+
/**
* @author alex...@google.com (Alex Eagle)
@@ -84,7 +86,8 @@
val source = "{ 1 should equal(1); }";
parser.parseBlock(source).toStringTree() should be("(should 1 equal
(ARGS 1))");
val statement =
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0);
- statement.getClass() should be(classOf[ShouldExpression]);
+ statement.getClass() should be(classOf[StatementWrapper]);
+ statement.asInstanceOf[StatementWrapper].getTypedExpression.getClass
should be (classOf[ShouldExpression])
}
}
}
==============================================================================
Revision: 214ef83b9c
Author: Alex Eagle <alex...@google.com>
Date: Mon Feb 1 21:26:33 2010
Log: merge
http://code.google.com/p/noop/source/detail?r=214ef83b9c
Modified:
/grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g
=======================================
--- /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
21:24:30 2010
+++ /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
21:26:33 2010
@@ -33,9 +33,12 @@
import noop.model.*;
import noop.model.proto.NoopAst;
import noop.model.proto.NoopAst.*;
+ import static noop.model.proto.NoopAst.Expr.Type.*;
+ import static noop.model.proto.NoopAst.Stmt.Type.*;
import scala.Enumeration;
import scala.collection.mutable.Buffer;
import scala.collection.mutable.ArrayBuffer;
+ import java.util.LinkedList;
}
@members {
@@ -279,19 +282,25 @@
{ $Block::block.statements().\$plus\$eq($w.exp); }
| identifierDeclaration
| should=shouldStatement
- { $Block::block.statements().\$plus\$eq($should.exp); }
+ { $Block::block.statements().\$plus\$eq(new
StatementWrapper($should.stmt)); }
| exp=expression
- { $Block::block.statements().\$plus\$eq($exp.exp); }
+ { $Block::block.statements().\$plus\$eq(new ExpressionWrapper($exp.exp));
}
;
-shouldStatement returns [Expression exp]
+shouldStatement returns [Stmt stmt]
: ^('should' left=expression right=expression)
- { $exp = new ShouldExpression($left.exp, $right.exp); }
+ { $stmt = Stmt.newBuilder()
+ .setType(SHOULD)
+ .setShould(ShouldStatement.newBuilder()
+ .setLhs($left.exp)
+ .setRhs($right.exp))
+ .build();
+ }
;
whileStatement returns [Expression exp]
: ^(WHILE term=expression b=block)
- { $exp = new WhileLoop($term.exp, $b.block); }
+ { $exp = new WhileLoop(new ExpressionWrapper($term.exp), $b.block); }
;
returnStatement
@@ -309,14 +318,9 @@
}
;
-assignment returns [Expression exp]
- : ^('=' lhs=expression rhs=expression)
- { $exp = new AssignmentExpression($lhs.exp, $rhs.exp); }
- ;
-
-expression returns [Expression exp]
+expression returns [Expr exp]
: l=literal
- { $exp = new ExpressionWrapper($l.exp); }
+ { $exp = $l.exp; }
| d=dereference
{ $exp = $d.exp; }
| o=operatorExpression
@@ -327,68 +331,112 @@
{ $exp = $c.exp; }
| right=(VariableIdentifier|TypeIdentifier) a=arguments?
{ if ($a.args != null) {
- Expression left = new IdentifierExpression("this");
- $exp = new MethodInvocationExpression(left, $right.text, $a.args);
+ Expr left = Expr.newBuilder()
+ .setType(IDENTIFIER)
+ .setIdentifier("this").build();
+ $exp = Expr.newBuilder()
+ .setType(METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder()
+ .setTarget(left)
+ .setMethodName($right.text)
+ .addAllArgument($a.args))
+ .build();
} else {
- $exp = new IdentifierExpression($right.text);
+ $exp = Expr.newBuilder()
+ .setType(IDENTIFIER)
+ .setIdentifier($right.text)
+ .build();
}
}
;
-conditionalExpression returns [Expression exp]
+assignment returns [Expr exp]
+ : ^('=' lhs=expression rhs=expression)
+ { $exp = Expr.newBuilder()
+ .setType(ASSIGNMENT)
+ .setAssignment(Assignment.newBuilder()
+ .setLhs($lhs.exp)
+ .setRhs($rhs.exp))
+ .build(); }
+ ;
+
+conditionalExpression returns [Expr exp]
: ^(cond=('||' | '&&') left=expression right=expression)
{
- if ($cond.text.equals("||")) {
- $exp = new ConditionalOrExpression($left.exp, $right.exp);
- } else if ($cond.text.equals("&&")) {
- $exp = new ConditionalAndExpression($left.exp, $right.exp);
- }
+ $exp = Expr.newBuilder()
+ .setType(CONDITIONAL)
+ .setConditional(Conditional.newBuilder()
+ .setLhs($left.exp)
+ .setOperator($cond.text)
+ .setRhs($right.exp))
+ .build();
}
;
-operatorExpression returns [Expression exp]
+operatorExpression returns [Expr exp]
: ^(op=('+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '<' | '>='
| '<=') left=expression right=expression)
- { $exp = new OperatorExpression($left.exp, $op.text, $right.exp); }
+ { $exp = Expr.newBuilder()
+ .setType(OPERATION)
+ .setOperation(Operation.newBuilder()
+ .setLhs($left.exp)
+ .setOperator($op.text)
+ .setRhs($right.exp))
+ .build(); }
;
-dereference returns [Expression exp]
+dereference returns [Expr exp]
: ^('.' left=expression right=VariableIdentifier a=arguments?)
{
if ($a.args != null) {
- $exp = new MethodInvocationExpression($left.exp, $right.text,
$a.args);
+ $exp = Expr.newBuilder()
+ .setType(Expr.Type.METHOD_INVOCATION)
+ .setMethodInvocation(MethodInvocation.newBuilder()
+ .setTarget($left.exp)
+ .setMethodName($right.text)
+ .addAllArgument($a.args)
+ )
+ .build();
} else {
- $exp = new DereferenceExpression($left.exp, new
IdentifierExpression($right.text));
+ $exp = Expr.newBuilder()
+ .setType(Expr.Type.DEREFERENCE)
+ .setDeref(Dereference.newBuilder()
+ .setLhs($left.exp)
+ .setRhs(Expr.newBuilder().setType(IDENTIFIER).setIdentifier($right.text)))
+ .build();
}
}
;
-arguments returns [Buffer<Expression> args]
-@init { $args = new ArrayBuffer<Expression>(); }
+arguments returns [List<Expr> args]
+@init { $args = new LinkedList<Expr>(); }
: ^(ARGS argument[args]*)
;
-argument[Buffer<Expression> args]
+argument[List<Expr> args]
: exp=expression
{
- $args.\$plus\$eq($exp.exp);
+ $args.add($exp.exp);
}
;
literal returns [Expr exp]
: i=INT
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.INT_LITERAL)
- .setIntLiteral(IntLiteral.newBuilder().setValue(Integer.valueOf($i.text)))
+ .setType(INT_LITERAL)
+ .setIntLiteral(IntLiteral.newBuilder()
+ .setValue(Integer.valueOf($i.text)))
.build(); }
| s=StringLiteral
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.STRING_LITERAL)
- .setStringLiteral(NoopAst.StringLiteral.newBuilder().setValue(stripQuotes($s.text)))
+ .setType(STRING_LITERAL)
+ .setStringLiteral(NoopAst.StringLiteral.newBuilder()
+ .setValue(stripQuotes($s.text)))
.build(); }
| b=('true' | 'false')
{ $exp = Expr.newBuilder()
- .setType(Expr.Type.BOOLEAN_LITERAL)
- .setBooleanLiteral(NoopAst.BooleanLiteral.newBuilder().setValue(Boolean.valueOf($b.text)))
+ .setType(BOOLEAN_LITERAL)
+ .setBooleanLiteral(NoopAst.BooleanLiteral.newBuilder()
+ .setValue(Boolean.valueOf($b.text)))
.build(); }
;
==============================================================================
Revision: 59da39fe06
Author: Alex Eagle <alex...@google.com>
Date: Sun Feb 21 17:25:15 2010
Log: Don't use proto buffer as the only way to build an AST model. It's too
verbose and doesn't allow methods to be declared.
http://code.google.com/p/noop/source/detail?r=59da39fe06
Modified:
/buildfile
/core/src/main/scala/noop/model/AssignmentExpression.scala
/core/src/main/scala/noop/model/BindingDeclaration.scala
/core/src/main/scala/noop/model/Block.scala
/core/src/main/scala/noop/model/BooleanLiteralExpression.scala
/core/src/main/scala/noop/model/ConditionalAndExpression.scala
/core/src/main/scala/noop/model/ConditionalOrExpression.scala
/core/src/main/scala/noop/model/DereferenceExpression.scala
/core/src/main/scala/noop/model/EvaluatedExpression.scala
/core/src/main/scala/noop/model/ExpressionWrapper.scala
/core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
/core/src/main/scala/noop/model/IntLiteralExpression.scala
/core/src/main/scala/noop/model/MethodInvocationExpression.scala
/core/src/main/scala/noop/model/OperatorExpression.scala
/core/src/main/scala/noop/model/ReturnExpression.scala
/core/src/main/scala/noop/model/ShouldExpression.scala
/core/src/main/scala/noop/model/StatementWrapper.scala
/core/src/main/scala/noop/model/StringLiteralExpression.scala
/grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g
/grammar/src/test/scala/noop/grammar/BindingSpec.scala
/grammar/src/test/scala/noop/grammar/BlockSpec.scala
/grammar/src/test/scala/noop/grammar/ClassSpec.scala
/grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala
/grammar/src/test/scala/noop/grammar/LiteralsSpec.scala
/grammar/src/test/scala/noop/grammar/TestSpec.scala
/interpreter/src/main/scala/noop/interpreter/InterpreterVisitor.scala
/interpreter/src/test/scala/noop/interpreter/ConditionalSpec.scala
/interpreter/src/test/scala/noop/interpreter/ControlStructureSpec.scala
/interpreter/src/test/scala/noop/interpreter/IdentifierDeclarationSpec.scala
/interpreter/src/test/scala/noop/interpreter/InterpreterSpec.scala
/interpreter/src/test/scala/noop/interpreter/MethodInvocationSpec.scala
/interpreter/src/test/scala/noop/interpreter/ShouldExpressionSpec.scala
=======================================
--- /buildfile Mon Feb 1 12:11:10 2010
+++ /buildfile Sun Feb 21 17:25:15 2010
@@ -30,6 +30,7 @@
GUICE = ["aopalliance:aopalliance:jar:1.0",
"com.google.inject:guice:jar:2.0", "com.google.inject.extensions:guice-assisted-inject:jar:2.0"
]
PROTO = ["com.google.protobuf:protobuf-java:jar:2.2.0"]
+JMOCK =
["org.hamcrest:hamcrest-core:jar:1.1", "org.hamcrest:hamcrest-library:jar:1.1", "org.jmock:jmock:jar:2.5.1"]
# Force Buildr Antlr integration to use the version we specify
Buildr::ANTLR::REQUIRES.clear
@@ -51,7 +52,7 @@
_('src/main/antlr3/noop/grammar/antlr/NoopAST.g')],
:in_package=>'noop.grammar.antlr')
compile.from(antlr).
- with [project("core"), ANTLR, SLF4J, PROTO]
+ with [project("core"), ANTLR, SLF4J, PROTO, JMOCK]
package :jar
end
=======================================
--- /core/src/main/scala/noop/model/AssignmentExpression.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/AssignmentExpression.scala Sun Feb 21
17:25:15 2010
@@ -16,21 +16,21 @@
package noop.model
import proto.NoopAst.Assignment
-import proto.NoopAst.Expr.Type;
/**
+ * An assignment evaluates the left-hand side, which must evaluate to an
identifier.
+ * The identifier is then assigned the value of evaluating the right-hand
side.
+ *
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class AssignmentExpression(val data: Assignment) extends Expression {
-
- def lhs = new ExpressionWrapper(data.getLhs)
- def rhs = new ExpressionWrapper(data.getRhs)
-
- def accept(visitor: Visitor) = {
- if (data.getLhs.getType != Type.IDENTIFIER) {
- throw new RuntimeException("Oops, I only know how to assign to
identifiers");
- }
+class AssignmentExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+
+ // Proto-based constructor
+ def this(data: Assignment) =
+ this(new ExpressionWrapper(data.getLhs), new
ExpressionWrapper(data.getRhs));
+
+ override def accept(visitor: Visitor) = {
lhs.accept(visitor);
rhs.accept(visitor);
visitor.visit(this);
=======================================
--- /core/src/main/scala/noop/model/BindingDeclaration.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/BindingDeclaration.scala Sun Feb 21
17:25:15 2010
@@ -15,16 +15,20 @@
*/
package noop.model
-import proto.NoopAst.Expr;
+import proto.NoopAst.Expr
/**
* AST model element which represents a declaration of a binding from a
type to an expression.
* @author alex...@google.com (Alex Eagle)
*/
-class BindingDeclaration(val noopType: String, val boundTo: Expr) extends
Expression {
-
- def accept(visitor: Visitor) = {
- new ExpressionWrapper(boundTo).accept(visitor);
+class BindingDeclaration(val noopType: String, val boundTo: Expression)
extends Expression {
+
+ // Proto-based constructor
+ def this(noopType: String, boundData: Expr) =
+ this(noopType, new ExpressionWrapper(boundData).getTypedExpression);
+
+ override def accept(visitor: Visitor) = {
+ boundTo.accept(visitor);
visitor.visit(this);
}
=======================================
--- /core/src/main/scala/noop/model/Block.scala Sat Nov 7 12:07:39 2009
+++ /core/src/main/scala/noop/model/Block.scala Sun Feb 21 17:25:15 2010
@@ -27,7 +27,7 @@
val anonymousBindings: Buffer[BindingDeclaration] = new
ArrayBuffer[BindingDeclaration];
var namedBinding: Option[String] = None;
- def accept(visitor: Visitor): Unit = {
+ override def accept(visitor: Visitor): Unit = {
for (anonBinding <- anonymousBindings) {
anonBinding.accept(visitor);
}
=======================================
--- /core/src/main/scala/noop/model/BooleanLiteralExpression.scala Fri Dec
18 09:39:36 2009
+++ /core/src/main/scala/noop/model/BooleanLiteralExpression.scala Sun Feb
21 17:25:15 2010
@@ -18,14 +18,23 @@
import noop.model.proto.NoopAst.BooleanLiteral;
/**
+ * A boolean literal, either true or false.
+ *
* @author Erik Soe Sorensen (eri...@gmail.com)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class BooleanLiteralExpression(data: BooleanLiteral) extends Expression {
-
- def value = data.getValue;
+class BooleanLiteralExpression(val value: Boolean) extends Expression {
+
+ // Proto-based constructor
+ def this(data: BooleanLiteral) = this(data.getValue);
def accept(visitor: Visitor) = {
visitor.visit(this);
}
-}
+
+ override def hashCode = value.hashCode;
+ override def equals(other: Any) = other match {
+ case that: BooleanLiteralExpression => that.value.equals(value);
+ case _ => false;
+ }
+}
=======================================
--- /core/src/main/scala/noop/model/ConditionalAndExpression.scala Mon Feb
1 19:07:04 2010
+++ /core/src/main/scala/noop/model/ConditionalAndExpression.scala Sun Feb
21 17:25:15 2010
@@ -20,11 +20,11 @@
/**
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ConditionalAndExpression(val data: Conditional) extends Expression {
- def lhs = new ExpressionWrapper(data.getLhs)
- def rhs = new ExpressionWrapper(data.getRhs)
-
- def accept(visitor: Visitor) = {
+class ConditionalAndExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+ def this(data: Conditional) =
+ this(new ExpressionWrapper(data.getLhs), new
ExpressionWrapper(data.getRhs));
+
+ override def accept(visitor: Visitor) = {
lhs.accept(visitor);
visitor.visit(this);
rhs.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/ConditionalOrExpression.scala Mon Feb
1 19:07:04 2010
+++ /core/src/main/scala/noop/model/ConditionalOrExpression.scala Sun Feb
21 17:25:15 2010
@@ -20,11 +20,11 @@
/**
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ConditionalOrExpression(val data: Conditional) extends Expression {
- def lhs = new ExpressionWrapper(data.getLhs)
- def rhs = new ExpressionWrapper(data.getRhs)
-
- def accept(visitor: Visitor) = {
+class ConditionalOrExpression(val lhs: Expression, val rhs: Expression)
extends Expression {
+ def this(data: Conditional) =
+ this(new ExpressionWrapper(data.getLhs), new
ExpressionWrapper(data.getRhs));
+
+ override def accept(visitor: Visitor) = {
lhs.accept(visitor);
visitor.visit(this);
rhs.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/DereferenceExpression.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/DereferenceExpression.scala Sun Feb 21
17:25:15 2010
@@ -25,12 +25,13 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class DereferenceExpression(val data: Dereference) extends Expression {
-
- def left = new ExpressionWrapper(data.getLhs)
- def right = new ExpressionWrapper(data.getRhs)
-
- def accept(visitor: Visitor) = {
+class DereferenceExpression(val left: Expression, val right: Expression)
extends Expression {
+
+ // Proto-based constructor
+ def this(data: Dereference) = this(new
ExpressionWrapper(data.getLhs).getTypedExpression,
+ new ExpressionWrapper(data.getRhs).getTypedExpression);
+
+ override def accept(visitor: Visitor) = {
left.accept(visitor);
right.accept(visitor);
visitor.visit(this);
=======================================
--- /core/src/main/scala/noop/model/EvaluatedExpression.scala Thu Oct 8
10:25:57 2009
+++ /core/src/main/scala/noop/model/EvaluatedExpression.scala Sun Feb 21
17:25:15 2010
@@ -23,7 +23,7 @@
*/
class EvaluatedExpression(val value: NoopObject) extends Expression {
- def accept(visitor: Visitor) = {
+ override def accept(visitor: Visitor) = {
visitor.visit(this);
}
}
=======================================
--- /core/src/main/scala/noop/model/ExpressionWrapper.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/ExpressionWrapper.scala Sun Feb 21
17:25:15 2010
@@ -46,4 +46,6 @@
}
}
}
-}
+
+ override def toString = getTypedExpression.toString;
+}
=======================================
--- /core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
Mon Feb 1 19:07:04 2010
+++ /core/src/main/scala/noop/model/IdentifierDeclarationExpression.scala
Sun Feb 21 17:25:15 2010
@@ -15,18 +15,22 @@
*/
package noop.model
-import proto.NoopAst.Expr;
+import proto.NoopAst.Expr
/**
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
class IdentifierDeclarationExpression(val noopType: String, val name:
String) extends Expression {
- var initialValue: Option[Expr] = None;
-
- def accept(visitor: Visitor) = {
+ var initialValue: Option[Expression] = None;
+
+ def setInitialValueProto(expr: Expr) = {
+ initialValue = Some(new ExpressionWrapper(expr).getTypedExpression);
+ }
+
+ override def accept(visitor: Visitor) = {
val value = initialValue match {
- case Some(v) => new ExpressionWrapper(v);
+ case Some(v) => v;
case None => new EvaluatedExpression(null);
}
value.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/IntLiteralExpression.scala Fri Dec 18
09:39:36 2009
+++ /core/src/main/scala/noop/model/IntLiteralExpression.scala Sun Feb 21
17:25:15 2010
@@ -18,14 +18,22 @@
import noop.model.proto.NoopAst.IntLiteral;
/**
+ * An integer literal, like 4.
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class IntLiteralExpression(data: IntLiteral) extends Expression {
-
- def value: Int = data.getValue;
-
- def accept(visitor: Visitor) = {
+class IntLiteralExpression(val value: Int) extends Expression {
+
+ // Proto-based constructor
+ def this(data: IntLiteral) = this(data.getValue);
+
+ override def accept(visitor: Visitor) = {
visitor.visit(this);
}
-}
+
+ override def hashCode() = value.hashCode;
+ override def equals(other: Any) = other match {
+ case that: IntLiteralExpression => that.value.equals(value);
+ case _ => false;
+ }
+}
=======================================
--- /core/src/main/scala/noop/model/MethodInvocationExpression.scala Mon
Feb 1 19:07:04 2010
+++ /core/src/main/scala/noop/model/MethodInvocationExpression.scala Sun
Feb 21 17:25:15 2010
@@ -22,13 +22,15 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class MethodInvocationExpression(val data: MethodInvocation) extends
Expression {
-
- def left = new ExpressionWrapper(data.getTarget)
- def name = data.getMethodName
- def arguments: Seq[Expression] = Buffer(data.getArgumentList) map (new
ExpressionWrapper(_))
-
- def accept(visitor: Visitor) = {
+class MethodInvocationExpression(val left: Expression, val name: String,
val arguments: Seq[Expression])
+ extends Expression {
+
+ // Proto-based constructor
+ def this(data: MethodInvocation) =
+ this(new ExpressionWrapper(data.getTarget).getTypedExpression,
data.getMethodName,
+ Buffer(data.getArgumentList) map (new
ExpressionWrapper(_).getTypedExpression));
+
+ override def accept(visitor: Visitor) = {
left.accept(visitor);
visitor.enter(this);
arguments.foreach(arg => {
=======================================
--- /core/src/main/scala/noop/model/OperatorExpression.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/OperatorExpression.scala Sun Feb 21
17:25:15 2010
@@ -18,15 +18,19 @@
import proto.NoopAst.{Operation, MethodInvocation}
/**
+ * An expression with a binary operator, like + , with two operands.
+ * This is sugar for the named method on the left operand, with the right
operand as the argument.
+ *
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class OperatorExpression(val data: Operation) extends Expression {
- def left = new ExpressionWrapper(data.getLhs)
- def right = new ExpressionWrapper(data.getRhs)
- def operator = data.getOperator
-
- def accept(visitor: Visitor) = {
+class OperatorExpression(val left: Expression, val operator: String, val
right: Expression) extends Expression {
+ // Proto-based constructor
+ def this(data: Operation) =
+ this(new ExpressionWrapper(data.getLhs).getTypedExpression,
+ data.getOperator, new
ExpressionWrapper(data.getRhs).getTypedExpression);
+
+ override def accept(visitor: Visitor) = {
val methodName = operator match {
case "+" => "plus";
case "-" => "minus";
@@ -41,12 +45,7 @@
case "<=" => "lesserOrEqualThan";
}
- new MethodInvocationExpression(MethodInvocation.newBuilder()
- .setTarget(data.getLhs)
- .setMethodName(data.getOperator)
- .addArgument(data.getRhs)
- .build())
- .accept(visitor);
+ new MethodInvocationExpression(left, methodName,
List(right)).accept(visitor);
visitor.visit(this);
}
}
=======================================
--- /core/src/main/scala/noop/model/ReturnExpression.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/ReturnExpression.scala Sun Feb 21
17:25:15 2010
@@ -21,10 +21,13 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ReturnExpression(val expr: Expr) extends Expression {
+class ReturnExpression(val expr: Expression) extends Expression {
+
+ // Proto-based constructor
+ def this(data: Expr) = this(new
ExpressionWrapper(data).getTypedExpression);
def accept(visitor: Visitor) = {
- new ExpressionWrapper(expr).accept(visitor);
+ expr.accept(visitor);
visitor.visit(this);
}
}
=======================================
--- /core/src/main/scala/noop/model/ShouldExpression.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/ShouldExpression.scala Sun Feb 21
17:25:15 2010
@@ -19,12 +19,13 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class ShouldExpression(data: proto.NoopAst.ShouldStatement) extends
Expression {
-
- def left = new ExpressionWrapper(data.getLhs)
- def right = new ExpressionWrapper(data.getRhs)
-
- def accept(visitor: Visitor) = {
+class ShouldExpression(val left: Expression, val right: Expression)
extends Expression {
+
+ // Proto-based constructor
+ def this(data: proto.NoopAst.ShouldStatement) =
+ this(new ExpressionWrapper(data.getLhs), new
ExpressionWrapper(data.getRhs));
+
+ override def accept(visitor: Visitor) = {
left.accept(visitor);
if (!right.isInstanceOf[MethodInvocationExpression]) {
throw new RuntimeException("right-hand side of should must be a
matcher");
=======================================
--- /core/src/main/scala/noop/model/StatementWrapper.scala Mon Feb 1
19:07:04 2010
+++ /core/src/main/scala/noop/model/StatementWrapper.scala Sun Feb 21
17:25:15 2010
@@ -6,7 +6,6 @@
/**
* @author alex...@google.com (Alex Eagle)
*/
-
class StatementWrapper(data: Stmt) extends Expression {
def accept(visitor: Visitor): Unit = {
getTypedExpression.accept(visitor);
=======================================
--- /core/src/main/scala/noop/model/StringLiteralExpression.scala Fri Dec
18 09:39:36 2009
+++ /core/src/main/scala/noop/model/StringLiteralExpression.scala Sun Feb
21 17:25:15 2010
@@ -21,11 +21,12 @@
* @author alex...@google.com (Alex Eagle)
* @author toc...@gmail.com (Jeremie Lenfant-Engelmann)
*/
-class StringLiteralExpression(data: StringLiteral) extends Expression {
-
- def value = data.getValue;
-
- def accept(visitor: Visitor) = {
+class StringLiteralExpression(val value: String) extends Expression {
+
+ // Proto-based constructor
+ def this(data: StringLiteral) = this(data.getValue);
+
+ override def accept(visitor: Visitor) = {
visitor.visit(this);
}
}
=======================================
--- /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Mon Feb 1
21:26:33 2010
+++ /grammar/src/main/antlr3/noop/grammar/antlr/NoopAST.g Sun Feb 21
17:25:15 2010
@@ -284,7 +284,7 @@
| should=shouldStatement
{ $Block::block.statements().\$plus\$eq(new
StatementWrapper($should.stmt)); }
| exp=expression
- { $Block::block.statements().\$plus\$eq(new ExpressionWrapper($exp.exp));
}
+ { $Block::block.statements().\$plus\$eq(new
ExpressionWrapper($exp.exp).getTypedExpression()); }
;
shouldStatement returns [Stmt stmt]
@@ -313,7 +313,7 @@
{ IdentifierDeclarationExpression identifierDeclaration = new
IdentifierDeclarationExpression($t.text, $v.text);
$Block::block.statements().\$plus\$eq(identifierDeclaration);
if ($exp.exp != null) {
- identifierDeclaration.initialValue_\$eq(new scala.Some($exp.exp));
+ identifierDeclaration.setInitialValueProto($exp.exp);
}
}
;
@@ -389,7 +389,7 @@
{
if ($a.args != null) {
$exp = Expr.newBuilder()
- .setType(Expr.Type.METHOD_INVOCATION)
+ .setType(METHOD_INVOCATION)
.setMethodInvocation(MethodInvocation.newBuilder()
.setTarget($left.exp)
.setMethodName($right.text)
@@ -398,7 +398,7 @@
.build();
} else {
$exp = Expr.newBuilder()
- .setType(Expr.Type.DEREFERENCE)
+ .setType(DEREFERENCE)
.setDeref(Dereference.newBuilder()
.setLhs($left.exp)
.setRhs(Expr.newBuilder().setType(IDENTIFIER).setIdentifier($right.text)))
=======================================
--- /grammar/src/test/scala/noop/grammar/BindingSpec.scala Mon Feb 1
19:07:04 2010
+++ /grammar/src/test/scala/noop/grammar/BindingSpec.scala Sun Feb 21
17:25:15 2010
@@ -19,8 +19,6 @@
import org.scalatest.matchers.ShouldMatchers
import noop.model.{ExpressionWrapper, BindingDefinition,
StringLiteralExpression, IdentifierExpression}
import org.scalatest.Spec
-import noop.model.proto.NoopAst.Expr;
-import Expr.Type.IDENTIFIER;
/**
* @author alex...@google.com (Alex Eagle)
@@ -42,8 +40,8 @@
val bindingDef = file.classDef.asInstanceOf[BindingDefinition];
bindingDef.bindings should have length(3);
bindingDef.bindings.first.noopType should be("BankService");
- val expectedBoundTo =
Expr.newBuilder().setType(IDENTIFIER).setIdentifier("BankServiceImpl").build();
- bindingDef.bindings.first.boundTo should be(expectedBoundTo);
+ bindingDef.bindings.first.boundTo.getClass() should
be(classOf[IdentifierExpression]);
+
bindingDef.bindings.first.boundTo.asInstanceOf[IdentifierExpression].identifier
should be ("BankServiceImpl");
}
it("can appear as an anonymous binding block") {
@@ -56,7 +54,8 @@
method.block.namedBinding should be(None);
val firstBinding = method.block.anonymousBindings.first;
firstBinding.noopType should be("A");
- firstBinding.boundTo should
be(Expr.newBuilder().setType(IDENTIFIER).setIdentifier("B").build());
+ firstBinding.boundTo.getClass() should
be(classOf[IdentifierExpression]);
+ firstBinding.boundTo.asInstanceOf[IdentifierExpression].identifier
should be ("B");
}
it("can appear as a named binding block") {
@@ -104,8 +103,8 @@
method.block.anonymousBindings should have length(1);
val firstBinding = method.block.anonymousBindings.first;
firstBinding.noopType should be("String");
- val typedExpression = new
ExpressionWrapper(firstBinding.boundTo.asInstanceOf[Expr]).getTypedExpression;
- typedExpression.asInstanceOf[StringLiteralExpression].value should
be ("foo");
+ firstBinding.boundTo.getClass() should
be(classOf[StringLiteralExpression]);
+ firstBinding.boundTo.asInstanceOf[StringLiteralExpression].value
should be ("foo");
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/BlockSpec.scala Mon Feb 1
19:07:04 2010
+++ /grammar/src/test/scala/noop/grammar/BlockSpec.scala Sun Feb 21
17:25:15 2010
@@ -20,8 +20,6 @@
import org.scalatest.matchers.ShouldMatchers
import java.io.InputStream
import org.scalatest.Spec
-import noop.model.proto.NoopAst._
-import noop.model.proto.NoopAst.Expr.Type._
import noop.model._;
@@ -44,10 +42,8 @@
block.statements(0).getClass() should be(classOf[ReturnExpression]);
val returnExpression =
block.statements(0).asInstanceOf[ReturnExpression];
- returnExpression.expr should be(Expr.newBuilder
- .setType(INT_LITERAL)
- .setIntLiteral(IntLiteral.newBuilder
- .setValue(0)).build());
+ returnExpression.expr.getClass() should
be(classOf[IntLiteralExpression]);
+ returnExpression.expr.asInstanceOf[IntLiteralExpression].value
should be(0);
}
it("should allow chained property access on properties") {
@@ -58,15 +54,17 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- val expectedExpr: Expr =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
- expectedExpr.getType should be (DEREFERENCE);
- expectedExpr.getDeref.getRhs.getType should be (IDENTIFIER);
- expectedExpr.getDeref.getRhs.getIdentifier should be ("d");
- expectedExpr.getDeref.getLhs.getType should be (DEREFERENCE);
- expectedExpr.getDeref.getLhs.getDeref.getLhs.getType should be
(IDENTIFIER);
- expectedExpr.getDeref.getLhs.getDeref.getLhs.getIdentifier should be
("b");
- expectedExpr.getDeref.getLhs.getDeref.getRhs.getType should be
(IDENTIFIER);
- expectedExpr.getDeref.getLhs.getDeref.getRhs.getIdentifier should be
("c");
+ block.statements(0).getClass() should
be(classOf[DereferenceExpression]);
+ val deref1 = block.statements(0).asInstanceOf[DereferenceExpression];
+ deref1.left.getClass() should be(classOf[DereferenceExpression]);
+ deref1.right.getClass() should be(classOf[IdentifierExpression]);
+ deref1.right.asInstanceOf[IdentifierExpression].identifier should
be("d");
+
+ val deref2 = deref1.left.asInstanceOf[DereferenceExpression];
+ deref2.left.getClass() should be(classOf[IdentifierExpression]);
+ deref2.right.getClass() should be(classOf[IdentifierExpression]);
+ deref2.left.asInstanceOf[IdentifierExpression].identifier should
be("b");
+ deref2.right.asInstanceOf[IdentifierExpression].identifier should
be("c");
}
it("should allow a method call on implicit 'this'") {
@@ -76,14 +74,12 @@
blockAst.toStringTree() should be ("a ARGS");
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- block.statements(0).asInstanceOf[ExpressionWrapper].data should be
- (Expr.newBuilder
- .setType(Expr.Type.METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(Expr.Type.IDENTIFIER)
- .setIdentifier("this"))
- .setMethodName("a")).build());
+ block.statements(0).getClass() should
be(classOf[MethodInvocationExpression]);
+ val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
+ methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
+ methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("this");
+ methodInvocation.name should be("a");
+ methodInvocation.arguments should be ('empty);
}
it("should allow calling a method on an identifier") {
@@ -94,14 +90,11 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- val methodInvocation =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
- methodInvocation should be (Expr.newBuilder
- .setType(METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("a"))
- .setMethodName("b")).build())
+ val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
+ methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
+ methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
+ methodInvocation.name should be("b");
+ methodInvocation.arguments.isEmpty should be (true);
}
it("should allow method chaining") {
@@ -112,18 +105,17 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements should have length (1);
- val method = block.statements(0).asInstanceOf[ExpressionWrapper];
- method.data should be (Expr.newBuilder
- .setType(METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("a"))
- .setMethodName("b")))
- .setMethodName("c")).build());
+ val method1 =
block.statements(0).asInstanceOf[MethodInvocationExpression];
+ method1.left.getClass() should
be(classOf[MethodInvocationExpression]);
+ val method2 = method1.left.asInstanceOf[MethodInvocationExpression];
+
+ method2.left.getClass() should be(classOf[IdentifierExpression]);
+ method2.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
+ method2.name should be("b");
+ method2.arguments should be ('empty);
+
+ method1.name should be("c");
+ method1.arguments should be('empty);
}
it("should allow a method call on a property") {
@@ -134,20 +126,17 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements should have length (1);
- val method = block.statements(0).asInstanceOf[ExpressionWrapper];
- method.data should be(Expr.newBuilder
- .setType(METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(DEREFERENCE)
- .setDeref(Dereference.newBuilder
- .setLhs(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("a"))
- .setRhs(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("b"))))
- .setMethodName("c")).build());
+ val method =
block.statements(0).asInstanceOf[MethodInvocationExpression];
+ method.left.getClass() should be(classOf[DereferenceExpression]);
+ val deref = method.left.asInstanceOf[DereferenceExpression];
+
+ deref.left.getClass() should be(classOf[IdentifierExpression]);
+ deref.left.asInstanceOf[IdentifierExpression].identifier should
be("a");
+ deref.right.getClass() should be(classOf[IdentifierExpression]);
+ deref.right.asInstanceOf[IdentifierExpression].identifier should
be("b");
+
+ method.name should be("c");
+ method.arguments should be('empty);
}
it("should allow a method call with arguments") {
@@ -159,20 +148,15 @@
val block = parser.buildTreeParser(blockAst).block();
block.statements.size should be(1);
- val methodInvocation =
block.statements(0).asInstanceOf[ExpressionWrapper].data;
- methodInvocation should be(Expr.newBuilder
- .setType(METHOD_INVOCATION)
- .setMethodInvocation(MethodInvocation.newBuilder
- .setTarget(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("a"))
- .setMethodName("b")
- .addArgument(Expr.newBuilder
- .setType(IDENTIFIER)
- .setIdentifier("c"))
- .addArgument(Expr.newBuilder
- .setType(STRING_LITERAL)
- .setStringLiteral(StringLiteral.newBuilder.setValue("d")))).build());
+ val methodInvocation =
block.statements(0).asInstanceOf[MethodInvocationExpression];
+ methodInvocation.left.getClass() should
be(classOf[IdentifierExpression]);
+ methodInvocation.left.asInstanceOf[IdentifierExpression].identifier
should be("a");
+ methodInvocation.name should be("b");
+ methodInvocation.arguments should have length(2);
+ methodInvocation.arguments(0).getClass() should
be(classOf[IdentifierExpression]);
+
methodInvocation.arguments(0).asInstanceOf[IdentifierExpression].identifier
should be("c");
+ methodInvocation.arguments(1).getClass() should
be(classOf[StringLiteralExpression]);
+
methodInvocation.arguments(1).asInstanceOf[StringLiteralExpression].value
should be ("d");
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/ClassSpec.scala Mon Feb 1
21:24:30 2010
+++ /grammar/src/test/scala/noop/grammar/ClassSpec.scala Sun Feb 21
17:25:15 2010
@@ -84,15 +84,15 @@
"(PARAM (MOD mutable delegate) C c)))");
val file = parser.file(source);
file.classDef.name should be("Bar");
- file.classDef.parameters should have length(3);
- file.classDef.parameters(0).modifiers should have length(1);
- file.classDef.parameters(0).modifiers should
contain(Modifier.mutable);
- file.classDef.parameters(1).modifiers should have length(1);
- file.classDef.parameters(1).modifiers should
contain(Modifier.delegate);
- file.classDef.parameters(2).modifiers should have length(2);
- file.classDef.parameters(2).modifiers should
contain(Modifier.mutable);
- file.classDef.parameters(2).modifiers should
contain(Modifier.delegate);
-
+ val parameters =
file.classDef.asInstanceOf[ConcreteClassDefinition].parameters;
+ parameters should have length(3);
+ parameters(0).modifiers should have length(1);
+ parameters(0).modifiers should contain(Modifier.mutable);
+ parameters(1).modifiers should have length(1);
+ parameters(1).modifiers should contain(Modifier.delegate);
+ parameters(2).modifiers should have length(2);
+ parameters(2).modifiers should contain(Modifier.mutable);
+ parameters(2).modifiers should contain(Modifier.delegate);
}
it("should allow an implements clause with one interface") {
=======================================
--- /grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala Mon Feb 1
19:07:04 2010
+++ /grammar/src/test/scala/noop/grammar/ExpressionsSpec.scala Sun Feb 21
17:25:15 2010
@@ -16,10 +16,8 @@
package noop.grammar;
import org.scalatest.matchers.ShouldMatchers
-import noop.model.{ExpressionWrapper, OperatorExpression,
IntLiteralExpression, IdentifierDeclarationExpression}
import org.scalatest.Spec
-import noop.model.proto.NoopAst.{IntLiteral, Operation, Expr};
-import noop.model.proto.NoopAst.Expr.Type.{OPERATION,INT_LITERAL}
+import noop.model._
/**
* @author alex...@google.com (Alex Eagle)
@@ -45,13 +43,15 @@
block.statements(0).getClass should
be(classOf[IdentifierDeclarationExpression]);
val declaration =
block.statements(0).asInstanceOf[IdentifierDeclarationExpression];
declaration.initialValue should be ('defined);
- val expr:Expr = declaration.initialValue.get().asInstanceOf[Expr];
- expr.getType should be (OPERATION);
- expr.getOperation.getLhs.getType should be (INT_LITERAL);
- expr.getOperation.getLhs.getIntLiteral.getValue should be (3);
- expr.getOperation.getOperator should be ("+");
- expr.getOperation.getRhs.getType should be (OPERATION);
- expr.getOperation.getRhs.getOperation.getOperator should be ("%")
+ declaration.initialValue match {
+ case Some(expression1: OperatorExpression) => {
+ expression1.operator should be ("+");
+ expression1.left.asInstanceOf[IntLiteralExpression].value should
be (3);
+ val expression2 =
expression1.asInstanceOf[OperatorExpression].right;
+ expression2.asInstanceOf[OperatorExpression].operator should be
("%");
+ }
+ case _ => fail();
+ }
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/LiteralsSpec.scala Mon Feb 1
19:07:04 2010
+++ /grammar/src/test/scala/noop/grammar/LiteralsSpec.scala Sun Feb 21
17:25:15 2010
@@ -15,11 +15,11 @@
*/
package noop.grammar;
+import org.jmock.Mockery;
+import org.jmock.Expectations;
import org.scalatest.matchers.ShouldMatchers
-import noop.model.{ExpressionWrapper, BooleanLiteralExpression,
IdentifierDeclarationExpression}
import org.scalatest.Spec
-import noop.model.proto.NoopAst.Expr.Type.BOOLEAN_LITERAL
-import noop.model.proto.NoopAst.{Expr, BooleanLiteral};
+import noop.model._
/**
* @author alex...@google.com (Alex Eagle)
@@ -28,6 +28,7 @@
class LiteralsSpec extends Spec with ShouldMatchers {
val parser = new Parser();
+ val mockery = new Mockery();
describe("the parser") {
@@ -61,11 +62,18 @@
val statement: IdentifierDeclarationExpression =
parser.buildTreeParser(parser.parseBlock(source)).block().statements(0).asInstanceOf[IdentifierDeclarationExpression];
statement.initialValue should be('defined);
- statement.initialValue.get should be (Expr.newBuilder
- .setType(BOOLEAN_LITERAL)
- .setBooleanLiteral(BooleanLiteral.newBuilder
- .setValue(true))
- .build());
+ statement.initialValue match {
+ case Some(boolean: Expression) => {
+
+ val visitor = mockery.mock(classOf[Visitor]);
+ mockery.checking(new Expectations() {{
+ oneOf(visitor).visit(new BooleanLiteralExpression(true));
+ }});
+ boolean.asInstanceOf[Expression].accept(visitor);
+ mockery.assertIsSatisfied();
+ }
+ case None => fail();
+ }
}
}
}
=======================================
--- /grammar/src/test/scala/noop/grammar/TestSpec.scala Mon Feb 1 19:07:04
2010
+++ /grammar/src/test/scala/noop/grammar/TestSpec.scala Sun Feb 21 17:25:15
2010
@@ -17,7 +17,6 @@
import org.scalatest.matchers.ShouldMatchers
import noop.model.{StatementWrapper, ShouldExpression}
-import noop.model.proto.NoopAst.Stmt;
import org.scalatest.Spec;
=======================================
--- /interpreter/src/main/scala/noop/interpreter/InterpreterVisitor.scala
Thu Dec 3 18:36:36 2009
+++ /interpreter/src/main/scala/noop/interpreter/InterpreterVisitor.scala
Sun Feb 21 17:25:15 2010
@@ -15,20 +15,21 @@
*/
package noop.interpreter;
-import com.google.inject.Inject;
-import inject.Injector;
-import org.slf4j.LoggerFactory;
-
-import scala.collection.mutable.ArrayBuffer;
-
-import interpreter.testing.TestFailedException;
-import model.{AssignmentExpression, BindingDeclaration, Block,
BooleanLiteralExpression,
+import com.google.inject.Inject
+import org.slf4j.{Logger, LoggerFactory}
+
+import scala.collection.mutable.ArrayBuffer
+
+import noop.inject.Injector
+import noop.model.ExpressionWrapper;
+import noop.interpreter.testing.TestFailedException
+import noop.model.{AssignmentExpression, BindingDeclaration, Block,
BooleanLiteralExpression,
ConditionalAndExpression, ConditionalOrExpression,
DereferenceExpression,
EvaluatedExpression, IdentifierDeclarationExpression,
IdentifierExpression,
IntLiteralExpression, Method, MethodInvocationExpression, Modifier,
OperatorExpression, ReturnExpression, ShouldExpression,
StringLiteralExpression,
- Visitor, WhileLoop};
-import types._;
+ Visitor, WhileLoop}
+import noop.types._
/**
* @author alex...@google.com (Alex Eagle)
@@ -38,11 +39,15 @@
booleanFactory: BooleanFactory, stringFactory: StringFactory,
integerFactory: IntegerFactory)
extends Visitor {
- val logger = LoggerFactory.getLogger(this.getClass());
+ val logger: Logger = LoggerFactory.getLogger(this.getClass());
def visit(assignmentExpression: AssignmentExpression) = {
val currentFrame = context.stack.top;
- val identifier =
assignmentExpression.lhs.asInstanceOf[IdentifierExpression].identifier;
+ logger.info("lastEvaluated " + currentFrame.lastEvaluated);
+ val identifier = assignmentExpression.lhs match {
+ case idExp: IdentifierExpression => idExp.identifier;
+ case wrapped: ExpressionWrapper =>
wrapped.getTypedExpression.asInstanceOf[IdentifierExpression].identifier;
+ }
val obj = currentFrame.lastEvaluated(1);
currentFrame.lastEvaluated.clear();
=======================================
--- /interpreter/src/test/scala/noop/interpreter/ConditionalSpec.scala Fri
Dec 18 09:39:36 2009
+++ /interpreter/src/test/scala/noop/interpreter/ConditionalSpec.scala Sun
Feb 21 17:25:15 2010
@@ -20,8 +20,7 @@
import org.scalatest.matchers.ShouldMatchers;
import org.scalatest.Spec;
-import noop.model.proto.NoopAst.IntLiteral;
-import noop.model.{Block, IntLiteralExpression, OperatorExpression,
Visitor};
+import noop.model.{IntLiteralExpression, OperatorExpression, Visitor};
import noop.types.{IntegerFactory, NoopBoolean, NoopTypesModule};
/**
@@ -29,10 +28,6 @@
*/
class ConditionalSpec extends Spec with ShouldMatchers {
- val one = IntLiteral.newBuilder.setValue(1).build;
- val two = IntLiteral.newBuilder.setValue(2).build;
- val three = IntLiteral.newBuilder.setValue(3).build;
-
def createFixture = {
val injector = Guice.createInjector(new InterpreterModule(List()), new
NoopTypesModule());
val context = injector.getInstance(classOf[Context]);
@@ -47,8 +42,8 @@
it("should evaluate to true when equals is called and the values are
equal") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "==",
- new IntLiteralExpression(one));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "==",
+ new IntLiteralExpression(1));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -60,8 +55,8 @@
it("should evaluate to false when equals is called and the values are
not equal") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "==",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "==",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -73,8 +68,8 @@
it("should evaluate to true when doesNotEqual is called and the values
are not equal") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "!=",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "!=",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -86,8 +81,8 @@
it("should evaluate to false when doesNotEqual is called and the
values are equal") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "!=",
- new IntLiteralExpression(one));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "!=",
+ new IntLiteralExpression(1));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -99,8 +94,8 @@
it("should evaluate to true when greaterThan is called and the value
is greater than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(two), ">",
- new IntLiteralExpression(one));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(2), ">",
+ new IntLiteralExpression(1));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -112,8 +107,8 @@
it("should evaluate to false when greaterThan is called and the value
is less than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), ">",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), ">",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -125,8 +120,8 @@
it("should evaluate to true when lesserThan is called and the value is
less than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "<",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "<",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -138,8 +133,8 @@
it("should evaluate to false when lesserThan is called and the value
is greater than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(three), "<",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(3), "<",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -151,8 +146,8 @@
it("should evaluate to true when greaterOrEqualThan is called and the
value is greater or equal than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(three), ">=",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(3), ">=",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -164,8 +159,8 @@
it("should evaluate to false when greaterOrEqualThan is called and the
value is lesser than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), ">=",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), ">=",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -177,8 +172,8 @@
it("should evaluate to true when lesserOrEqualThan is called and the
value is lesser or equal than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(one), "<=",
- new IntLiteralExpression(two));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(1), "<=",
+ new IntLiteralExpression(2));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
@@ -190,8 +185,8 @@
it("should evaluate to false when lesserOrEqualThan is called and the
value is greater than the other one") {
val (injector, context, visitor) = createFixture;
- val conditional = new OperatorExpression(new
IntLiteralExpression(two), "<=",
- new IntLiteralExpression(one));
+ val conditional = new OperatorExpression(new
IntLiteralExpression(2), "<=",
+ new IntLiteralExpression(1));
conditional.accept(visitor);
context.stack.top.lastEvaluated should have size(1);
=======================================
--- /interpreter/src/test/scala/noop/interpreter/ControlStructureSpec.scala
Fri Dec 18 09:39:36 2009
+++ /interpreter/src/test/scala/noop/interpreter/ControlStructureSpec.scala
Sun Feb 21 17:25:15 2010
@@ -15,8 +15,6 @@
*/
package noop.interpreter;
-import noop.model.proto.NoopAst.BooleanLiteral;
-import noop.model.proto.NoopAst.StringLiteral;
import org.scalatest.matchers.ShouldMatchers;
import org.scalatest.Spec;
@@ -30,7 +28,6 @@
*/
class ControlStructureSpec extends Spec with ShouldMatchers with
GuiceInterpreterFixture {
- val falseExpr = BooleanLiteral.newBuilder.setValue(false).build;
def interpreterFixture = {
val injector = fixture;
@@ -43,7 +40,7 @@
def accept(visitor: Visitor) = {
called += 1;
- new
BooleanLiteralExpression(BooleanLiteral.newBuilder.setValue(called <=
timesToReturnTrue).build).accept(visitor);
+ new BooleanLiteralExpression(called <=
timesToReturnTrue).accept(visitor);
}
}
@@ -65,7 +62,7 @@
val expression: MockExpression = new MockExpression();
block.statements += expression;
- val whileLoop = new WhileLoop(new
BooleanLiteralExpression(falseExpr), block);
+ val whileLoop = new WhileLoop(new BooleanLiteralExpression(false),
block);
whileLoop.accept(visitor);
expression.timesCalled should be(0);
@@ -95,7 +92,7 @@
val enclosingBlock = new Block();
enclosingBlock.statements += block;
enclosingBlock.statements += new AssignmentExpression(
- new IdentifierExpression("s"), new
StringLiteralExpression(StringLiteral.newBuilder.setValue("s").build));
+ new IdentifierExpression("s"), new StringLiteralExpression("s"));
new WhileLoop(new TrueThenFalseExpression(1),
enclosingBlock).accept(visitor);
}
}
@@ -104,7 +101,7 @@
it("should exit the current block and return the supplied value") {
val (context, block, visitor) = interpreterFixture;
- val returnMe = new ReturnExpression(new
StringLiteralExpression(StringLiteral.newBuilder.setValue("to
return").build));
+ val returnMe = new ReturnExpression(new StringLiteralExpression("to
return"));
block.statements += returnMe;
val dontRunMe = new MockExpression((c: Context) => fail());
=======================================
---
/interpreter/src/test/scala/noop/interpreter/IdentifierDeclarationSpec.scala
Fri Dec 18 09:39:36 2009
+++
/interpreter/src/test/scala/noop/interpreter/IdentifierDeclarationSpec.scala
Sun Feb 21 17:25:15 2010
@@ -15,7 +15,6 @@
*/
package noop.interpreter;
-import noop.model.proto.NoopAst.StringLiteral;
import noop.model.{Visitor, StringLiteralExpression,
IdentifierDeclarationExpression}
import org.scalatest.matchers.ShouldMatchers;
import org.scalatest.Spec;
@@ -37,8 +36,7 @@
it("should add an identifier to the map of identifiers on the current
stack frame") {
val identifierDeclaration = new
IdentifierDeclarationExpression("type", "myString");
- identifierDeclaration.initialValue = Some(new
StringLiteralExpression(
- StringLiteral.newBuilder.setValue("hello world").build));
+ identifierDeclaration.initialValue = Some(new
StringLiteralExpression("hello world"));
val (context, visitor) = myFixture;
=======================================
--- /interpreter/src/test/scala/noop/interpreter/InterpreterSpec.scala Fri
Dec 18 09:39:36 2009
+++ /interpreter/src/test/scala/noop/interpreter/InterpreterSpec.scala Sun
Feb 21 17:25:15 2010
@@ -17,7 +17,6 @@
import noop.types.{NoopTypesModule, NoopInteger};
-import noop.model.proto.NoopAst.IntLiteral;
import noop.model.{Visitor, IntLiteralExpression, OperatorExpression}
import noop.grammar.Parser;
@@ -43,9 +42,7 @@
it("should evaluate simple arithmetic") {
val (context, visitor) = createFixture;
- val expr = new OperatorExpression(
- new
IntLiteralExpression(IntLiteral.newBuilder.setValue(2).build), "+",
- new IntLiteralExpression(IntLiteral.newBuilder.setValue(3).build));
+ val expr = new OperatorExpression(new IntLiteralExpression(2), "+",
new IntLiteralExpression(3));
expr.accept(visitor);
val result = context.stack.top.lastEvaluated(0);
=======================================
--- /interpreter/src/test/scala/noop/interpreter/MethodInvocationSpec.scala
Fri Dec 18 09:39:36 2009
+++ /interpreter/src/test/scala/noop/interpreter/MethodInvocationSpec.scala
Sun Feb 21 17:25:15 2010
@@ -15,8 +15,6 @@
*/
package noop.interpreter;
-import noop.model.proto.NoopAst.IntLiteral;
-import noop.model.proto.NoopAst.StringLiteral;
import noop.model._
import org.scalatest.matchers.ShouldMatchers;
import org.scalatest.Spec;
@@ -28,8 +26,6 @@
*/
class MethodInvocationSpec extends Spec with ShouldMatchers with
GuiceInterpreterFixture {
- val aString = StringLiteral.newBuilder.setValue("aString").build;
-
def interpreterFixture = {
val injector = fixture;
(injector.getInstance(classOf[Context]),
injector.getInstance(classOf[Visitor]));
@@ -39,7 +35,7 @@
it("should throw an exception if the method doesn't exist on the
type") {
val (context, visitor) = interpreterFixture;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new
MethodInvocationExpression(target, "noSuchMethodSorry", List());
val exception = intercept[NoSuchMethodException] (
expr.accept(visitor)
@@ -58,7 +54,7 @@
val myMethod = new Method("length", block, null);
myMethod.returnTypes += "Int";
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new MethodInvocationExpression(target, "length", List());
expr.accept(visitor);
}
@@ -80,9 +76,9 @@
myMethod.parameters += new Parameter(paramName, "String");
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new MethodInvocationExpression(target, "plus",
- List(new
StringLiteralExpression(StringLiteral.newBuilder.setValue(arg).build)));
+ List(new StringLiteralExpression(arg)));
expr.accept(visitor);
}
@@ -93,7 +89,7 @@
myMethod.parameters += new Parameter("other", "String");
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new MethodInvocationExpression(target, "plus", List());
intercept[RuntimeException] {
@@ -108,9 +104,8 @@
myMethod.parameters += new Parameter("other", "String");
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
- val expr = new MethodInvocationExpression(target, "plus",
- List(new
IntLiteralExpression(IntLiteral.newBuilder.setValue(1).build)));
+ val target = new StringLiteralExpression("aString");
+ val expr = new MethodInvocationExpression(target, "plus", List(new
IntLiteralExpression(1)));
intercept[RuntimeException] {
expr.accept(visitor);
@@ -123,7 +118,7 @@
myMethod.returnTypes += "Void";
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new MethodInvocationExpression(target, "plus", List());
val currentFrame = new Frame(null, null);
@@ -144,7 +139,7 @@
myMethod.parameters += new Parameter(paramName, "String");
context.classLoader.findClass("noop.String").methods += myMethod;
- val target = new StringLiteralExpression(aString);
+ val target = new StringLiteralExpression("aString");
val expr = new MethodInvocationExpression(target, "plus", List(new
MockExpression()));
intercept[RuntimeException] {
@@ -154,7 +149,7 @@
it("should be aware of the 'this' identifier and dispatch the method
on thisRef") {
val (context, visitor) = interpreterFixture;
- new StringLiteralExpression(aString).accept(visitor);
+ new StringLiteralExpression("aString").accept(visitor);
val thisRef: NoopObject = context.stack.top.lastEvaluated(0);
thisRef should not be (null);
=======================================
--- /interpreter/src/test/scala/noop/interpreter/ShouldExpressionSpec.scala
Fri Dec 18 09:39:36 2009
+++ /interpreter/src/test/scala/noop/interpreter/ShouldExpressionSpec.scala
Sun Feb 21 17:25:15 2010
@@ -16,7 +16,6 @@
package noop.interpreter
import noop.interpreter.testing.{TestFailedException};
-import noop.model.proto.NoopAst.StringLiteral;
import noop.model.{ShouldExpression, Visitor, MethodInvocationExpression,
StringLiteralExpression};
import org.scalatest.matchers.ShouldMatchers;
@@ -27,14 +26,10 @@
*/
class ShouldExpressionSpec extends Spec with ShouldMatchers with
GuiceInterpreterFixture {
- val hello = StringLiteral.newBuilder.setValue("hello").build;
- val goodbye = StringLiteral.newBuilder.setValue("goodbye").build;
-
describe("the 'should' operator") {
-
it("should be silent if the lefthand side matches an equals matcher") {
- val matcher = new MethodInvocationExpression(null, "equal", List(new
StringLiteralExpression(hello)));
- val shouldExpr = new ShouldExpression(new
StringLiteralExpression(hello), matcher);
+ val matcher = new MethodInvocationExpression(null, "equal", List(new
StringLiteralExpression("hello")));
+ val shouldExpr = new ShouldExpression(new
StringLiteralExpression("hello"), matcher);
val injector = fixture;
val visitor = injector.getInstance(classOf[Visitor]);
val context = injector.getInstance(classOf[Context]);
@@ -46,8 +41,8 @@
}
it("should throw a test failed exception if an equals matcher is not
satisfied") {
- val matcher = new MethodInvocationExpression(null, "equal", List(new
StringLiteralExpression(goodbye)));
- val shouldExpr = new ShouldExpression(new
StringLiteralExpression(hello), matcher);
+ val matcher = new MethodInvocationExpression(null, "equal", List(new
StringLiteralExpression("goodbye")));
+ val shouldExpr = new ShouldExpression(new
StringLiteralExpression("hello"), matcher);
val injector = fixture;
val visitor = injector.getInstance(classOf[Visitor]);