Class: LexerKit::Builder::ModeDef

Inherits:
Object
  • Object
show all
Defined in:
lib/lexer_kit/builder/mode_def.rb

Overview

ModeDef represents a lexer mode definition.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, location: nil) ⇒ ModeDef

Returns a new instance of ModeDef.



10
11
12
13
14
15
# File 'lib/lexer_kit/builder/mode_def.rb', line 10

def initialize(name, location: nil)
  @name = name
  @tokens = []
  @delimited = nil
  @location = location
end

Instance Attribute Details

#delimitedObject

Returns the value of attribute delimited.



8
9
10
# File 'lib/lexer_kit/builder/mode_def.rb', line 8

def delimited
  @delimited
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/lexer_kit/builder/mode_def.rb', line 7

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/lexer_kit/builder/mode_def.rb', line 7

def name
  @name
end

#tokensObject (readonly)

Returns the value of attribute tokens.



7
8
9
# File 'lib/lexer_kit/builder/mode_def.rb', line 7

def tokens
  @tokens
end

Instance Method Details

#add_token(token_def) ⇒ Object



17
18
19
# File 'lib/lexer_kit/builder/mode_def.rb', line 17

def add_token(token_def)
  @tokens << token_def
end

#inspectObject



31
32
33
# File 'lib/lexer_kit/builder/mode_def.rb', line 31

def inspect
  "#<ModeDef :#{@name} tokens=#{@tokens.size}>"
end

#literal_tokensObject

Get all literal tokens (for SWITCH_BYTE optimization)



22
23
24
# File 'lib/lexer_kit/builder/mode_def.rb', line 22

def literal_tokens
  @tokens.select(&:literal?)
end

#regex_tokensObject

Get all regex tokens



27
28
29
# File 'lib/lexer_kit/builder/mode_def.rb', line 27

def regex_tokens
  @tokens.select(&:regex?)
end