summaryrefslogtreecommitdiffstats
path: root/theme-compiler/src
diff options
context:
space:
mode:
authorjoheriks <joheriks@vaadin.com>2013-10-22 17:30:31 +0300
committerjoheriks <joheriks@vaadin.com>2013-10-30 10:27:44 +0200
commit29a6a8a7cbd0560721f313bf8554be886f98e699 (patch)
tree84d96c7afa2d0a0d514938e93558d4ee179f5e80 /theme-compiler/src
parentf5feaa2e3a8aebace6d9978131b192ed8b046557 (diff)
downloadvaadin-framework-29a6a8a7cbd0560721f313bf8554be886f98e699.tar.gz
vaadin-framework-29a6a8a7cbd0560721f313bf8554be886f98e699.zip
Import W3C CSS tests to validate CSS parsing (#12735)
Downloaded W3C conformance tests for CSS 2.1 and CSS 3 (selectors), extracted all CSS (style tags, inline styles, and linked stylesheets), Since each CSS is valid SCSS, the parser should accept them. Since these are browser tests, some include CSS fragments which are intentionally malformed. These are excluded via explicit exclusion lists. Change-Id: Ib3347e1c559908f3bdd12817e55985e85f0009a2
Diffstat (limited to 'theme-compiler/src')
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java45
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java24
2 files changed, 55 insertions, 14 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
index 7213553e18..ed6b98f5ac 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
@@ -93,19 +93,49 @@ public class ScssStylesheet extends Node {
}
/**
- * Main entry point for the SASS compiler. Takes in a file and encoding then
- * builds up a ScssStylesheet tree out of it. Calling compile() on it will
- * transform SASS into CSS. Calling toString() will print out the SCSS/CSS.
+ * Main entry point for the SASS compiler. Takes in a file and an optional
+ * parent style sheet, then builds up a ScssStylesheet tree out of it.
+ * Calling compile() on it will transform SASS into CSS. Calling toString()
+ * will print out the SCSS/CSS.
*
* @param identifier
* The file path. If null then null is returned.
- * @param encoding
+ * @param parentStylesheet
+ * Style sheet from which to inherit resolvers and encoding. May
+ * be null.
* @return
* @throws CSSException
* @throws IOException
*/
public static ScssStylesheet get(String identifier,
ScssStylesheet parentStylesheet) throws CSSException, IOException {
+ return get(identifier, parentStylesheet, new SCSSDocumentHandlerImpl(),
+ new SCSSErrorHandler());
+ }
+
+ /**
+ * Main entry point for the SASS compiler. Takes in a file, an optional
+ * parent stylesheet, and document and error handlers. Then builds up a
+ * ScssStylesheet tree out of it. Calling compile() on it will transform
+ * SASS into CSS. Calling toString() will print out the SCSS/CSS.
+ *
+ * @param identifier
+ * The file path. If null then null is returned.
+ * @param parentStylesheet
+ * Style sheet from which to inherit resolvers and encoding. May
+ * be null.
+ * @param documentHandler
+ * Instance of document handler. May not be null.
+ * @param errorHandler
+ * Instance of error handler. May not be null.
+ * @return
+ * @throws CSSException
+ * @throws IOException
+ */
+ public static ScssStylesheet get(String identifier,
+ ScssStylesheet parentStylesheet,
+ SCSSDocumentHandler documentHandler, SCSSErrorHandler errorHandler)
+ throws CSSException, IOException {
/*
* The encoding to be used is passed through "encoding" parameter. the
* imported children scss node will have the same encoding as their
@@ -123,8 +153,7 @@ public class ScssStylesheet extends Node {
File file = new File(identifier);
file = file.getCanonicalFile();
- SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
- ScssStylesheet stylesheet = handler.getStyleSheet();
+ ScssStylesheet stylesheet = documentHandler.getStyleSheet();
if (parentStylesheet == null) {
// Use default resolvers
stylesheet.addResolver(new FilesystemResolver());
@@ -143,8 +172,8 @@ public class ScssStylesheet extends Node {
}
Parser parser = new Parser();
- parser.setErrorHandler(new SCSSErrorHandler());
- parser.setDocumentHandler(handler);
+ parser.setErrorHandler(errorHandler);
+ parser.setDocumentHandler(documentHandler);
try {
parser.parseStyleSheet(source);
diff --git a/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java b/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
index 2e51c686d4..0d48da34e4 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/handler/SCSSErrorHandler.java
@@ -15,34 +15,46 @@
*/
package com.vaadin.sass.internal.handler;
+import java.io.PrintStream;
+
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.CSSParseException;
import org.w3c.css.sac.ErrorHandler;
public class SCSSErrorHandler implements ErrorHandler {
+ private PrintStream errorStream;
+
+ public SCSSErrorHandler(PrintStream errorStream) {
+ this.errorStream = errorStream;
+ }
+
+ public SCSSErrorHandler() {
+ this(System.out);
+ }
+
@Override
public void error(CSSParseException arg0) throws CSSException {
- System.out.println("Error when parsing file \n" + arg0.getURI()
+ errorStream.println("Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
@Override
public void fatalError(CSSParseException arg0) throws CSSException {
- System.out.println("FATAL Error when parsing file \n" + arg0.getURI()
+ errorStream.println("FATAL Error when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
@Override
public void warning(CSSParseException arg0) throws CSSException {
- System.out.println("Warning when parsing file \n" + arg0.getURI()
+ errorStream.println("Warning when parsing file \n" + arg0.getURI()
+ " on line " + arg0.getLineNumber() + ", column "
+ arg0.getColumnNumber());
- System.out.println(arg0.getMessage() + "\n");
+ errorStream.println(arg0.getMessage() + "\n");
}
}