public void GetEndOfCommand() { Lexer lexer = new Lexer(";"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(";", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetEqualOperator() { Lexer lexer = new Lexer("=="); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("==", token.Value); Assert.AreEqual(TokenType.Operator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetInteger() { Lexer lexer = new Lexer("123"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("123", token.Value); Assert.AreEqual(TokenType.Integer, token.Type); Assert.IsNull(lexer.NextToken()); }
static void Main(string[] args) { System.Console.WriteLine("DartSharp 0.0.0"); Lexer lexer = new Lexer(System.Console.In); Context context = new Context(); context.SetValue("print", new Print(System.Console.Out)); Parser parser = new Parser(lexer); for (ICommand cmd = parser.ParseCommand(); cmd != null; cmd = parser.ParseCommand()) { cmd.Execute(context); } }
public void RaiseForUnknownOperator() { Lexer lexer = new Lexer("^"); lexer.NextToken(); }
public void GetNameWithSpaces() { Lexer lexer = new Lexer(" foo "); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetNameWithLineComment() { Lexer lexer = new Lexer(" foo // Foo Variable "); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void SkipNewLine() { Lexer lexer = new Lexer("\n"); Token token = lexer.NextToken(); Assert.IsNull(token); }
public void SkipNewLineCarriageReturn() { Lexer lexer = new Lexer("\n\r"); Token token = lexer.NextToken(); Assert.IsNull(lexer.NextToken()); }
public void RaiseIfCommentIsNotClosedByAMissingChar() { Lexer lexer = new Lexer("/* Comment wo/end *"); lexer.NextToken(); }
public void RaiseUnclosedString() { Lexer lexer = new Lexer("'foo"); lexer.NextToken(); }
public Parser(Lexer lexer) { this.lexer = lexer; }
public void GetNamesWithMultiLineComment() { Lexer lexer = new Lexer(" foo /* Foo \r\n Variable */ bar"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.Name, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("bar", token.Value); Assert.AreEqual(TokenType.Name, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetSquareBrackets() { Lexer lexer = new Lexer("[]"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("[", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("]", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetSimpleStringSingleQuote() { Lexer lexer = new Lexer("'foo'"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("foo", token.Value); Assert.AreEqual(TokenType.String, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetSimpleAssignmentCommand() { Lexer lexer = new Lexer("a=123"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("a", token.Value); Assert.AreEqual(TokenType.Name, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("=", token.Value); Assert.AreEqual(TokenType.Operator, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("123", token.Value); Assert.AreEqual(TokenType.Integer, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetPointSeparator() { Lexer lexer = new Lexer("."); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(".", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void GetParenthesis() { Lexer lexer = new Lexer("()"); Token token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual("(", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); token = lexer.NextToken(); Assert.IsNotNull(token); Assert.AreEqual(")", token.Value); Assert.AreEqual(TokenType.Separator, token.Type); Assert.IsNull(lexer.NextToken()); }
public void RaiseIfCommentIsNotClosed() { Lexer lexer = new Lexer("/* Comment wo/end "); lexer.NextToken(); }