Class: Liquidscript::Scanner::Base
- Inherits:
-
Object
- Object
- Liquidscript::Scanner::Base
show all
- Includes:
- Enumerable, Lexer
- Defined in:
- lib/liquidscript/scanner/base.rb,
lib/liquidscript/scanner/base/dsl.rb,
lib/liquidscript/scanner/base/lexer.rb,
lib/liquidscript/scanner/base/builder.rb,
lib/liquidscript/scanner/base/context.rb
Overview
Defined Under Namespace
Modules: DSL, Lexer
Classes: Builder, Context
Constant Summary
collapse
- EXIT =
Object.new.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Lexer
#error, #lex, #perform_with_context
Constructor Details
#initialize(source, file = nil) ⇒ Base
Returns a new instance of Base.
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/liquidscript/scanner/base.rb', line 20
def initialize(source, file = nil)
@source = source
@scanner = StringScanner.new(@source)
@tokens = []
@_scan = nil
@metadata = {}
if !file and source.respond_to?(:to_path)
file = source.to_path
end
@metadata[:file] = file || "<none>"
end
|
Instance Attribute Details
Returns the value of attribute metadata.
18
19
20
|
# File 'lib/liquidscript/scanner/base.rb', line 18
def metadata
@metadata
end
|
Instance Method Details
#column ⇒ Object
65
66
67
|
# File 'lib/liquidscript/scanner/base.rb', line 65
def column
"(unkown)"
end
|
#contexts ⇒ Object
38
39
40
|
# File 'lib/liquidscript/scanner/base.rb', line 38
def contexts
self.class.contexts
end
|
#default_context ⇒ Object
42
43
44
|
# File 'lib/liquidscript/scanner/base.rb', line 42
def default_context
self.class.default
end
|
#each ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/liquidscript/scanner/base.rb', line 51
def each
e = buffer.each
if block_given?
e.each(&Proc.new)
else
e
end
end
|
#emit(token_name, body = nil) ⇒ Object
69
70
71
|
# File 'lib/liquidscript/scanner/base.rb', line 69
def emit(token_name, body = nil)
@tokens << Token.new(token_name, body, line, column)
end
|
#file ⇒ Object
34
35
36
|
# File 'lib/liquidscript/scanner/base.rb', line 34
def file
@metadata[:file]
end
|
#inspect ⇒ Object
73
74
75
|
# File 'lib/liquidscript/scanner/base.rb', line 73
def inspect
"#<#{self.class}:#{'0x%08x' % object_id}>"
end
|
#line ⇒ Object
61
62
63
|
# File 'lib/liquidscript/scanner/base.rb', line 61
def line
"(unknown)"
end
|
#scan ⇒ Object
46
47
48
49
|
# File 'lib/liquidscript/scanner/base.rb', line 46
def scan
lex default_context
self
end
|