Class: JsDuck::Doc::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/doc/scanner.rb

Overview

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.

Direct Known Subclasses

Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScanner

Returns a new instance of Scanner.



15
16
17
18
19
20
21
# 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

Instance Attribute Details

#inputObject

Provides access to StringScanner



24
25
26
# File 'lib/jsduck/doc/scanner.rb', line 24

def input
  @input
end

Instance Method Details

#hwObject

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.



70
71
72
73
# File 'lib/jsduck/doc/scanner.rb', line 70

def hw
  @input.scan(/[ \t]+/)
  self
end

#identObject

matches identifier and returns its name



43
44
45
# File 'lib/jsduck/doc/scanner.rb', line 43

def ident
  @input.scan(@ident_pattern)
end

#ident_chainObject

matches chained.identifier.name and returns it



38
39
40
# File 'lib/jsduck/doc/scanner.rb', line 38

def ident_chain
  @input.scan(@ident_chain_pattern)
end

#look(re) ⇒ Object

Looks for the existance of pattern. Returns the matching string on success, nil on failure, but doesn’t advance the scan pointer.



50
51
52
# File 'lib/jsduck/doc/scanner.rb', line 50

def look(re)
  @input.check(re)
end

#match(re) ⇒ Object

Matches the given pattern and advances the scan pointer returning the string that matched. When the pattern doesn’t match, nil is returned.



57
58
59
# File 'lib/jsduck/doc/scanner.rb', line 57

def match(re)
  @input.scan(re)
end

#skip_whiteObject

Skips all whitespace. Moves scan pointer to next non-whitespace character.



63
64
65
# File 'lib/jsduck/doc/scanner.rb', line 63

def skip_white
  @input.scan(/\s+/)
end

#standard_tag(cfg) ⇒ Object

Parses standard pattern common in several builtin tags, which goes like this:

@tag {Type} [some.name=default]

See StandardTagParser#parse for details.



33
34
35
# File 'lib/jsduck/doc/scanner.rb', line 33

def standard_tag(cfg)
  Doc::StandardTagParser.new(self).parse(cfg)
end

#warn(type, msg) ⇒ Object

Prints a warning message



76
77
78
# File 'lib/jsduck/doc/scanner.rb', line 76

def warn(type, msg)
  Logger.warn(type, msg, @position)
end