Class: JsDuck::CssParser
- Inherits:
-
Object
- Object
- JsDuck::CssParser
- Defined in:
- lib/jsduck/css_parser.rb
Instance Method Summary collapse
-
#code_block ⇒ Object
<code-block> := <mixin> | <nop>.
-
#css_ident ⇒ Object
<css-ident> := <ident> [ “-” <ident> ]*.
-
#initialize(input, options = {}) ⇒ CssParser
constructor
A new instance of CssParser.
- #look(*args) ⇒ Object
-
#match(*args) ⇒ Object
Matches all arguments, returns the value of last match When the whole sequence doesn’t match, throws exception.
-
#mixin ⇒ Object
<mixin> := “@mixin” <css-ident>.
-
#parse ⇒ Object
Parses the whole CSS block and returns same kind of structure that JavaScript parser does.
Constructor Details
Instance Method Details
#code_block ⇒ Object
<code-block> := <mixin> | <nop>
32 33 34 35 36 37 38 |
# File 'lib/jsduck/css_parser.rb', line 32 def code_block if look("@", "mixin") mixin else {:type => :nop} end end |
#css_ident ⇒ Object
<css-ident> := <ident> [ “-” <ident> ]*
50 51 52 53 54 55 56 |
# File 'lib/jsduck/css_parser.rb', line 50 def css_ident chain = [match(:ident)] while look("-", :ident) do chain << match("-", :ident) end return chain.join("-") end |
#look(*args) ⇒ Object
70 71 72 |
# File 'lib/jsduck/css_parser.rb', line 70 def look(*args) @lex.look(*args) end |
#match(*args) ⇒ Object
Matches all arguments, returns the value of last match When the whole sequence doesn’t match, throws exception
60 61 62 63 64 65 66 67 68 |
# File 'lib/jsduck/css_parser.rb', line 60 def match(*args) if look(*args) last = nil args.length.times { last = @lex.next } last else throw "Expected: " + args.join(", ") end end |
#mixin ⇒ Object
<mixin> := “@mixin” <css-ident>
41 42 43 44 45 46 47 |
# File 'lib/jsduck/css_parser.rb', line 41 def mixin match("@", "mixin") return { :type => :css_mixin, :name => look(:ident) ? css_ident : nil, } end |
#parse ⇒ Object
Parses the whole CSS block and returns same kind of structure that JavaScript parser does.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jsduck/css_parser.rb', line 15 def parse while !@lex.empty? do if look(:doc_comment) comment = @lex.next(true) @docs << { :comment => @doc_parser.parse(comment[:value]), :linenr => comment[:linenr], :code => code_block } else @lex.next end end @docs end |