Class: LexerKit::Builder::TokenDef

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

Overview

TokenDef represents a token definition from the DSL.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, pattern:, skip: false, push: nil, pop: false, delimited: false, delimiter: nil, escape: nil, meta: nil, location: nil) ⇒ TokenDef

Returns a new instance of TokenDef.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lexer_kit/builder/token_def.rb', line 10

def initialize(
  name:,
  pattern:,
  skip: false,
  push: nil,
  pop: false,
  delimited: false,
  delimiter: nil,
  escape: nil,
  meta: nil,
  location: nil
)
  @name = name
  @pattern = pattern
  @skip = skip
  @push = push
  @pop = pop
  @delimited = delimited
  @delimiter = delimiter
  @escape = escape
  @meta = meta
  @inner_mode = nil
  @token_id = nil
  @location = location
end

Instance Attribute Details

#delimitedObject (readonly)

Returns the value of attribute delimited.



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

def delimited
  @delimited
end

#delimiterObject (readonly)

Returns the value of attribute delimiter.



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

def delimiter
  @delimiter
end

#escapeObject (readonly)

Returns the value of attribute escape.



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

def escape
  @escape
end

#inner_modeObject

Returns the value of attribute inner_mode.



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

def inner_mode
  @inner_mode
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#metaObject (readonly)

Returns the value of attribute meta.



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

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

#popObject (readonly)

Returns the value of attribute pop.



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

def pop
  @pop
end

#pushObject (readonly)

Returns the value of attribute push.



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

def push
  @push
end

#skipObject (readonly)

Returns the value of attribute skip.



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

def skip
  @skip
end

#token_idObject

Returns the value of attribute token_id.



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

def token_id
  @token_id
end

Instance Method Details

#delimited?Boolean

Check if this is a delimited token (like TEXT in templates)

Returns:

  • (Boolean)


47
48
49
# File 'lib/lexer_kit/builder/token_def.rb', line 47

def delimited?
  @delimited
end

#inspectObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lexer_kit/builder/token_def.rb', line 51

def inspect
  parts = ["#<TokenDef :#{@name}"]
  parts << @pattern.inspect if @pattern
  parts << "skip" if @skip
  parts << "push=#{@push}" if @push
  parts << "pop" if @pop
  parts << "delimited=#{@delimiter.inspect}" if @delimited
  parts << "escape=#{@escape.inspect}" if @escape
  parts << "meta=#{@meta.inspect}" if @meta
  parts << ">"
  parts.join(" ")
end

#literal?Boolean

Check if pattern is a literal string

Returns:

  • (Boolean)


37
38
39
# File 'lib/lexer_kit/builder/token_def.rb', line 37

def literal?
  @pattern.is_a?(String)
end

#regex?Boolean

Check if pattern is a regex

Returns:

  • (Boolean)


42
43
44
# File 'lib/lexer_kit/builder/token_def.rb', line 42

def regex?
  @pattern.is_a?(Regexp) || @pattern.is_a?(LexerKit::RegexAstProvider)
end