Example usage for org.antlr.v4.runtime.tree.xpath XPath findAll

List of usage examples for org.antlr.v4.runtime.tree.xpath XPath findAll

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.tree.xpath XPath findAll.

Prototype

public static Collection<ParseTree> findAll(ParseTree tree, String xpath, Parser parser) 

Source Link

Usage

From source file:org.acmsl.javacss.css.StringTemplateCSSHelper.java

License:Open Source License

protected void initialize(String input) {
    StringTemplateCSSLexer lexer = new StringTemplateCSSLexer(new ANTLRInputStream(input));

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    StringTemplateCSSParser parser = new StringTemplateCSSParser(tokens);

    parser.setErrorHandler(new BailErrorStrategy());

    ParseTree tree = parser.css();//w  w w  . j a v a2s . c o  m

    Collection<ParseTree> selectorCombinations = XPath.findAll(tree, "//selectorCombination", parser);

    final StringUtils stringUtils = StringUtils.getInstance();

    this.selectors = new ArrayList<List<String>>(selectorCombinations.size());
    this.properties = new HashMap<List<String>, Map<String, String>>();

    for (ParseTree selectorCombination : selectorCombinations) {
        List<String> currentSelectors = new ArrayList<String>(selectorCombination.getChildCount());
        this.selectors.add(currentSelectors);

        for (int index = 0; index < selectorCombination.getChildCount(); index++) {
            String text = selectorCombination.getChild(index).getText();
            currentSelectors.add(text);
        }
        Map<String, String> block = retrieveProperties(selectorCombination, stringUtils);

        this.properties.put(currentSelectors, block);
    }
}

From source file:org.mar9000.antmark.MarkdownTranslator.java

License:Open Source License

public MarkdownTranslator(ParseTree tree, MarkdownParser parser) {
     this.tree = tree;
     this.parser = parser;
     // Collect reference to be used for links and images.
     for (ParseTree t : XPath.findAll(tree, "//reference", parser)) {
         MarkdownParser.ReferenceContext reference = (MarkdownParser.ReferenceContext) t;
         references.put(reference.referenceLabel().referenceId().getText().toLowerCase(), reference);
     }//w w w . jav a  2 s  .c o  m
 }