Class: LexerKit::Builder::TokenDef
- Inherits:
-
Object
- Object
- LexerKit::Builder::TokenDef
- Defined in:
- lib/lexer_kit/builder/token_def.rb
Overview
TokenDef represents a token definition from the DSL.
Instance Attribute Summary collapse
-
#delimited ⇒ Object
readonly
Returns the value of attribute delimited.
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#escape ⇒ Object
readonly
Returns the value of attribute escape.
-
#inner_mode ⇒ Object
Returns the value of attribute inner_mode.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#pop ⇒ Object
readonly
Returns the value of attribute pop.
-
#push ⇒ Object
readonly
Returns the value of attribute push.
-
#skip ⇒ Object
readonly
Returns the value of attribute skip.
-
#token_id ⇒ Object
Returns the value of attribute token_id.
Instance Method Summary collapse
-
#delimited? ⇒ Boolean
Check if this is a delimited token (like TEXT in templates).
-
#initialize(name:, pattern:, skip: false, push: nil, pop: false, delimited: false, delimiter: nil, escape: nil, meta: nil, location: nil) ⇒ TokenDef
constructor
A new instance of TokenDef.
- #inspect ⇒ Object
-
#literal? ⇒ Boolean
Check if pattern is a literal string.
-
#regex? ⇒ Boolean
Check if pattern is a regex.
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 = @inner_mode = nil @token_id = nil @location = location end |
Instance Attribute Details
#delimited ⇒ Object (readonly)
Returns the value of attribute delimited.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def delimited @delimited end |
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def delimiter @delimiter end |
#escape ⇒ Object (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_mode ⇒ Object
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 |
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def location @location end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def pattern @pattern end |
#pop ⇒ Object (readonly)
Returns the value of attribute pop.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def pop @pop end |
#push ⇒ Object (readonly)
Returns the value of attribute push.
7 8 9 |
# File 'lib/lexer_kit/builder/token_def.rb', line 7 def push @push end |
#skip ⇒ Object (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_id ⇒ Object
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)
47 48 49 |
# File 'lib/lexer_kit/builder/token_def.rb', line 47 def delimited? @delimited end |
#inspect ⇒ Object
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
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
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 |