Class: ParseBlock
- Inherits:
-
EndableParseState
- Object
- ParseState
- EndableParseState
- ParseBlock
- Defined in:
- lib/saikuro/parse_block.rb
Instance Attribute Summary
Attributes inherited from ParseState
#children, #complexity, #lines, #name, #parent
Instance Method Summary collapse
- #do_right_brace_token(token) ⇒ Object
-
#initialize(lexer, parent = nil) ⇒ ParseBlock
constructor
A new instance of ParseBlock.
-
#parse_token(token) ⇒ Object
Because the token for a block and hash right brace is the same, we need to track the hash left braces to determine when an end is encountered.
Methods inherited from EndableParseState
Methods inherited from ParseState
#calc_complexity, #calc_lines, #compute_state, #compute_state_for_global, #count_tokens?, #do_begin_token, #do_block_token, #do_case_token, #do_class_token, #do_comment_token, #do_conditional_do_control_token, #do_conditional_token, #do_constant_token, #do_def_token, #do_else_token, #do_end_token, #do_identifier_token, #do_module_token, #do_one_line_conditional_token, #do_symbol_token, #end_debug, get_token_counter, #lexer=, #lexer_loop?, #make_state, make_top_state, #parse, set_token_counter, #top_state?
Constructor Details
#initialize(lexer, parent = nil) ⇒ ParseBlock
Returns a new instance of ParseBlock.
3 4 5 6 7 |
# File 'lib/saikuro/parse_block.rb', line 3 def initialize(lexer,parent=nil) super(lexer,parent) @complexity = 1 @lbraces = Array.new end |
Instance Method Details
#do_right_brace_token(token) ⇒ Object
27 28 29 30 31 |
# File 'lib/saikuro/parse_block.rb', line 27 def do_right_brace_token(token) # we are done ? what about a hash in a block :-/ @run = false nil end |
#parse_token(token) ⇒ Object
Because the token for a block and hash right brace is the same, we need to track the hash left braces to determine when an end is encountered.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/saikuro/parse_block.rb', line 12 def parse_token(token) if token.is_a?(TkLBRACE) @lbraces.push(true) elsif token.is_a?(TkRBRACE) if @lbraces.empty? do_right_brace_token(token) #do_end_token(token) else @lbraces.pop end else super(token) end end |