Ejemplo n.º 1
0
		public void SyntaxOKTest ()
		{
			parser = new Parser ("var } function + i 'Hello',".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			parser.ParseProgram (ref comments);
			Assert.IsFalse (parser.SyntaxOK ());
		}
Ejemplo n.º 2
0
		public void BlockTest ()
		{
			parser = new Parser ("{}".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (BlockStatement), it.Element, "#3.1");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 3
0
		public void VarTest ()
		{
			parser = new Parser ("var a = 10;".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement > list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement,BlockStatement>.Iterator(list);
			Assert.IsInstanceOfType (typeof(VariableDeclarationStatement), it.Element, "#1.1");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 4
0
		public void FunctionTest ()
		{
			parser = new Parser ("function foo() {}".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (FunctionStatement), it.Element, "#2.1");
			FunctionStatement foo = ((FunctionStatement)it.Element);
			Assert.AreEqual ("foo", foo.Function.Name.Spelling, "#2.2");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 5
0
		public SLE.LambdaExpression CompileProgram (char[] Input, ref List<Diagnostic> Diagnostics, ref bool IncompleteInput, bool PrintExpressions)
		{
			IdentifierMappingTable idmtable = new IdentifierMappingTable ();
			IdentifierTable idtable = new IdentifierTable ();
			Parser parser = new Parser (Input, new IdentifierTable (), true);//tode get ecma from somewhere
			List<Comment> comments = null;
			BindingInfo bindinginfo = null;
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments, ref bindinginfo);
			Diagnostics = parser.Diagnostics;
			IncompleteInput = parser.SyntaxIncomplete();
			RowanGenerator gen = new RowanGenerator (idmtable, idtable.InsertIdentifier ("this"), idtable.InsertIdentifier ("arguments"));
			return gen.BindAndTransform (list, bindinginfo, PrintExpressions);
		}
Ejemplo n.º 6
0
		public void IfTest ()
		{
			parser = new Parser ("if (true) { } else  ;".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (IfStatement), it.Element, "#4.1");
			IfStatement ifelse = ((IfStatement)it.Element);
			Assert.AreEqual (Expression.Operation.@true, ifelse.Condition.Opcode, "#4.2");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 7
0
		public void AddTest ()
		{
			Parser parser = new Parser ("var i = 5 + 1;".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (VariableDeclarationStatement), it.Element, "#8.1");
			VariableDeclarationStatement varst = ((VariableDeclarationStatement)it.Element);
			Assert.AreEqual ("i", varst.Declarations[0].Declaration.Name.Spelling, "#8.2");
			Assert.IsInstanceOfType (typeof (InitializerVariableDeclaration), varst.Declarations[0].Declaration, "#8.3");
			InitializerVariableDeclaration ini = (InitializerVariableDeclaration)varst.Declarations[0].Declaration;
			Assert.IsInstanceOfType (typeof (BinaryOperatorExpression), ini.Initializer, "#8.4");
			Assert.AreEqual (Expression.Operation.Plus, ini.Initializer.Opcode, "#8.5");			 
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 8
0
		public void EmptyTest ()
		{
			parser = new Parser (";".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.AreEqual (Statement.Operation.Empty, it.Element.Opcode, "#12.1");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 9
0
		public void switchTest ()
		{
			parser = new Parser ("switch (test) { case a: break; default: break;}".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (SwitchStatement), it.Element, "#9.1");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 10
0
		public void ForTest ()
		{
			parser = new Parser ("for (var i = 0 ; i < 5 ; i++ ) { break; }".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (DeclarationForStatement), it.Element, "#7.1");
			DeclarationForStatement forst = ((DeclarationForStatement)it.Element);
			Assert.IsInstanceOfType (typeof (BlockStatement), forst.Body, "#7.2");
			it = new DList<Statement, BlockStatement>.Iterator (((BlockStatement)forst.Body).Children);
			Assert.IsInstanceOfType (typeof (BreakOrContinueStatement), it.Element, "#7.3");
			Assert.IsTrue (parser.SyntaxOK ());
		}
Ejemplo n.º 11
0
		public void DoWhileTest ()
		{
			parser = new Parser ("do { }while (true);".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (DoStatement), it.Element, "#6.1");
			DoStatement dost = ((DoStatement)it.Element);
			Assert.AreEqual (Expression.Operation.@true, dost.Condition.Opcode, "#6.2");
			Assert.IsTrue (parser.SyntaxOK (), PrintSyntax ("#6", parser));
		}
Ejemplo n.º 12
0
		public void WhileTest ()
		{
			parser = new Parser ("while (true) { }".ToCharArray ());
			List<Comment> comments = new List<Comment> ();
			DList<Statement, BlockStatement> list = parser.ParseProgram (ref comments);
			DList<Statement, BlockStatement>.Iterator it = new DList<Statement, BlockStatement>.Iterator (list);
			Assert.IsInstanceOfType (typeof (WhileStatement), it.Element, "#5.1");
			WhileStatement whilest = ((WhileStatement)it.Element);
			Assert.AreEqual (Expression.Operation.@true, whilest.Condition.Opcode,  "#5.2");
			Assert.IsTrue (parser.SyntaxOK ());
		}