Class: Inform::Verb::Grammar
- Defined in:
- lib/story_teller/grammar_parser.rb
Overview
Grammars
Constant Summary collapse
- MultipleEnquotedPrepositionPattern =
%r{^'(.*)'/'(.*)'+$}.freeze
- SingleEnquotedPrepositionPattern =
%r{^'(.*)'$}.freeze
- CustomScopePattern =
%r{^(.*)=(.*)$}.freeze
- SpaceString =
' '.freeze
- Indention =
SpaceString * 4
- AsteriskString =
'*'.freeze
- ReverseString =
'reverse'.freeze
- ArrowString =
'->'.freeze
- GrammarTokenPadding =
40
Constants inherited from Array
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#expected_tokens ⇒ Object
readonly
Returns the value of attribute expected_tokens.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #expected_parameters ⇒ Object
-
#initialize(grammar, source, action, reverse = nil) ⇒ Grammar
constructor
A new instance of Grammar.
- #parameters ⇒ Object
- #reverse? ⇒ Boolean (also: #reversed?)
- #reversed_parameters ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Methods inherited from Array
#+, #average, #having, #identities, #longest_length, #pad, #plus_operator, #ruby_to_s, #sum, #to_sentence
Constructor Details
#initialize(grammar, source, action, reverse = nil) ⇒ Grammar
Returns a new instance of Grammar.
118 119 120 121 122 123 124 125 126 |
# File 'lib/story_teller/grammar_parser.rb', line 118 def initialize(grammar, source, action, reverse = nil) super() concat(symbolize_grammar(grammar)) unless grammar.empty? push(:end) @action = action @expected_tokens = grammar.map { |a| CustomScopePattern.match?(a) ? a.to_s.split('=').first.to_sym : a } @reverse = reverse.nil? ? false : reverse @source = source end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
116 117 118 |
# File 'lib/story_teller/grammar_parser.rb', line 116 def action @action end |
#expected_tokens ⇒ Object (readonly)
Returns the value of attribute expected_tokens.
116 117 118 |
# File 'lib/story_teller/grammar_parser.rb', line 116 def expected_tokens @expected_tokens end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
116 117 118 |
# File 'lib/story_teller/grammar_parser.rb', line 116 def source @source end |
Instance Method Details
#empty? ⇒ Boolean
128 129 130 |
# File 'lib/story_teller/grammar_parser.rb', line 128 def empty? length == (include?(:end) ? 1 : 0) end |
#expected_parameters ⇒ Object
159 160 161 |
# File 'lib/story_teller/grammar_parser.rb', line 159 def expected_parameters reverse? ? reversed_parameters : parameters end |
#parameters ⇒ Object
151 152 153 |
# File 'lib/story_teller/grammar_parser.rb', line 151 def parameters @parameters ||= [] end |
#reverse? ⇒ Boolean Also known as: reversed?
163 164 165 |
# File 'lib/story_teller/grammar_parser.rb', line 163 def reverse? @reverse end |
#reversed_parameters ⇒ Object
155 156 157 |
# File 'lib/story_teller/grammar_parser.rb', line 155 def reversed_parameters @reversed_parameters ||= [parameters[1], parameters[0]] + parameters[2..] end |
#to_s ⇒ Object Also known as: to_str
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/story_teller/grammar_parser.rb', line 139 def to_s Indention + AsteriskString + SpaceString + tokens_sans_end.ljust(GrammarTokenPadding) + ArrowString + SpaceString + action + if reverse? SpaceString + ReverseString else '' end end |