Class: Token
- Inherits:
-
Object
- Object
- Token
- Defined in:
- lib/luobo/token.rb
Overview
this class holds a block of carrot source code tokenized by the parser.
Instance Attribute Summary collapse
-
#blocks ⇒ Object
raw line and line number.
-
#indent_level ⇒ Object
raw line and line number.
-
#line ⇒ Object
raw line and line number.
-
#line_code ⇒ Object
raw line and line number.
-
#ln ⇒ Object
raw line and line number.
-
#processor_name ⇒ Object
raw line and line number.
Instance Method Summary collapse
-
#add_block_code(line) ⇒ Object
add a line to current block args, separate each line with ānā.
- #block_args ⇒ Object
- #block_code ⇒ Object
- #block_open? ⇒ Boolean
- #has_block? ⇒ Boolean
- #indent ⇒ Object
-
#initialize(ln, line, indent_level, processor_name, line_code = '', block_open = false) ⇒ Token
constructor
A new instance of Token.
- #line_args ⇒ Object
Constructor Details
#initialize(ln, line, indent_level, processor_name, line_code = '', block_open = false) ⇒ Token
Returns a new instance of Token.
6 7 8 9 |
# File 'lib/luobo/token.rb', line 6 def initialize ln, line, indent_level, processor_name, line_code = '', block_open = false @ln, @line, @indent_level, @processor_name, @line_code = ln, line, indent_level, processor_name, line_code @blocks = Array.new if block_open end |
Instance Attribute Details
#blocks ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def blocks @blocks end |
#indent_level ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def indent_level @indent_level end |
#line ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def line @line end |
#line_code ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def line_code @line_code end |
#ln ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def ln @ln end |
#processor_name ⇒ Object
raw line and line number
3 4 5 |
# File 'lib/luobo/token.rb', line 3 def processor_name @processor_name end |
Instance Method Details
#add_block_code(line) ⇒ Object
add a line to current block args, separate each line with ānā
16 17 18 19 20 21 |
# File 'lib/luobo/token.rb', line 16 def add_block_code line raise "block not opened in line #{:ln}" unless block_open? line.chomp.split("\n").each do |ln| @blocks << ln end end |
#block_args ⇒ Object
35 36 37 |
# File 'lib/luobo/token.rb', line 35 def block_args YAML.load(block_code) end |
#block_code ⇒ Object
31 32 33 |
# File 'lib/luobo/token.rb', line 31 def block_code has_block? ? @blocks.join("\n") : "" end |
#block_open? ⇒ Boolean
27 28 29 |
# File 'lib/luobo/token.rb', line 27 def block_open? @blocks.is_a?(Array) end |
#has_block? ⇒ Boolean
23 24 25 |
# File 'lib/luobo/token.rb', line 23 def has_block? (@blocks and @blocks.size > 0) ? true : false end |
#indent ⇒ Object
11 12 13 |
# File 'lib/luobo/token.rb', line 11 def indent " " * indent_level end |
#line_args ⇒ Object
39 40 41 |
# File 'lib/luobo/token.rb', line 39 def line_args YAML.load(line_code) end |