class JsDuck::Doc::Scanner
Abstract base class for parsing doc-comments.
The methods of this class are to be called from implementations of concrete @tags. Although the @tag classes will get passed an instance of Doc::Parser
, only methods of Doc::Scanner
should be called by them.
Attributes
Provides access to StringScanner
Public Class Methods
# File lib/jsduck/doc/scanner.rb, line 15 def initialize @ident_pattern = /[$\w-]+/ @ident_chain_pattern = /[$\w-]+(\.[$\w-]+)*/ @input = nil # set to StringScanner in subclass @position = {} # set in subclass end
Public Instance Methods
Skips horizontal whitespace (tabs and spaces). Moves scan pointer to next non-whitespace character or to the end of line. Returns self to allow chaining.
# File lib/jsduck/doc/scanner.rb, line 70 def hw @input.scan(/[ \t]+/) self end
matches identifier and returns its name
# File lib/jsduck/doc/scanner.rb, line 43 def ident @input.scan(@ident_pattern) end
matches chained.identifier.name and returns it
# File lib/jsduck/doc/scanner.rb, line 38 def ident_chain @input.scan(@ident_chain_pattern) end
Looks for the existance of pattern. Returns the matching string on success, nil on failure, but doesn't advance the scan pointer.
# File lib/jsduck/doc/scanner.rb, line 50 def look(re) @input.check(re) end
Matches the given pattern and advances the scan pointer returning the string that matched. When the pattern doesn't match, nil is returned.
# File lib/jsduck/doc/scanner.rb, line 57 def match(re) @input.scan(re) end
Skips all whitespace. Moves scan pointer to next non-whitespace character.
# File lib/jsduck/doc/scanner.rb, line 63 def skip_white @input.scan(/\s+/) end
Parses standard pattern common in several builtin tags, which goes like this:
@tag {Type} [some.name=default]
See StandardTagParser#parse
for details.
# File lib/jsduck/doc/scanner.rb, line 33 def standard_tag(cfg) Doc::StandardTagParser.new(self).parse(cfg) end
Prints a warning message
# File lib/jsduck/doc/scanner.rb, line 76 def warn(type, msg, params=[]) Logger.warn(type, msg, @position, params) end