private String extractIdentifier(ParseTree parse) {
   if (parse instanceof TerminalNode) {
     int type = ((TerminalNode) parse).getSymbol().getType();
     if (type == PSQLParser.Identifier) {
       return parse.getText();
     } else if (type == PSQLParser.QuotedIdentifier) {
       return parse.getText().substring(1, parse.getText().length() - 1);
     }
   }
   return parse.getText();
 }
 public static ParseTree createParseTree(String program) {
   ANTLRInputStream antlrInput = new ANTLRInputStream(program);
   EKPLexer lexer = new EKPLexer(antlrInput);
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   EKPParser parser = new EKPParser(tokens);
   ParseTree tree = parser.programm();
   System.out.println(tree.getText());
   return tree;
 }
 /**
  * Creates JavadocNodeImpl node on base of ParseTree node.
  *
  * @param parseTree ParseTree node
  * @param parent DetailNode that will be parent of new node
  * @param index child index that has new node
  * @return JavadocNodeImpl node on base of ParseTree node.
  */
 private JavadocNodeImpl createJavadocNode(ParseTree parseTree, DetailNode parent, int index) {
   final JavadocNodeImpl node = new JavadocNodeImpl();
   node.setText(parseTree.getText());
   node.setColumnNumber(getColumn(parseTree));
   node.setLineNumber(getLine(parseTree) + blockCommentLineNumber);
   node.setIndex(index);
   node.setType(getTokenType(parseTree));
   node.setParent(parent);
   node.setChildren((DetailNode[]) new JavadocNodeImpl[parseTree.getChildCount()]);
   return node;
 }
Exemple #4
0
  @Override
  public String visitDiceinit(@NotNull DiceGameParser.DiceinitContext ctx) {

    StringBuilder result = new StringBuilder();

    result.append("Dice('" + ctx.NAME.getText() + "',[");

    for (ParseTree val : ctx.children) {
      if (val.getClass() == DiceGameParser.FaceContext.class) {
        result.append(val.getText() + ", ");
      }
    }

    result.append("])");

    return result.toString();
  }
Exemple #5
0
 @Override
 public String visitPlayerobjects(@NotNull DiceGameParser.PlayerobjectsContext ctx) {
   if (ctx.ALL != null) {
     return "self.players";
   }
   if (ctx.ACTIVE != null) {
     return "[player for player in self.players if player.isActive()]";
   }
   if (ctx.LAST != null) {
     String ret = "[";
     for (ParseTree val : ctx.children) {
       if (val.getClass() == DiceGameParser.PlayerobjectContext.class) {
         ret += (val.getText() + ", ");
       }
     }
     ret += ctx.LAST.getText() + "]";
     return ret;
   }
   return "visitPlayerobjects";
 }