Skip to content

Commit

Permalink
Updated license
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBrinks committed Jan 8, 2014
1 parent b45ea22 commit 9a37378
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 76 deletions.
91 changes: 48 additions & 43 deletions ExCSS/Model/Values/PrimitiveTerm.cs
Expand Up @@ -43,6 +43,11 @@ public UnitType PrimitiveType
get { return _unit; }
}

public object Value
{
get { return _data; }
}

internal PrimitiveTerm SetFloatValue(UnitType unitType, Single value)
{
Text = value.ToString(CultureInfo.InvariantCulture) + ConvertUnitTypeToString(unitType);
Expand All @@ -52,17 +57,17 @@ internal PrimitiveTerm SetFloatValue(UnitType unitType, Single value)
return this;
}

internal Single? GetFloatValue(UnitType unitType)
{
if (_data is Single)
{
var value = (Single)_data;
//TODO Convert
return value;
}
//internal Single? GetFloatValue(UnitType unitType)
//{
// if (_data is Single)
// {
// var value = (Single)_data;
// //TODO Convert
// return value;
// }

return null;
}
// return null;
//}

internal PrimitiveTerm SetStringValue(UnitType unitType, string value)
{
Expand All @@ -87,39 +92,39 @@ internal PrimitiveTerm SetStringValue(UnitType unitType, string value)
return this;
}

internal string GetStringValue()
{
var val = _data as string;

if (val != null)
{
var value = val;
//TODO Convert
return value;
}

return null;
}

internal Counter GetCounterValue()
{
return _data as Counter;
}

internal Rectangle GetRectValue()
{
return _data as Rectangle;
}

internal HtmlColor? GetRGBColorValue()
{
if (_unit == UnitType.RGB)
{
return (HtmlColor)_data;
}

return null;
}
//public string GetStringValue()
//{
// var val = _data as string;

// if (val != null)
// {
// var value = val;
// //TODO Convert
// return value;
// }

// return null;
//}

//internal Counter GetCounterValue()
//{
// return _data as Counter;
//}

//internal Rectangle GetRectValue()
//{
// return _data as Rectangle;
//}

//internal HtmlColor? GetRGBColorValue()
//{
// if (_unit == UnitType.RGB)
// {
// return (HtmlColor)_data;
// }

// return null;
//}

internal static UnitType ConvertStringToUnitType(string unit)
{
Expand Down
4 changes: 0 additions & 4 deletions ExCSS/Model/Values/TermList.cs
Expand Up @@ -12,9 +12,6 @@ public class TermList : Term

public TermList() : this(new List<Term>())
{
//_items = new List<Term>();
//RuleValueType = RuleValueType.ValueList;
//_commaDelimited = false;
}

public TermList(List<Term> items, bool commaDelimited = false)
Expand All @@ -29,7 +26,6 @@ public int Length
get { return _items.Count; }
}


[IndexerName("ListItems")]
public Term this[int index]
{
Expand Down
21 changes: 21 additions & 0 deletions license.txt
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 13 additions & 29 deletions readme.md
Expand Up @@ -4,52 +4,36 @@ ExCSS (Pronoundec Excess) is a CSS 2.1 and CSS 3 parser for .NET.

The goal of ExCSS is to make it easy to read and parse stylesheets into a friendly object model with full LINQ support.

#Original Work#
ExCSS is based on the original work by Scott Green, and is used with his expressed permission
http://www.codeproject.com/Articles/20450/Simple-CSS-Parser?msg=4179839#xx4179839xx
#Version 2.0#
Version 2 has been rewritten from the ground up! Unlike v1 which used Coco/r to generate a lexer and parser, version 2 is
written entirely by hand. This gives the new parser an incredibly fine grained level of detail when parsing some of the more
unusual edge cases for CSS 3 selectors.

#NuGet#
Install the pagckage from the NuGet Package Manager or via command line

Install-Package ExCSS

#Lexing and Parsing - How it all Wors#
ExCSS builds a Scanner (a.k.a. a Lexer) and a Parser based on a CSS3-specific grammar. The Scanner and Parser
are generated using [Coco/r](http://www.ssw.uni-linz.ac.at/coco/), and generate .NET code required to parse any common
stylesheet. Once parsed, the input styles sheet is turned into a sandard .NET object model. That means it's
#Lexing and Parsing - How it all Works#
ExCSS uses a Lexer and a Parser based on a CSS3-specific grammar. The Lexer and Parser read CSS text and parse each
character as individual tokens run against a complex set of rules that define what CSS segment each token represents.
Once parsed, the input styles sheet is turned into a standard .NET object model. That means it's
fully queryable using Linq to objects.

##A basic example:##

var parser = StylesheetParser();
var parser = Parser();
var stylesheet = parser.Parse(".someClass{color: red; background-image: url('/images/logo.png')");

var imageUrl = var image = parsed.RuleSets
var imageUrl = stylesheet.Rulesets
.SelectMany(r => r.Declarations)
.SelectMany(d => d.Expression.Terms)
.Where(t => t.Type == TermType.Url)
.First(); // Finds the '/images/logo.png' image
.FirstOrDefault(d => d.Name.Equals("background-image", StringComparison.InvariantCultureIgnoreCase))
.Term
.ToString(); // Finds the url('/images/logo.png') image url
##CSS 3 Compatible##
The project has a growing suite of tests. Currently the tests account for and pass all CSS Level 3 selector definitions
found in [the W3 CSS 3 Release Candidate documentation](http://www.w3.org/TR/2001/CR-css3-selectors-20011113/)

Take a look at the currently tested selectors: https://github.com/TylerBrinks/ExCSS/wiki/CSS-3-Selector-Test-Status

*Please consider helping* this project out by helping our test list grow to match any valid CSS selector we're missing.

##Advanced Stuff##
ExCSS uses [Coco/r](http://http://ssw.jku.at/Coco/) to build a Lexer and Parser based on a CSS3 compatible grammar.
The grammar defines valid CSS3 directives, selectors, rules, attributes, elements, and types that make up the body
ofa style sheet.

Coco/r is responsible for translating the grammar into usable C#. The grammar is a living document; the goal of
this project is to keep it up to date wtih the CSS Level 3 specifications as they evolve.

The grammar is an Attributed Grammar (ATG) based on an Extended Backus-Naur Form (EBNF). That means the output
parser allows for injecting C# coding conventions. In the case of ExCSS, that means an entire object model can
be constructed from simple and isolated grammar-based rules.

Take a look at the css.v3.02.1.atg file for the full grammar


0 comments on commit 9a37378

Please sign in to comment.