treetop_css 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ grammar CSS
2
+ include CSSSelector
3
+ include CSSDeclaration
4
+
5
+ rule stylesheet
6
+ (ruleset / media)*
7
+ end
8
+
9
+ rule media
10
+ s? '@media' media_list '{' ruleset* '}' s?
11
+ end
12
+
13
+ rule media_list
14
+ s? medium ( s? ',' s? medium )* s?
15
+ end
16
+
17
+ rule medium
18
+ (identifier / '(' s declaration s ')' ) s? (medium)* s
19
+ end
20
+
21
+ rule ruleset
22
+ s? selector ( s? ',' s? selector)* s? '{' s? ( declaration s? )* '}' s?
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ grammar CSSColor
2
+ rule color
3
+ color_keyword / hex_value / rgb
4
+ end
5
+
6
+ rule color_keyword
7
+ 'aqua' / 'black' / 'blue' / 'fuchsia' / 'gray' / 'green' / 'lime' /
8
+ 'maroon' / 'navy' / 'olive' / 'purple' / 'red' / 'silver' / 'teal' /
9
+ 'white' / 'yellow'
10
+ end
11
+
12
+ rule rgb
13
+ 'rgb' s '(' s rgb_value s ',' s rgb_value s ',' s rgb_value s ')'
14
+ end
15
+
16
+ rule rgb_value
17
+ percentage / two_fifty_six_color
18
+ end
19
+
20
+ rule two_fifty_six_color
21
+ number
22
+ end
23
+
24
+ rule hex_value
25
+ '#' (six_digit_hex / three_digit_hex)
26
+ end
27
+
28
+ rule six_digit_hex
29
+ three_digit_hex three_digit_hex
30
+ end
31
+
32
+ rule three_digit_hex
33
+ hex_char hex_char hex_char
34
+ end
35
+
36
+ rule hex_char
37
+ [0-9a-fA-F]
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ grammar CSSDeclaration
2
+ include CSSExpression
3
+
4
+ rule declaration
5
+ property s ':' s expression? s priority? s (semicolon s)*
6
+ end
7
+
8
+ rule property
9
+ '*'? s identifier
10
+ end
11
+
12
+ rule priority
13
+ '!important'
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ grammar CSSExpression
2
+ include CSSPrimitives
3
+
4
+ rule expression
5
+ term (operator? term)*
6
+ end
7
+
8
+ rule term
9
+ quoted_string / function / primitive_data / string / number / identifier
10
+ end
11
+
12
+ rule identifier
13
+ [-]? [_a-zA-Z]+ [_a-zA-Z0-9-]*
14
+ end
15
+
16
+ rule function
17
+ identifier ( [:.] identifier )* '(' [^)]* ')'
18
+ end
19
+
20
+ rule operator
21
+ s ('/' / ',' / '=') s
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module CSSPreparser
2
+ def parse(string)
3
+ replace_comments(string)
4
+ super
5
+ end
6
+
7
+ private
8
+
9
+ def replace_comments(string)
10
+ string.gsub!(/\/\*.*?\*\//m, '')
11
+ end
12
+ end
@@ -0,0 +1,104 @@
1
+ grammar CSSPrimitives
2
+ include URL
3
+ include CSSColor
4
+
5
+ rule primitive_data
6
+ length / percentage / color / space / url_declaration / angle / time / frequency
7
+ end
8
+
9
+ rule length
10
+ sign? float length_unit
11
+ end
12
+
13
+ rule length_unit
14
+ 'em' / 'ex' / 'px' / 'in' / 'cm' / 'mm' / 'pt' / 'pc'
15
+ end
16
+
17
+ rule percentage
18
+ sign? number '%'
19
+ end
20
+
21
+ rule url_declaration
22
+ 'url(' q? url q? ')'
23
+ end
24
+
25
+ rule angle
26
+ sign? float angle_unit
27
+ end
28
+
29
+ rule angle_unit
30
+ 'deg' / 'grad' / 'rad'
31
+ end
32
+
33
+ rule time
34
+ positive_float time_unit
35
+ end
36
+
37
+ rule time_unit
38
+ 'ms' / 's'
39
+ end
40
+
41
+ rule frequency
42
+ positive_float frequency_unit
43
+ end
44
+
45
+ rule frequency_unit
46
+ 'Hz' / 'kHz'
47
+ end
48
+
49
+ rule number
50
+ sign? positive_number
51
+ end
52
+
53
+ rule positive_number
54
+ [0-9]+
55
+ end
56
+
57
+ rule float
58
+ number ('.' number)?
59
+ end
60
+
61
+ rule positive_float
62
+ '+'? positive_number ('.' positive_number)?
63
+ end
64
+
65
+ rule quoted_string
66
+ q [^"']* q
67
+ end
68
+
69
+ rule string
70
+ [a-zA-Z\.\/]+
71
+ end
72
+
73
+ rule symbol
74
+ semicolon / colon / sign / space
75
+ end
76
+
77
+ rule semicolon
78
+ ';'
79
+ end
80
+
81
+ rule colon
82
+ ':'
83
+ end
84
+
85
+ rule sign
86
+ '+' / '-'
87
+ end
88
+
89
+ rule space
90
+ ' '
91
+ end
92
+
93
+ rule q
94
+ '"' / "'"
95
+ end
96
+
97
+ rule s
98
+ [ \r\n\t]*
99
+ end
100
+
101
+ rule comment
102
+ '/*' [.]* '*/'
103
+ end
104
+ end
@@ -0,0 +1,47 @@
1
+ grammar CSSSelector
2
+ include CSSExpression
3
+
4
+ rule selector
5
+ simple_selector s? combinator? s? selector?
6
+ end
7
+
8
+ rule simple_selector
9
+ tag_selector / property_selector+
10
+ end
11
+
12
+ rule tag_selector
13
+ tag_name property_selector*
14
+ end
15
+
16
+ rule property_selector
17
+ hash / class / attrib / pseudo
18
+ end
19
+
20
+ rule hash
21
+ '#'
22
+ end
23
+
24
+ rule class
25
+ '.' identifier
26
+ end
27
+
28
+ rule attrib
29
+ '[' s identifier s ( match_operator s ( identifier / string ) s)? ']'
30
+ end
31
+
32
+ rule match_operator
33
+ '=' / '~=' / '|='
34
+ end
35
+
36
+ rule pseudo
37
+ ':' ( function / identifier)
38
+ end
39
+
40
+ rule tag_name
41
+ identifier / '*'
42
+ end
43
+
44
+ rule combinator
45
+ '+' / '>' / '*' / '~'
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # TODO replace with http://labs.apache.org/webarch/uri/rev-2002/rfc2396bis.html#collected-abnf
2
+
3
+ grammar URL
4
+ rule url
5
+ protocol_with_suffix? domain_with_optional_port path?
6
+ end
7
+
8
+ rule protocol_with_suffix
9
+ protocol '://'
10
+ end
11
+
12
+ rule domain_with_optional_port
13
+ domain (':' port_number)?
14
+ end
15
+
16
+ rule port_number
17
+ positive_number
18
+ end
19
+
20
+ rule domain
21
+ [a-zA-Z0-9\-\._\/]+
22
+ end
23
+
24
+ rule path
25
+ '/' path_character* query_string?
26
+ end
27
+
28
+ rule path_character
29
+ [a-zA-Z0-9\-\._~]
30
+ end
31
+
32
+ rule query_string
33
+ '?' url_key_value_pair (('&' url_key_value_pair)+)?
34
+ end
35
+
36
+ rule url_key_value_pair
37
+ string '=' string
38
+ end
39
+
40
+ rule protocol
41
+ 'https' / 'http' / 'ftp' / 'gopher' / 'mailto' / 'news' / 'nntp' /
42
+ 'telnet' / 'wais' / 'file' / 'prospero'
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ require "rubygems"
2
+ require "treetop"
3
+ require File.dirname(__FILE__) + "/css/css_pre_parser"
4
+
5
+ Treetop.load File.dirname(__FILE__) + "/css/url"
6
+ Treetop.load File.dirname(__FILE__) + "/css/css_color"
7
+ Treetop.load File.dirname(__FILE__) + "/css/css_primitives"
8
+ Treetop.load File.dirname(__FILE__) + "/css/css_expression"
9
+ Treetop.load File.dirname(__FILE__) + "/css/css_declaration"
10
+ Treetop.load File.dirname(__FILE__) + "/css/css_selector"
11
+ Treetop.load File.dirname(__FILE__) + "/css/css"
12
+
13
+ CSSParser.send(:include, CSSPreparser)
@@ -0,0 +1,3 @@
1
+ module TreetopCss
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: treetop_css
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Sven Fuchs
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-20 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Treetop CSS grammar/parser.
22
+ email: svenfuchs@artweb-design.de
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/css/css.treetop
31
+ - lib/css/css_color.treetop
32
+ - lib/css/css_declaration.treetop
33
+ - lib/css/css_expression.treetop
34
+ - lib/css/css_pre_parser.rb
35
+ - lib/css/css_primitives.treetop
36
+ - lib/css/css_selector.treetop
37
+ - lib/css/url.treetop
38
+ - lib/treetop_css.rb
39
+ - lib/treetop_css/version.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/svenfuchs/treetop_css
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 1
62
+ - 3
63
+ - 6
64
+ version: 1.3.6
65
+ requirements: []
66
+
67
+ rubyforge_project: "[none]"
68
+ rubygems_version: 1.3.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Treetop CSS grammar/parser
72
+ test_files: []
73
+