Class: JsDuck::Warning::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/warning/parser.rb

Overview

Parses the warnings passed in from command line

Grammar:

:= [ "," ]*

:= ["+" | "-"] [] []

:= \w+

:= "(" [] ")"

:= [ "," ]*

:= \w+ | ""

:= ":"

:= .*

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

Returns a new instance of Parser.



28
29
30
# File 'lib/jsduck/warning/parser.rb', line 28

def initialize(string)
  @scanner = StringScanner.new(string)
end

Instance Method Details

#parse ⇒ Object

Parses the warnings string.

For example the following string:

+tag,-nodoc(class,private):/some/path

is parsed into the following structure:

[
  {
    :type => :tag,
    :enabled => true,
    :params => [],
    :path => nil,
  },
  {
    :type => :nodoc,
    :enabled => false,
    :params => [:class, :private],
    :path => "/some/path",
  },
]

When scanning fails, raises an exception with a descriptive message.



57
58
59
60
61
62
63
64
65
66
# File 'lib/jsduck/warning/parser.rb', line 57

def parse
  results = []

  while !eos?
    results << warning
    match(/,/)
  end

  results
end