コード例 #1
0
 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();
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
ファイル: VisitorImpl.java プロジェクト: jonashoechst/DiGaL
  @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();
  }
コード例 #5
0
ファイル: VisitorImpl.java プロジェクト: jonashoechst/DiGaL
 @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";
 }