Class: AdLint::StringContent
Overview
DESCRIPTION
Object represents the whole content of the string.
Direct Known Subclasses
Instance Method Summary collapse
- #_debug_inspect ⇒ Object
- #check(regexp) ⇒ Object
-
#eat!(len = 1) ⇒ Object
DESCRIPTION Skips a content.
-
#empty? ⇒ Boolean
DESCRIPTION Checks whether this content is currently empty or not.
-
#initialize(str, tab_width = 8, fpath = nil, line_no = 1, column_no = 1) ⇒ StringContent
constructor
DESCRIPTION Constructs the content object of the string.
- #location ⇒ Object
-
#scan(regexp) ⇒ Object
DESCRIPTION Scans a token.
Constructor Details
#initialize(str, tab_width = 8, fpath = nil, line_no = 1, column_no = 1) ⇒ StringContent
DESCRIPTION
Constructs the content object of the string.
PARAMETER
- str
-
String – Target string.
- fpath
-
Pathname – File path name contains the target string.
- line_no
-
Integer – Initial line-no of the target string.
84 85 86 87 88 89 |
# File 'lib/adlint/lexer.rb', line 84 def initialize(str, tab_width = 8, fpath = nil, line_no = 1, column_no = 1) @scanner = StringScanner.new(str) @tab_width = tab_width @fpath, @line_no, @column_no = fpath, line_no, column_no @appearance_column_no = column_no end |
Instance Method Details
#_debug_inspect ⇒ Object
139 140 141 |
# File 'lib/adlint/lexer.rb', line 139 def _debug_inspect @scanner.rest end |
#check(regexp) ⇒ Object
114 115 116 |
# File 'lib/adlint/lexer.rb', line 114 def check(regexp) @scanner.check(regexp) end |
#eat!(len = 1) ⇒ Object
DESCRIPTION
Skips a content.
PARAMETER
- len
-
Integer – Skipping content length.
RETURN VALUE
String – Eaten string.
126 127 128 |
# File 'lib/adlint/lexer.rb', line 126 def eat!(len = 1) self.scan(/.{#{len}}/m) end |
#empty? ⇒ Boolean
DESCRIPTION
Checks whether this content is currently empty or not.
RETURN VALUE
Boolean – Returns true if already empty.
135 136 137 |
# File 'lib/adlint/lexer.rb', line 135 def empty? @scanner.eos? end |
#location ⇒ Object
91 92 93 |
# File 'lib/adlint/lexer.rb', line 91 def location Location.new(@fpath, @line_no, @column_no, @appearance_column_no) end |
#scan(regexp) ⇒ Object
DESCRIPTION
Scans a token.
PARAMETER
- regexp
-
Regexp – Token pattern.
RETURN VALUE
String – Token string or nil.
104 105 106 107 108 109 110 111 112 |
# File 'lib/adlint/lexer.rb', line 104 def scan(regexp) tok = @scanner.scan(regexp) if tok update_location(tok) tok else nil end end |