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

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

Introduction

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

Prototype

public CssRootNode(CssRootNode node) 

Source Link

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 {/*  w w w. ja  v  a 2  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;
}