Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
sudo: false

language: node_js

node_js:
- "0.6"
- "0.8"
- "0.10"
- "0.11"
- "0.12"
- "4"
- "5"

script:
- ant test

matrix:
fast_finish: true
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
CSS Parser
==========
# CSS Parser

[![build status](https://secure.travis-ci.org/CSSLint/parser-lib.svg)](http://travis-ci.org/CSSLint/parser-lib)

Introduction
------------
## Introduction

The ParserLib CSS parser is a CSS3 SAX-inspired parser written in JavaScript. By default, the parser only deals with standard CSS syntax and doesn't do validation (checking of property names and values).

Adding to your project
----------------------
## Adding to your project

The CSS parser is intended for use primarily in command line JavaScript environments. The files you should use are in the `build` directory. Copy the files to an appropriate location for your usage.

Expand Down Expand Up @@ -40,8 +37,7 @@ Or include it as its component parts, the ParserLib core and the CSS parser:
```
Note that parsing large JavaScript files may cause the browser to become unresponsive.

Basic usage
-----------
## Basic usage

You can create a new instance of the parser by using the following code:
```js
Expand All @@ -66,8 +62,7 @@ The `parse()` method throws an error if a non-recoverable syntax error occurs, o

Note: The `parseStyleSheet()` method is provided for compatibility with SAC-based APIs but does the exact same thing as `parse()`.

Understanding syntax units
--------------------------
## Understanding syntax units

The CSS parser defines several types that inherit from `parserlib.util.SyntaxUnit`. These types are designed to give you easy access to all relevant parts of the CSS syntax.

Expand Down Expand Up @@ -131,16 +126,15 @@ Each instance of `parserlib.css.SelectorPart` has an `elementName` property, whi
Each instance of `parserlib.css.Combinator` has an additional `type` property that indicates the type of combinator: "descendant", "child", "sibling", or "adjacent-sibling".


Using events
------------
## Using events

The CSS parser fires events as it parses text. The events correspond to important parts of the parsing algorithm and are designed to provide developers with all of the information necessary to create lint checkers, ASTs, and other data structures.

For many events, the `event` object contains additional information. This additional information is most frequently in the form of a `parserlib.util.SyntaxUnit` object, which has three properties:

1. `text` - the string value
1. `line` - the line on which this token appeared
1. `col` - the column within the line at which this token appeared
2. `line` - the line on which this token appeared
3. `col` - the column within the line at which this token appeared

The `toString()` method for these objects is overridden to be the same value as `text`, so that you can treat the object as a string for comparison and concatenation purposes.

Expand Down Expand Up @@ -293,8 +287,8 @@ parser.addListener("error", function(event){
console.log("Parse error: " + event.message + " (" + event.line + "," + event.col + ")", "error");
});
```
Error recovery
--------------

## Error recovery

The CSS parser's goal is to be on-par with error recovery of CSS parsers in browsers. To that end, the following error recovery mechanisms are in place:

Expand All @@ -318,7 +312,6 @@ a:hover, foo ... bar {

* **Unknown @ Rules** - any @ rules that isn't recognized is automatically skipped, meaning the entire block after it is not parsed.

Running Tests
-------------
## Running Tests

With the Apache Ant build tool installed, you can run the tests via `ant test` from the repository's root.
2 changes: 2 additions & 0 deletions src/css/Colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ var Colors = {
whitesmoke :"#f5f5f5",
yellow :"#ffff00",
yellowgreen :"#9acd32",
//'currentColor' color keyword http://www.w3.org/TR/css3-color/#currentcolor
currentColor :"The value of the 'color' property.",
//CSS2 system colors http://www.w3.org/TR/css3-color/#css2-system
activeBorder :"Active window border.",
activecaption :"Active window caption.",
Expand Down
6 changes: 3 additions & 3 deletions src/css/Properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ var Properties = {
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
"top" : "<margin-width> | inherit",
"-ms-touch-action" : "auto | none | pan-x | pan-y",
"touch-action" : "auto | none | pan-x | pan-y",
"-ms-touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
"touch-action" : "auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation",
"transform" : 1,
"transform-origin" : 1,
"transform-style" : 1,
Expand All @@ -523,7 +523,7 @@ var Properties = {
"user-select" : "none | text | toggle | element | elements | all | inherit",

//V
"vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
"vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length> | inherit",
"visibility" : "visible | hidden | collapse | inherit",
"voice-balance" : 1,
"voice-duration" : 1,
Expand Down
4 changes: 4 additions & 0 deletions src/css/PropertyValuePart.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function PropertyValuePart(text, line, col){
case "vmin":
this.type = "length";
break;

case "fr":
this.type = "grid";
break;

case "deg":
case "rad":
Expand Down
40 changes: 36 additions & 4 deletions tests/css/Validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,16 @@
"auto",
"none",
"pan-x",
"pan-y"
"pan-y",
"pan-left",
"pan-right",
"pan-up",
"pan-down"
"manipulation"
],

invalid: {
"foo" : "Expected (auto | none | pan-x | pan-y) but found 'foo'."
"foo" : "Expected (auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation) but found 'foo'."
}
}));

Expand All @@ -946,11 +951,38 @@
"auto",
"none",
"pan-x",
"pan-y"
"pan-y",
"pan-left",
"pan-right",
"pan-up",
"pan-down"
"manipulation"
],

invalid: {
"foo" : "Expected (auto | none | pan-x | pan-y) but found 'foo'."
"foo" : "Expected (auto | none | pan-x | pan-y | pan-left | pan-right | pan-up | pan-down | manipulation) but found 'foo'."
}
}));

suite.add(new ValidationTestCase({
property: "vertical-align",

valid: [
"baseline",
"sub",
"super",
"top",
"text-top",
"middle",
"bottom",
"text-bottom",
"25%",
"-1px",
"inherit"
],

invalid: {
"foo" : "Expected (auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length> | inherit) but found 'foo'."
}
}));

Expand Down