通过Antlr的ParseTree生成Beetl的ProgramMetaData
@param tree
@return
161348
public ProgramMetaData build(ParseTree tree)
	{

		int size = tree.getChildCount() - 1;
		List<Statement> ls = new ArrayList<Statement>(size);
		for (int i = 0; i < size; i++)
		{
			Statement st = parseStatment((ParserRuleContext) tree.getChild(i));
			if (st != null)
			{
				ls.add(st);
			}

		}

		if (pbCtx.current.gotoValue == IGoto.RETURN || pbCtx.current.gotoValue == IGoto.BREAK)
		{
			//如果顶级scope也有return 和break，则检测
			data.hasGoto = true;
		}

		pbCtx.anzlyszeGlobal();
		pbCtx.anzlyszeLocal();
		data.varIndexSize = pbCtx.varIndexSize;
		data.tempVarStartIndex = pbCtx.globalIndexMap.size();
		data.statements = ls.toArray(new Statement[0]);
		data.globalIndexMap = pbCtx.globalIndexMap;
		data.globalVarAttr = pbCtx.globaVarAttr;
		data.setTemplateRootScopeIndexMap(pbCtx.rootIndexMap);

		return data;

	}
140030
public Class<? extends org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor> bindIParseTreeConstructor() {
		return org.eclipse.xtext.generator.parser.antlr.debug.parseTreeConstruction.SimpleAntlrParsetreeConstructor.class;
	}
868775
public Template getParseTree() {
        getTemplateClass();
        if (findExecuteMethod() == null)
            throw new IllegalArgumentException("Cannot locate compiled template entry point.");
        reflectParameters();

        mTree = new Template(mCallerInfo, new Name(mCallerInfo, getName()),
            mParameters, mSubParam, null, null);
        mTree.setReturnType(new Type(mExecuteMethod.getReturnType(),
                                     mExecuteMethod.getGenericReturnType()));

        return mTree;
    }
576908
private Map<String, ParseTreeNode> getTokens() throws GrammarException,
	    TreeException {
	Map<String, ParseTreeNode> tokens = new HashMap<String, ParseTreeNode>();
	ParseTreeNode tokensTree = parserTree.getChild("Tokens");
	ParseTreeNode tokenDefinitions = tokensTree.getChild("TokenDefinitions");
	for (ParseTreeNode tokenDefinition : tokenDefinitions
		.getChildren("TokenDefinition")) {
	    // identifier...
	    String identifier = tokenDefinition.getChild("IDENTIFIER")
		    .getText();
	    // token parts...
	    tokens.put(identifier, tokenDefinition);
	    // visibility...
	    ParseTreeNode visibilityAST = tokenDefinition.getChild("Visibility");
	    if (visibilityAST.hasChild("HIDE")) {
		tokenVisibility.put(identifier, Visibility.HIDDEN);
	    } else if (visibilityAST.hasChild("IGNORE")) {
		tokenVisibility.put(identifier, Visibility.IGNORED);
	    } else {
		tokenVisibility.put(identifier, Visibility.VISIBLE);
	    }
	}
	return tokens;
    }
222519
public static <T extends Tree> Matcher<T> isTransient() {
    return new Matcher<T>() {
      @Override
      public boolean matches(Tree tree, VisitorState state) {
        Symbol sym = ASTHelpers.getSymbol(tree);
        // NOTE(yorick): there is no isTransient() on Symbol. This is what it would be.
        return sym.getModifiers().contains(Modifier.TRANSIENT);
      }
    };
  }
513663
private function &_appendWordToTree(&$tree, $code, $word, $end = false, $data = array(), $full_str = '', $is_py) {
        if (!isset($tree[$code])) {
            $tree[$code] = array(
                'end' => $end,
                'child' => array(),
                'value' => $word,
            );
        }
        if ($end) {
            $tree[$code]['end'] = true;
            $tree[$code]['is_py'] = $is_py;
            //拼音不需要full 拼音根据读音多样性对应多个词语 重复词语覆盖data
            if ($is_py) {
                $is_change = false;
                if(isset($tree[$code]["chinese_list"]) && count($tree[$code]["chinese_list"])>0) {
                    foreach ($tree[$code]["chinese_list"] as $key => &$node) {
                        if ($node['word'] == $full_str) {
                            $node['data'] = $data;
                            $is_change = true;
                            break;
                        }
                    }
                }
                if(!$is_change){
                    $tree[$code]['chinese_list'][] = ["word" => $full_str, "data" => $data];
                }
            } else {
                $tree[$code]['full'] = $full_str;
                $tree[$code]['data'] = $data;
            }
        }

        return $tree[$code]['child'];
    }
1186792
public Tree transformTree(Tree t) {
    if (VERBOSE) {
      System.err.println("Input to CoordinationTransformer: " + t);
    }
    Tree tx = tn.transformTree(t);
    if (VERBOSE) {
      System.err.println("After DependencyTreeTransformer:  " + tx);
    }
    if (tx == null) {
      return tx;
    }
    Tree tt = UCPtransform(tx);
    if (VERBOSE) {
      System.err.println("After UCPTransformer:             " + t);
    }
    Tree ttt = CCtransform(tt);
    if (VERBOSE) {
      System.err.println("After CCTransformer:              " + t);
    }
    Tree ret = qp.transformTree(ttt);
    if (VERBOSE) {
      System.err.println("After QPTreeTransformer:          " + t);
    }
    return ret;
  }
321479
public static JCExpression skipParens(JCExpression tree) {
        while (tree.hasTag(PARENS)) {
            tree = ((JCParens) tree).expr;
        }
        return tree;
    }
358646
public static Tree buildTree(TreebankNode node) throws Exception {
        if (node.getLeaf())
            return toTree(node);
        else {
            List<TreebankNode> preChildren = children(node);
            List<Tree> children = new ArrayList<>();
            Tree t = toTree(node);
            for (int i = 0; i < preChildren.size(); i++) {
                children.add(buildTree(preChildren.get(i)));
            }

            t.connect(children);
            return t;

        }



    }
556592
private ParseTree parseAdditiveExpression() {
    SourcePosition start = getTreeStartLocation();
    ParseTree left = parseMultiplicativeExpression();
    while (peekAdditiveOperator()) {
      Token operator = nextToken();
      ParseTree right = parseMultiplicativeExpression();
      left = new BinaryOperatorTree(getTreeLocation(start), left, operator, right);
    }
    return left;
  }
1021467
private ParseTree parseArrayLiteral() {
    // ArrayLiteral :
    //   [ Elisionopt ]
    //   [ ElementList ]
    //   [ ElementList , Elisionopt ]
    //
    // ElementList :
    //   Elisionopt AssignmentOrSpreadExpression
    //   ElementList , Elisionopt AssignmentOrSpreadExpression
    //
    // Elision :
    //   ,
    //   Elision ,

    SourcePosition start = getTreeStartLocation();
    ImmutableList.Builder<ParseTree> elements = ImmutableList.builder();

    eat(TokenType.OPEN_SQUARE);
    Token trailingCommaToken = null;
    while (peek(TokenType.COMMA) || peek(TokenType.SPREAD) || peekAssignmentExpression()) {
      trailingCommaToken = null;
      if (peek(TokenType.COMMA)) {
        elements.add(new NullTree(getTreeLocation(getTreeStartLocation())));
      } else {
        if (peek(TokenType.SPREAD)) {
          recordFeatureUsed(Feature.SPREAD_EXPRESSIONS);
          elements.add(parseSpreadExpression());
        } else {
          elements.add(parseAssignmentExpression());
        }
      }
      if (!peek(TokenType.CLOSE_SQUARE)) {
        trailingCommaToken = eat(TokenType.COMMA);
      }
    }
    eat(TokenType.CLOSE_SQUARE);

    maybeReportTrailingComma(trailingCommaToken);

    return new ArrayLiteralExpressionTree(
        getTreeLocation(start), elements.build());
  }
580191
@SuppressWarnings("unchecked")
    public <T extends JCTree> T translate(T tree) {
        if (tree == null) {
            return null;
        } else {
            tree.accept(this);
            JCTree tmpResult = this.result;
            this.result = null;
            return (T)tmpResult; // XXX cast
        }
    }
277271
public static DTree getDTreeFromCoNLLXString(final String input) {
        if (input == null || input.trim().isEmpty()) {
            return null;
        }

        Map<Integer, Map<Integer, String>> semanticHeadsMap = new HashMap<>();
        String[] dNodesString = input.split(System.lineSeparator());
        DTree tree = new DTree();

        Arrays.stream(dNodesString)
                .map(s -> s.split("\t"))
                .forEachOrdered(fields -> {
                    int currentIndex = 0;
                    int id = Integer.parseInt(fields[currentIndex++]);
                    String form = fields[currentIndex++];
                    String lemma = fields[currentIndex++];
                    String cPOSTag = fields[currentIndex++];
                    String pos = fields[currentIndex++];
                    String feats = fields[currentIndex++];
                    Map<String, String> featsMap = null;
                    if (!feats.equals("_")) {
                        featsMap = Arrays.stream(feats.split("\\|"))
                                .map(entry -> entry.split("="))
                                .collect(Collectors.toMap(e -> e[0], e -> e.length > 1 ? e[1] : StringUtils.EMPTY));
                    } else {
                        featsMap = new HashMap<>();
                    }

                    String headIndex = fields[currentIndex++];
                    String depLabel = fields[currentIndex++];

                    String dump1 = fields[currentIndex++];
                    String dump2 = fields[currentIndex++];

                    String semanticHeadsString = currentIndex >= fields.length ? "_" : fields[currentIndex];

                    if (!semanticHeadsString.equals("_")) {
                        Map<Integer, String> semanticHeads = Arrays.stream(semanticHeadsString.split("\\|"))
                                .map(entry -> entry.split(":"))
                                .collect(Collectors.toMap(e -> Integer.parseInt(e[0]), e -> (e.length > 1) ? e[1] : StringUtils.EMPTY));
                        semanticHeadsMap.put(id, semanticHeads);
                    }

                    DNode node = id == 0 ? tree.getPaddingNode() : new DNode(id, form, lemma, cPOSTag, pos, depLabel);
                    if (id == 0 && !featsMap.containsKey("uuid")) {
                        featsMap.put("uuid", tree.getUUID().toString());
                    }
                    node.setFeats(featsMap);
                    node.addFeature("head", headIndex); // by the time head might not be generated!
                    if (node.getId() == 0) {
                        tree.getPaddingNode().setFeats(node.getFeats());// Substitute padding with actual 0 node from CoNLLX
                    } else {
                        tree.add(node);
                    }
                });

        tree.getPaddingNode().getFeats().remove("head");
        for (int i = 1; i < tree.size(); i++) {
            DNode node = tree.get(i);
            int headIndex = Integer.parseInt(node.getFeature("head"));
            DNode head = tree.get(headIndex);
            head.addChild(node);
            node.getFeats().remove("head");
            node.setHead(head);
        }


        // Recover semantic heads.
        semanticHeadsMap.entrySet().parallelStream().map(e -> {
            DNode node = tree.get(e.getKey());
            Map<Integer, String> nodeSemanticInfo = e.getValue();
            for (Integer id : nodeSemanticInfo.keySet()) {
                node.addSemanticHead(tree.get(id), nodeSemanticInfo.get(id));
                tree.get(id).getSemanticChildren().add(node);
            }
            return null;
        }).collect(Collectors.toList());
        return tree;
    }
322891
public static Tree stripParentheses(Tree tree) {
    while (tree instanceof ParenthesizedTree) {
      tree = ((ParenthesizedTree) tree).getExpression();
    }
    return tree;
  }
244790
protected AbcNode getParseTree(Reader reader) throws IOException {
		StringWriter writer = new StringWriter();
		char[] buffer = new char[32 * 1024];
		int n;
		while ((n = reader.read(buffer)) != -1) {
			writer.write(buffer, 0, n);
		}
		return getParseTree(writer.toString());
	}
245031
public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees)
        throws IOException
    {
        if (trees == null && notYetEntered != null && notYetEntered.isEmpty())
            return List.nil();

        prepareCompiler();

        ListBuffer<JCCompilationUnit> roots = null;

        if (trees == null) {
            // If there are still files which were specified to be compiled
            // (i.e. in fileObjects) but which have not yet been entered,
            // then we make sure they have been parsed and add them to the
            // list to be entered.
            if (notYetEntered.size() > 0) {
                if (!parsed)
                    parse(); // TODO would be nice to specify files needed to be parsed
                for (JavaFileObject file: fileObjects) {
                    JCCompilationUnit unit = notYetEntered.remove(file);
                    if (unit != null) {
                        if (roots == null)
                            roots = new ListBuffer<JCCompilationUnit>();
                        roots.append(unit);
                    }
                }
                notYetEntered.clear();
            }
        }
        else {
            for (CompilationUnitTree cu : trees) {
                if (cu instanceof JCCompilationUnit) {
                    if (roots == null)
                        roots = new ListBuffer<JCCompilationUnit>();
                    roots.append((JCCompilationUnit)cu);
                    notYetEntered.remove(cu.getSourceFile());
                }
                else
                    throw new IllegalArgumentException(cu.toString());
            }
        }

        if (roots == null)
            return List.nil();

        try {
            List<JCCompilationUnit> units = compiler.enterTrees(roots.toList());

            if (notYetEntered.isEmpty())
                compiler = compiler.processAnnotations(units);

            ListBuffer<TypeElement> elements = new ListBuffer<TypeElement>();
            for (JCCompilationUnit unit : units) {
                for (JCTree node : unit.defs) {
                    if (node.hasTag(JCTree.Tag.CLASSDEF)) {
                        JCClassDecl cdef = (JCClassDecl) node;
                        if (cdef.sym != null) // maybe null if errors in anno processing
                            elements.append(cdef.sym);
                    }
                }
            }
            return elements.toList();
        }
        finally {
            compiler.log.flush();
        }
    }
387260
protected JTree createTree() {
    JTree tree = new JTree(model);
    tree.setName("TreePopup.tree");
    tree.setFont(getFont());
    tree.setForeground(getForeground());
    tree.setBackground(getBackground());
    tree.setBorder(null);
    tree.setFocusable(true);
    tree.addMouseListener(handler);
    tree.addKeyListener(handler);
    tree.setCellRenderer(new Renderer());
    return tree;
  }