Class: Token

Inherits:
Object
  • Object
show all
Defined in:
lib/luobo/token.rb

Overview

this class holds a block of carrot source code tokenized by the parser.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blocksObject

raw line and line number



3
4
5
# File 'lib/luobo/token.rb', line 3

def blocks
  @blocks
end

#indent_levelObject

raw line and line number



3
4
5
# File 'lib/luobo/token.rb', line 3

def indent_level
  @indent_level
end

#lineObject

raw line and line number



3
4
5
# File 'lib/luobo/token.rb', line 3

def line
  @line
end

#line_codeObject

raw line and line number



3
4
5
# File 'lib/luobo/token.rb', line 3

def line_code
  @line_code
end

#lnObject

raw line and line number



3
4
5
# File 'lib/luobo/token.rb', line 3

def ln
  @ln
end

#processor_nameObject

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_argsObject



35
36
37
# File 'lib/luobo/token.rb', line 35

def block_args
  YAML.load(block_code)
end

#block_codeObject



31
32
33
# File 'lib/luobo/token.rb', line 31

def block_code
  has_block? ? @blocks.join("\n") : ""
end

#block_open?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/luobo/token.rb', line 27

def block_open?
  @blocks.is_a?(Array)
end

#has_block?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/luobo/token.rb', line 23

def has_block? 
  (@blocks and @blocks.size > 0) ? true : false
end

#indentObject



11
12
13
# File 'lib/luobo/token.rb', line 11

def indent
  " " * indent_level
end

#line_argsObject



39
40
41
# File 'lib/luobo/token.rb', line 39

def line_args
  YAML.load(line_code)
end