Class: LexerKit::DFA::RegexAST::Regex

Inherits:
Data
  • Object
show all
Defined in:
lib/lexer_kit/dfa/regex_ast.rb

Overview

Complete regex pattern with flags Wraps an AST node with pattern-level settings

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast

Returns:

  • (Object)

    the current value of ast



44
45
46
# File 'lib/lexer_kit/dfa/regex_ast.rb', line 44

def ast
  @ast
end

#case_insensitiveObject (readonly)

Returns the value of attribute case_insensitive

Returns:

  • (Object)

    the current value of case_insensitive



44
45
46
# File 'lib/lexer_kit/dfa/regex_ast.rb', line 44

def case_insensitive
  @case_insensitive
end

Class Method Details

.parse(pattern) ⇒ Regex

Parse a pattern into Regex

Parameters:

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lexer_kit/dfa/regex_ast.rb', line 48

def self.parse(pattern)
  case pattern
  when self
    pattern
  when LexerKit::RegexAstProvider
    pattern.to_regex
  else
    source = pattern.is_a?(Regexp) ? pattern.source : pattern
    case_insensitive = pattern.is_a?(Regexp) && pattern.casefold?
    ast = RegexParser.new(source).parse
    new(ast: ast, case_insensitive: case_insensitive)
  end
end