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

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

Introduction

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

Prototype

public StringCharStream(String inputString) 

Source Link

Document

Creates a character stream for a given string.

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   w  w  w .jav 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;
}