Module: LangScan::CSS
- Defined in:
- lib/langscan/css.rb
Constant Summary collapse
- Pattern =
[ [:comment, "/\\*", "\\*/"], [:string, "\"", "[^\\\\]\""], [:string, "\\(", "[^\\\\]\\)"], [:keyword, "\\!\s*important"], # [:ident, "[-@\\.\\#\\>\\w]+"], [:ident, "[-@\\w]+"], [:integer, "\\d[\\.\\w\\d%]+"], [:punct, "\\."], [:punct, "\\#"], [:punct, "\\{"], [:punct, "\\}"], [:punct, "\\:"], [:punct, "\\;"], ]
- Types =
[]
- Keywords =
%w( url @import important )
Class Method Summary collapse
- .abbrev ⇒ Object
- .extnames ⇒ Object
- .goback(new_tokens) ⇒ Object
- .name ⇒ Object
- .parse_token(t, new_tokens) ⇒ Object
-
.scan(input, &block) ⇒ Object
LangScan::CSS.scan iterates over CSS file.
Class Method Details
.abbrev ⇒ Object
21 22 23 |
# File 'lib/langscan/css.rb', line 21 def abbrev "css" end |
.extnames ⇒ Object
25 26 27 |
# File 'lib/langscan/css.rb', line 25 def extnames [".css"] end |
.goback(new_tokens) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/langscan/css.rb', line 53 def goback(new_tokens) for i in 0...new_tokens.length past_token = new_tokens[new_tokens.length-1-i] # take it from the last if past_token if past_token.type == :ident || past_token.type == :keyword past_token.type = :fundef end if past_token.type == :punct && (past_token.text == "}" || past_token.text == ";") break end end end end |
.name ⇒ Object
17 18 19 |
# File 'lib/langscan/css.rb', line 17 def name "CSS" end |
.parse_token(t, new_tokens) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/langscan/css.rb', line 69 def parse_token(t, new_tokens) last_token = new_tokens.last return if last_token.nil? return unless t.type == :punct and last_token.type == :ident if t.text == ':' last_token.type = :keyword return end if t.text == '{' goback(new_tokens) return end end |
.scan(input, &block) ⇒ Object
LangScan::CSS.scan iterates over CSS file. It yields for each Fragment.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/langscan/css.rb', line 88 def scan(input, &block) scanner = EasyScanner.new(Pattern, Types, Keywords) tokens = [] scanner.scan(input) {|t| tokens << t } new_tokens = [] tokens.each {|t| parse_token(t, new_tokens) new_tokens << t } new_tokens.each {|t| yield t } end |