Module: Regexp::Syntax
- Included in:
- Parser
- Defined in:
- lib/regexp_parser/syntax/tokens.rb,
lib/regexp_parser/syntax.rb,
lib/regexp_parser/syntax/tokens.rb,
lib/regexp_parser/syntax/ruby/1.8.rb,
lib/regexp_parser/syntax/ruby/1.9.rb,
lib/regexp_parser/syntax/ruby/2.0.rb,
lib/regexp_parser/syntax/ruby/2.1.rb,
lib/regexp_parser/syntax/ruby/2.2.rb,
lib/regexp_parser/syntax/ruby/2.3.rb,
lib/regexp_parser/syntax/ruby/1.8.6.rb,
lib/regexp_parser/syntax/ruby/1.8.7.rb,
lib/regexp_parser/syntax/ruby/1.9.1.rb,
lib/regexp_parser/syntax/ruby/1.9.2.rb,
lib/regexp_parser/syntax/ruby/1.9.3.rb,
lib/regexp_parser/syntax/ruby/2.0.0.rb,
lib/regexp_parser/syntax/ruby/2.1.0.rb,
lib/regexp_parser/syntax/ruby/2.1.2.rb,
lib/regexp_parser/syntax/ruby/2.1.3.rb,
lib/regexp_parser/syntax/ruby/2.1.4.rb,
lib/regexp_parser/syntax/ruby/2.1.5.rb,
lib/regexp_parser/syntax/ruby/2.1.6.rb,
lib/regexp_parser/syntax/ruby/2.1.7.rb,
lib/regexp_parser/syntax/ruby/2.1.8.rb,
lib/regexp_parser/syntax/ruby/2.2.0.rb,
lib/regexp_parser/syntax/ruby/2.2.1.rb,
lib/regexp_parser/syntax/ruby/2.2.2.rb,
lib/regexp_parser/syntax/ruby/2.2.3.rb,
lib/regexp_parser/syntax/ruby/2.2.4.rb,
lib/regexp_parser/syntax/ruby/2.3.0.rb,
lib/regexp_parser/syntax/tokens/keep.rb,
lib/regexp_parser/syntax/tokens/meta.rb,
lib/regexp_parser/syntax/tokens/group.rb,
lib/regexp_parser/syntax/tokens/anchor.rb,
lib/regexp_parser/syntax/tokens/escape.rb,
lib/regexp_parser/syntax/tokens/backref.rb,
lib/regexp_parser/syntax/tokens/assertion.rb,
lib/regexp_parser/syntax/tokens/quantifier.rb,
lib/regexp_parser/syntax/tokens/conditional.rb,
lib/regexp_parser/syntax/tokens/character_set.rb,
lib/regexp_parser/syntax/tokens/character_type.rb,
lib/regexp_parser/syntax/tokens/unicode_property.rb
Overview
After loading all the tokens the map is full. Extract all tokens and types into the All and Types constants.
Defined Under Namespace
Modules: Ruby, Token Classes: Any, Base, MissingSyntaxSpecError, NotImplementedError, SyntaxError, UnknownSyntaxNameError
Constant Summary collapse
- SYNTAX_SPEC_ROOT =
File.('../syntax', __FILE__)
Class Method Summary collapse
- .instantiate(name) ⇒ Object
-
.load(name) ⇒ Object
Checks if the named syntax has a specification class file, and requires it if it does.
-
.new(name) ⇒ Object
Loads, and instantiates an instance of the syntax specification class for the given syntax flavor name.
Class Method Details
.instantiate(name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/regexp_parser/syntax.rb', line 42 def self.instantiate(name) case name # Ruby 1.8.x (NOTE: 1.8.6 is no longer a supported runtime, # but its regex features are still recognized.) when 'ruby/1.8.6'; syntax = Regexp::Syntax::Ruby::V186.new when 'ruby/1.8.7'; syntax = Regexp::Syntax::Ruby::V187.new # alias for the latest 1.8 implementation when 'ruby/1.8'; syntax = Regexp::Syntax::Ruby::V18.new # Ruby 1.9.x when 'ruby/1.9.1'; syntax = Regexp::Syntax::Ruby::V191.new when 'ruby/1.9.2'; syntax = Regexp::Syntax::Ruby::V192.new when 'ruby/1.9.3'; syntax = Regexp::Syntax::Ruby::V193.new # alias for the latest 1.9 implementation when 'ruby/1.9'; syntax = Regexp::Syntax::Ruby::V19.new # Ruby 2.0.x when 'ruby/2.0.0'; syntax = Regexp::Syntax::Ruby::V200.new # aliases for the latest 2.0 implementations when 'ruby/2.0'; syntax = Regexp::Syntax::Ruby::V20.new # Ruby 2.1.x when 'ruby/2.1.0'; syntax = Regexp::Syntax::Ruby::V210.new when 'ruby/2.1.2'; syntax = Regexp::Syntax::Ruby::V212.new when 'ruby/2.1.3'; syntax = Regexp::Syntax::Ruby::V213.new when 'ruby/2.1.4'; syntax = Regexp::Syntax::Ruby::V214.new when 'ruby/2.1.5'; syntax = Regexp::Syntax::Ruby::V215.new when 'ruby/2.1.6'; syntax = Regexp::Syntax::Ruby::V216.new when 'ruby/2.1.7'; syntax = Regexp::Syntax::Ruby::V217.new when 'ruby/2.1.8'; syntax = Regexp::Syntax::Ruby::V218.new # aliases for the latest 2.1 implementations when 'ruby/2.1'; syntax = Regexp::Syntax::Ruby::V21.new # Ruby 2.2.x when 'ruby/2.2.0'; syntax = Regexp::Syntax::Ruby::V220.new when 'ruby/2.2.1'; syntax = Regexp::Syntax::Ruby::V221.new when 'ruby/2.2.2'; syntax = Regexp::Syntax::Ruby::V222.new when 'ruby/2.2.3'; syntax = Regexp::Syntax::Ruby::V223.new when 'ruby/2.2.4'; syntax = Regexp::Syntax::Ruby::V224.new # aliases for the latest 2.2 implementations when 'ruby/2.2'; syntax = Regexp::Syntax::Ruby::V22.new # Ruby 2.3.x when 'ruby/2.3.0'; syntax = Regexp::Syntax::Ruby::V230.new # alias for the latest 2.3 implementation when 'ruby/2.3'; syntax = Regexp::Syntax::Ruby::V23.new else raise UnknownSyntaxNameError.new(name) end end |
.load(name) ⇒ Object
Checks if the named syntax has a specification class file, and requires it if it does. Downcases names, and adds the .rb extension if omitted.
102 103 104 105 106 107 108 |
# File 'lib/regexp_parser/syntax.rb', line 102 def self.load(name) full = "#{SYNTAX_SPEC_ROOT}/#{name.downcase}" full = (full[-1, 3] == '.rb') ? full : "#{full}.rb" raise MissingSyntaxSpecError.new(name) unless File.exist?(full) require full end |
.new(name) ⇒ Object
Loads, and instantiates an instance of the syntax specification class for the given syntax flavor name. The special names βanyβ and β*β returns a instance of Syntax::Any. See below for more details.
34 35 36 37 38 39 40 |
# File 'lib/regexp_parser/syntax.rb', line 34 def self.new(name) return Regexp::Syntax::Any.new if ['*', 'any'].include?( name.to_s ) self.load(name) self.instantiate(name) end |