Package loop

Examples of loop.Token


*/
public class SexprTokenizerTest {
  @Test
  public final void simpleSExpressions() {
    assertEquals(Arrays.asList(
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("+", Token.Kind.PLUS, 0, 0),
        new Token("1", Token.Kind.INTEGER, 0, 0),
        new Token("2", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0)),
        new SexprTokenizer("(+ 1 2)").tokenize());

    assertEquals(Arrays.asList(
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("+", Token.Kind.PLUS, 0, 0),
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("1", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0),
        new Token("2", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0)),
        new SexprTokenizer("(+ (1) 2)").tokenize());
  }
View Full Code Here


  }

  @Test
  public final void simpleSExpressionsWithComments() {
    assertEquals(Arrays.asList(
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("+", Token.Kind.PLUS, 0, 0),
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("1", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0),
        new Token("2", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0)),
        new SexprTokenizer("(+ (1) 2) ;hello").tokenize());
    assertEquals(Arrays.asList(
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("+", Token.Kind.PLUS, 0, 0),
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("1", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0),
        new Token("2", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0)),
        new SexprTokenizer("(+ ;dude \n (1) 2);hello").tokenize());
    assertEquals(Arrays.asList(
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("+", Token.Kind.PLUS, 0, 0),
        new Token("(", Token.Kind.LPAREN, 0, 0),
        new Token("1", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0),
        new Token("2", Token.Kind.INTEGER, 0, 0),
        new Token(")", Token.Kind.RPAREN, 0, 0)),
        new SexprTokenizer("(+ # dude \n (1) 2);hello").tokenize());
  }
View Full Code Here

        Computation computation = new Computation();
        computation.add(reduceNode(list.children().get(1)));

        // Add binary op chain.
        for (int i = 2; i < list.children().size(); i++) {
          BinaryOp op = new BinaryOp(new Token(var.name, kind, var.sourceLine, var.sourceColumn));
          op.add(reduceNode(list.children().get(i)));
          computation.add(op);
        }

        return computation;
    }

    TernaryIfExpression ifExpression = new TernaryIfExpression();
    Computation test = new Computation();
    test.add(var);
    test.add(new BinaryOp(new Token("in", Token.Kind.IN, var.sourceLine, var.sourceColumn))
        .add(new JavaLiteral('"' + Closure.class.getName() + '"')));
    ifExpression.add(test);                               // test := var instanceof closure
    ifExpression.add(toFunctionCall(var, list));          // then call
    ifExpression.add(var);                                // else return as is
View Full Code Here

  /**
   * atom := symbol
   */
  private Node atom() {
    Token token = tokens.get(i);

    if (token.kind == Token.Kind.LPAREN || token.kind == Token.Kind.RPAREN)
      return null;

    i++;

    switch (token.kind) {
      case INTEGER:
        return new IntLiteral(token.value);
      case LONG:
        return new LongLiteral(token.value);
      case STRING:
        return new StringLiteral(token.value);
      case REGEX:
        return new RegexLiteral(token.value);
    }

    if ("#t".equals(token.value) || "#true".equals(token.value))
      return new BooleanLiteral(new Token(token.value, Token.Kind.TRUE, token.line, token.column));
    else if ("#f".equals(token.value) || "#false".equals(token.value))
      return new BooleanLiteral(new Token(token.value, Token.Kind.FALSE, token.line, token.column));

    if (token.value.trim().isEmpty())
      return null;

    return new Variable(token.value);
View Full Code Here

      // What we want is more than the size of the token stream.
      if (cursor >= tokens.size()) {
        return null;
      }

      Token token = tokens.get(cursor);
      if (not) {
        if (token.kind == kind)
          return null;
      } else if (token.kind != kind) {
        return null;
View Full Code Here

      // Hack to elide whitespace that sneaks in due to the leading whitespace detector.
      if (value.trim().isEmpty())
        return;

      // remove this disgusting hack when you can fix the lexer.
      tokens.add(new Token(value, Token.Kind.determine(value), line, column));
    }
  }
View Full Code Here

TOP

Related Classes of loop.Token

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.