Class: JsDuck::Doc::Scanner
- Inherits:
-
Object
- Object
- JsDuck::Doc::Scanner
- 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
Instance Attribute Summary collapse
-
#input ⇒ Object
Provides access to StringScanner.
Instance Method Summary collapse
-
#hw ⇒ Object
Skips horizontal whitespace (tabs and spaces).
-
#ident ⇒ Object
matches identifier and returns its name.
-
#ident_chain ⇒ Object
matches chained.identifier.name and returns it.
-
#initialize ⇒ Scanner
constructor
A new instance of Scanner.
-
#look(re) ⇒ Object
Looks for the existance of pattern.
-
#match(re) ⇒ Object
Matches the given pattern and advances the scan pointer returning the string that matched.
-
#skip_white ⇒ Object
Skips all whitespace.
-
#standard_tag(cfg) ⇒ Object
Parses standard pattern common in several builtin tags, which goes like this:.
-
#warn(type, msg, params = []) ⇒ Object
Prints a warning message.
Constructor Details
#initialize ⇒ Scanner
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
#input ⇒ Object
Provides access to StringScanner
24 25 26 |
# File 'lib/jsduck/doc/scanner.rb', line 24 def input @input end |
Instance Method Details
#hw ⇒ Object
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 |
#ident ⇒ Object
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_chain ⇒ Object
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_white ⇒ Object
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 |