Class: Aurum::LexicalSpecification
- Inherits:
-
Object
- Object
- Aurum::LexicalSpecification
show all
- Defined in:
- lib/aurum/grammar.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#__create_pattern(action, *patterns) ⇒ Object
-
#__get_pattern(name) ⇒ Object
-
#cat(*patterns) ⇒ Object
-
#enum(literal) ⇒ Object
-
#ignore(*patterns) ⇒ Object
-
#initialize(definition = {:initial => {}}, state = :initial) ⇒ LexicalSpecification
constructor
A new instance of LexicalSpecification.
-
#match(*patterns, &action) ⇒ Object
-
#method_missing(name, *patterns, &action) ⇒ Object
-
#range(a, b) ⇒ Object
-
#recognize_and_shift_to(token, state, *patterns) ⇒ Object
-
#shift_to(state, *patterns, &config) ⇒ Object
-
#string(literal) ⇒ Object
-
#within(*states, &config) ⇒ Object
Constructor Details
#initialize(definition = {:initial => {}}, state = :initial) ⇒ LexicalSpecification
Returns a new instance of LexicalSpecification.
40
41
42
43
|
# File 'lib/aurum/grammar.rb', line 40
def initialize definition = {:initial => {}}, state = :initial
@definitions, @character_classes = definition, CharacterClassDefinition.new
@lexical_definition, @patterns = @definitions[state], {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *patterns, &action) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/aurum/grammar.rb', line 86
def method_missing name, *patterns, &action
return __get_pattern(name) if patterns.empty?
pattern = Pattern.concat *(patterns.collect {|x| x.kind_of?(Pattern) ? x : Pattern.from_string(x.to_s)})
@patterns[name] = pattern
if name.to_s =~ /^_/
recognize_action = RecognizeTokenAction.new(name.to_s)
recognize_action.action = action
@lexical_definition[pattern] = recognize_action
end
pattern
end
|
Instance Attribute Details
#character_classes ⇒ Object
Returns the value of attribute character_classes.
38
39
40
|
# File 'lib/aurum/grammar.rb', line 38
def character_classes
@character_classes
end
|
#definitions ⇒ Object
Returns the value of attribute definitions.
38
39
40
|
# File 'lib/aurum/grammar.rb', line 38
def definitions
@definitions
end
|
Instance Method Details
#__create_pattern(action, *patterns) ⇒ Object
103
104
105
106
107
|
# File 'lib/aurum/grammar.rb', line 103
def __create_pattern action, *patterns
pattern = Pattern.concat *(patterns.collect {|x| x.kind_of?(Pattern) ? x : Pattern.from_string(x.to_s)})
@lexical_definition[pattern] = action
pattern
end
|
#__get_pattern(name) ⇒ Object
98
99
100
101
|
# File 'lib/aurum/grammar.rb', line 98
def __get_pattern name
return @patterns[name] if @patterns.has_key? name
Pattern.from_char_set @character_classes.definitions[name]
end
|
#enum(literal) ⇒ Object
53
54
55
|
# File 'lib/aurum/grammar.rb', line 53
def enum literal
Pattern.from_enum literal
end
|
#ignore(*patterns) ⇒ Object
71
72
73
|
# File 'lib/aurum/grammar.rb', line 71
def ignore *patterns
__create_pattern IgnoreAction, *patterns
end
|
#match(*patterns, &action) ⇒ Object
67
68
69
|
# File 'lib/aurum/grammar.rb', line 67
def match *patterns, &action
__create_pattern UserDefinedAction.new(action), *patterns
end
|
#recognize_and_shift_to(token, state, *patterns) ⇒ Object
82
83
84
|
# File 'lib/aurum/grammar.rb', line 82
def recognize_and_shift_to token, state, *patterns
__create_pattern RecognizeTokenAndChangeStateAction.new(token.to_s, state), *patterns
end
|
#shift_to(state, *patterns, &config) ⇒ Object
61
62
63
64
65
|
# File 'lib/aurum/grammar.rb', line 61
def shift_to state, *patterns, &config
pattern = __create_pattern ChangeStateAction.new(state), *patterns
within state, &config if block_given?
pattern
end
|
#string(literal) ⇒ Object
49
50
51
|
# File 'lib/aurum/grammar.rb', line 49
def string literal
Pattern.from_string literal
end
|
#within(*states, &config) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/aurum/grammar.rb', line 75
def within *states, &config
for state in states
@definitions[state] = {} unless @definitions[state]
LexicalSpecification.new(@definitions, state).instance_eval &config
end
end
|