Example usage for com.google.common.css.compiler.ast CssTree CssTree

List of usage examples for com.google.common.css.compiler.ast CssTree CssTree

Introduction

In this page you can find the example usage for com.google.common.css.compiler.ast CssTree CssTree.

Prototype

public CssTree(SourceCode sourceCode, CssRootNode root) 

Source Link

Document

Constructor of a tree.

Usage

From source file:io.bazel.rules.closure.webfiles.compiler.CssParser.java

/** Parses stylesheet. */
public CssTree parse(String path, String content) {
    SourceCode source = new SourceCode(path, content);
    StringCharStream stream = new StringCharStream(source.getFileContents());
    CssBlockNode globalBlock = new CssBlockNode(false /* isEnclosedWithBraces */);
    CssTree tree = new CssTree(source, new CssRootNode(globalBlock));
    GssParserCC parser = new GssParserCC(stream, globalBlock, source, false /* enableErrorRecovery */);
    int endOfLastError = 0;
    while (true) {
        try {//from   www.  jav  a2 s .  c  o  m
            parser.parse();
            break;
        } catch (GssParserException e) {
            // TODO(jart): Re-enable when csscomp supports --foo syntax.
            //errorReporter.report(CSS_SYNTAX_ERROR, e.getGssError().format());
            // Generic strategy to retry parsing by getting back to top level
            // NOTE: +1 for end-index because a location is represented as a closed range
            int begin = globalBlock.isEmpty() ? endOfLastError
                    : Math.max(endOfLastError,
                            globalBlock.getLastChild().getSourceCodeLocation().getEndCharacterIndex() + 1);
            endOfLastError = skipCurrentStatement(parser, stream, begin);
        }
    }
    return tree;
}

From source file:com.google.gwt.resources.rg.GssResourceGenerator.java

private CssTree deepCopy(CssTree cssTree) {
    return new CssTree(cssTree.getSourceCode(), cssTree.getRoot().deepCopy());
}