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

input[RW]

Provides access to StringScanner

Public Class Methods

new() click to toggle source
# 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

hw() click to toggle source

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
ident() click to toggle source

matches identifier and returns its name

# File lib/jsduck/doc/scanner.rb, line 43
def ident
  @input.scan(@ident_pattern)
end
ident_chain() click to toggle source

matches chained.identifier.name and returns it

# File lib/jsduck/doc/scanner.rb, line 38
def ident_chain
  @input.scan(@ident_chain_pattern)
end
look(re) click to toggle source

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
match(re) click to toggle source

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
skip_white() click to toggle source

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
standard_tag(cfg) click to toggle source

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
warn(type, msg, params=[]) click to toggle source

Prints a warning message

# File lib/jsduck/doc/scanner.rb, line 76
def warn(type, msg, params=[])
  Logger.warn(type, msg, @position, params)
end