gift-parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+
2
+ doc/*
data/LICENCE ADDED
@@ -0,0 +1,23 @@
1
+ Licence for GIFT-Parser
2
+
3
+ The MIT Licence
4
+
5
+ Copyright (c) 2010 Stuart Coyle
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,18 @@
1
+ A Ruby parser for the GIFT question format.
2
+
3
+ GIFT is the format used by Moodle Learning Management System for writing multiple-choice, true-false, short answer, match missing word and numerical questions.
4
+ For details on the format see:
5
+ http://docs.moodle.org/en/GIFT
6
+
7
+ The parser is generated by Treetop parser generator.
8
+ http://treetop.rubyforge.org/
9
+
10
+ The parser is not yet complete. It generates the syntactic tree but does not
11
+ have all the semantic features as yet.
12
+
13
+ See the tests to get an idea on how the parser is supposed to be used.
14
+
15
+ See the file LICENCE for copyright details. (MIT license.)
16
+
17
+ Author:
18
+ Stuart Coyle 2010
@@ -0,0 +1,39 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "gift-parser"
5
+ gemspec.summary = "Moodle GIFT format parser"
6
+ gemspec.description = "A library for parsing the Moodle GIFT question format."
7
+ gemspec.email = "stuart.coyle@gmail.com"
8
+ gemspec.homepage = "http://github.com/stuart/gift-parser"
9
+ gemspec.authors = ["Stuart Coyle"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: gem install jeweler"
14
+ end
15
+
16
+ task :default => [:treetop, :test]
17
+
18
+ task :test do
19
+ # Run all the tests
20
+ Dir.glob("test/*_test.rb").each do |file|
21
+ require file
22
+ end
23
+ end
24
+
25
+ task :treetop do
26
+ # Generate the parser from the treetop source
27
+ print "Generating the parser..."
28
+ system("tt #{File.expand_path("../src/gift_parser.treetop", __FILE__)}" )
29
+ puts "done."
30
+ end
31
+
32
+ task :clean do
33
+ system( "rm -r #{File.expand_path("../doc/*", __FILE__)}")
34
+ system( "rm #{File.expand_path("../gift_parser.rb", __FILE__)}")
35
+ end
36
+
37
+ task :doc do
38
+ system("rdoc --exclude *parser.rb")
39
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in RakeFile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gift-parser}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Stuart Coyle"]
12
+ s.date = %q{2010-06-23}
13
+ s.description = %q{A library for parsing the Moodle GIFT question format.}
14
+ s.email = %q{stuart.coyle@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENCE",
21
+ "README",
22
+ "RakeFile",
23
+ "VERSION",
24
+ "gift-parser.gemspec",
25
+ "github.com",
26
+ "lib/gift.rb",
27
+ "lib/gift_parser.rb",
28
+ "src/gift_parser.treetop",
29
+ "test/GIFT-examples.rb",
30
+ "test/GIFT-examples.txt",
31
+ "test/gift_semantic_test.rb",
32
+ "test/gift_syntax_test.rb",
33
+ "test/gift_test.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/stuart/gift-parser}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Moodle GIFT format parser}
40
+ s.test_files = [
41
+ "test/GIFT-examples.rb",
42
+ "test/gift_semantic_test.rb",
43
+ "test/gift_syntax_test.rb",
44
+ "test/gift_test.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ else
53
+ end
54
+ else
55
+ end
56
+ end
57
+
File without changes
@@ -0,0 +1,267 @@
1
+ require 'treetop'
2
+ require File.expand_path('../gift_parser.rb', __FILE__)
3
+
4
+ module Gift
5
+
6
+ class Gift
7
+
8
+ attr_accessor :root
9
+
10
+ # Create a Gift object form a file IO or string.
11
+ #
12
+ def initialize(io_or_string)
13
+ parser = GiftParser.new()
14
+ case io_or_string
15
+ when String
16
+ # Add blank line to make sure we can parse.
17
+ @root = parser.parse(io_or_string + "\n\n")
18
+ when IO
19
+ @root = parser.parse(io_or_string.read + "\n\n")
20
+ end
21
+
22
+ raise ArgumentError, "Cannot parse GIFT input.\nReason:\n#{parser.failure_reason.inspect}" if @root.nil?
23
+ end
24
+
25
+ # An array of the questions from the Gift file.
26
+ def questions
27
+ @root.questions
28
+ end
29
+
30
+ end
31
+ # A representation of the questions in the gift format.
32
+ # The GIFT format is described in http://docs.moodle.org/en/GIFT
33
+ #
34
+ # This is an abstract class representing question types.
35
+ class Question < Treetop::Runtime::SyntaxNode
36
+
37
+ attr_accessor :category
38
+
39
+ def initialize(*args)
40
+ self.category = Command::category
41
+ super(*args)
42
+ end
43
+
44
+ # The set of possible answers for this question.
45
+ # Returns a array of hashes with contents depending on the subclass.
46
+ def answers
47
+ []
48
+ end
49
+
50
+ # The question text.
51
+ def text
52
+ question_text.text_value.strip
53
+ end
54
+
55
+ # The question title, defaults to the question text if no title is given.
56
+ def title
57
+ t = elements[1].text_value.gsub("::", "")
58
+ t.blank? ? self.text : t
59
+ end
60
+
61
+ # Any comment text before the question.
62
+ def comment
63
+ elements[0].text_value.gsub("//", "").rstrip
64
+ end
65
+
66
+ def markup
67
+ question_text.markup.text_value.gsub(/[\[\]]/, '')
68
+ end
69
+
70
+
71
+ # Returns the percentage value of the answer.
72
+ # Defaults to 100% if correct or 50% if wrong.
73
+ # Subclasses are expected to implement their own version of this function.
74
+ def mark_answer(response)
75
+ correct_answers.include?(response) ? 100 : 0
76
+ end
77
+
78
+ def correct_answers
79
+ answers.delete_if{|a| !a[:correct]}.map{|a| a[:value]}
80
+ end
81
+
82
+ end
83
+
84
+ # A question with no set answer. Used for requestion an essay.
85
+ # Gift example:
86
+ # <tt>Write 2000 words on parser generators{}</tt>
87
+ #
88
+ # Answer format: none.
89
+ class EssayQuestion < Question
90
+
91
+ end
92
+
93
+ # Purely a description or informative phrase.
94
+ # Gift example:
95
+ # <tt>This is a description only</tt>
96
+ #
97
+ # Answer format: none
98
+ class DescriptionQuestion < Question
99
+
100
+ end
101
+
102
+ # A question with a true or false boolean answer
103
+ # Gift examples:
104
+ # <tt>Is the sky blue?{T}</tt>
105
+ # <tt>Is the sky up?{TRUE}</tt>
106
+ # <tt>Is the sea made of stone?{FALSE#It's made of water.}</tt>
107
+ #
108
+ # Answer format:
109
+ # <tt>[{:value => true, :correct => true, :feedback => "Feedback string"}] </tt>
110
+ #
111
+ class TrueFalseQuestion < Question
112
+
113
+ def answers
114
+ [answer_list.answer]
115
+ end
116
+
117
+ def mark_answer(answer)
118
+ (answers[0][:value] == answer) ? 100 : 0
119
+ end
120
+ end
121
+
122
+ # A question with multiple choices avaialble
123
+ # Each choice may be given a weight and feedback string.
124
+ # Gift examples:
125
+ # <tt>// question: 1 name: Grants tomb
126
+ # ::Grants tomb::Who is buried in Grant's tomb in New York City? {
127
+ # =Grant
128
+ # ~No one
129
+ # #Was true for 12 years, but Grant's remains were buried in the tomb in 1897
130
+ # ~Napoleon
131
+ # #He was buried in France
132
+ # ~Churchill
133
+ # #He was buried in England
134
+ # ~Mother Teresa
135
+ # #She was buried in India
136
+ # }</tt>
137
+ #
138
+ # Answer format:
139
+ # <tt>[{:value => "Grant", :correct=> true, :feedback=> nil},
140
+ # {:value => "No one", :correct => false, :feedback => "Was true for 12 years, but Grant's remains were buried in the tomb in 1897"}] </tt>
141
+ class MultipleChoiceQuestion < Question
142
+
143
+ def answers
144
+ answer_list.elements.map{|e| e.answer}
145
+ end
146
+ end
147
+
148
+ # A question requiring a short written answer.
149
+ # Differentiated from multiple choice by not having and wrong answers
150
+ # i.e. answers prefixed with '~'
151
+ #
152
+ # An extension in this implementation is the ability to have weights to the short answers
153
+ # If all the answers have weights then it's treated as a multiple short answer question.
154
+ # Multiple short answer questions require several of the answers adding up to 100% to be present.
155
+ # For example: <tt>Name the three priamry colors{=%33.3%red =%33.3%blue =%33.3%yellow}</tt>
156
+ #
157
+ # Gift Example:
158
+ # <tt>Who's buried in Grant's tomb?{=Grant =Ulysses S. Grant =Ulysses Grant} </tt>
159
+ #
160
+ # Answer format:
161
+ # <tt>[{:feedback => nil, :value => "Grant", :correct => true},
162
+ # {:feedback => nil, :value => "Ulysses S. Grant", :correct => true},
163
+ # {:feedback => nil, :value => "Ulysses Grant" , :correct => true}] </tt>
164
+ #
165
+ class ShortAnswerQuestion < Question
166
+
167
+ def answers
168
+ answer_list.elements.map{ |e| e.answer}
169
+ end
170
+ end
171
+
172
+ # A question requiring a numeric answer
173
+ # Can have a tolerance or range or multiple answers with weights.
174
+ #
175
+ # Gift Examples:
176
+ # <tt>When was Ulysses S. Grant born? {#
177
+ # =1822:0
178
+ # =%50%1822:2
179
+ # }</tt>
180
+ #
181
+ # What is the value of pi (to 3 decimal places)? {#3.141..3.142}
182
+ #
183
+ # Answer format:
184
+ # [{:minimum => "1822", :maximum => "1822"}]
185
+ #
186
+ class NumericQuestion < Question
187
+
188
+ def answers
189
+ answer_list.elements.map{|e| e.answer}
190
+ end
191
+ end
192
+
193
+ # A questions where items have to be matched up one to one.
194
+ #
195
+ # Gift Example:
196
+ # <tt>Match the following countries with their corresponding capitals. {
197
+ # =Canada -> Ottawa
198
+ # =Italy -> Rome
199
+ # =Japan -> Tokyo
200
+ # =India -> New Delhi
201
+ # } </tt>
202
+ #
203
+ # Answer format:
204
+ # {'Canada' => 'Ottowa','Italy' => 'Rome'}</tt>
205
+ #
206
+ class MatchQuestion < Question
207
+ def answers
208
+ answer_list.elements.inject({}){ |ans, e| ans.merge e.answer}
209
+ end
210
+
211
+ def mark_answer(response)
212
+ response == answers ? 100 : 0
213
+ end
214
+
215
+ end
216
+
217
+ # A questions requiring a blank to be filled in.
218
+ # It is like the multiple choice but has text after the answers.
219
+ #
220
+ # The question text will have %% in it where the answer is to be placed.
221
+ #
222
+ # Gift example:
223
+ # <tt>The American holiday of Thanksgiving is celebrated on the {
224
+ # ~second
225
+ # ~third
226
+ # =fourth
227
+ # } Thursday of November.</tt>
228
+ #
229
+ # text: <tt>"The American holiday of Thanksgiving is celebrated on the %% Thursday of November"</tt>
230
+ #
231
+ # Answer format:
232
+ # <tt>[{:value => 'second', :correct => false}, {:value => 'third', :correct => false}, {:value => 'fourth', :correct => true}]
233
+ #
234
+ class FillInQuestion < Question
235
+ def text
236
+ question_text.text_value + "%%" + elements[9].text_value
237
+ end
238
+
239
+ def answers
240
+ answer_list.elements.map{|e| e.answer}
241
+ end
242
+ end
243
+
244
+ class Command < Treetop::Runtime::SyntaxNode
245
+ @@category = ""
246
+
247
+ def self.category
248
+ @@category
249
+ end
250
+
251
+ def self.category=(new_category)
252
+ @@category = new_category
253
+ end
254
+
255
+ def initialize(input, interval, elements)
256
+ if /^\$CATEGORY:.*/.match input[interval]
257
+ @@category = input[interval].gsub(/^\$CATEGORY:/, '').strip
258
+ end
259
+ super(input,interval,elements)
260
+ end
261
+
262
+ def command_text
263
+ elements[1].text_value
264
+ end
265
+
266
+ end
267
+ end
@@ -0,0 +1,3242 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ # Gift format treetop parser
5
+
6
+ #:nodoc: all
7
+ module Gift
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root || :gift
12
+ end
13
+
14
+ module Gift0
15
+ def question
16
+ elements[1]
17
+ end
18
+
19
+ def blank_line
20
+ elements[2]
21
+ end
22
+ end
23
+
24
+ module Gift1
25
+
26
+ @current_category
27
+
28
+ def questions
29
+ elements.map{|e| e.question}
30
+ end
31
+
32
+ def commands
33
+ elements.map{|e| e.elements[0].elements[0].command_text}
34
+ end
35
+ end
36
+
37
+ def _nt_gift
38
+ start_index = index
39
+ if node_cache[:gift].has_key?(index)
40
+ cached = node_cache[:gift][index]
41
+ @index = cached.interval.end if cached
42
+ return cached
43
+ end
44
+
45
+ s0, i0 = [], index
46
+ loop do
47
+ i1, s1 = index, []
48
+ s2, i2 = [], index
49
+ loop do
50
+ r3 = _nt_command
51
+ if r3
52
+ s2 << r3
53
+ else
54
+ break
55
+ end
56
+ end
57
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
58
+ s1 << r2
59
+ if r2
60
+ r4 = _nt_question
61
+ s1 << r4
62
+ if r4
63
+ r5 = _nt_blank_line
64
+ s1 << r5
65
+ end
66
+ end
67
+ if s1.last
68
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
69
+ r1.extend(Gift0)
70
+ else
71
+ @index = i1
72
+ r1 = nil
73
+ end
74
+ if r1
75
+ s0 << r1
76
+ else
77
+ break
78
+ end
79
+ end
80
+ if s0.empty?
81
+ @index = i0
82
+ r0 = nil
83
+ else
84
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
85
+ r0.extend(Gift1)
86
+ end
87
+
88
+ node_cache[:gift][start_index] = r0
89
+
90
+ r0
91
+ end
92
+
93
+ module Command0
94
+ end
95
+
96
+ module Command1
97
+ def line_break
98
+ elements[2]
99
+ end
100
+ end
101
+
102
+ def _nt_command
103
+ start_index = index
104
+ if node_cache[:command].has_key?(index)
105
+ cached = node_cache[:command][index]
106
+ @index = cached.interval.end if cached
107
+ return cached
108
+ end
109
+
110
+ i0, s0 = index, []
111
+ if has_terminal?('$', false, index)
112
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
113
+ @index += 1
114
+ else
115
+ terminal_parse_failure('$')
116
+ r1 = nil
117
+ end
118
+ s0 << r1
119
+ if r1
120
+ s2, i2 = [], index
121
+ loop do
122
+ i3, s3 = index, []
123
+ i4 = index
124
+ r5 = _nt_line_break
125
+ if r5
126
+ r4 = nil
127
+ else
128
+ @index = i4
129
+ r4 = instantiate_node(SyntaxNode,input, index...index)
130
+ end
131
+ s3 << r4
132
+ if r4
133
+ if index < input_length
134
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
135
+ @index += 1
136
+ else
137
+ terminal_parse_failure("any character")
138
+ r6 = nil
139
+ end
140
+ s3 << r6
141
+ end
142
+ if s3.last
143
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
144
+ r3.extend(Command0)
145
+ else
146
+ @index = i3
147
+ r3 = nil
148
+ end
149
+ if r3
150
+ s2 << r3
151
+ else
152
+ break
153
+ end
154
+ end
155
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
156
+ s0 << r2
157
+ if r2
158
+ r7 = _nt_line_break
159
+ s0 << r7
160
+ end
161
+ end
162
+ if s0.last
163
+ r0 = instantiate_node(Command,input, i0...index, s0)
164
+ r0.extend(Command1)
165
+ else
166
+ @index = i0
167
+ r0 = nil
168
+ end
169
+
170
+ node_cache[:command][start_index] = r0
171
+
172
+ r0
173
+ end
174
+
175
+ def _nt_question
176
+ start_index = index
177
+ if node_cache[:question].has_key?(index)
178
+ cached = node_cache[:question][index]
179
+ @index = cached.interval.end if cached
180
+ return cached
181
+ end
182
+
183
+ i0 = index
184
+ r1 = _nt_essay_question
185
+ if r1
186
+ r0 = r1
187
+ else
188
+ r2 = _nt_true_false_question
189
+ if r2
190
+ r0 = r2
191
+ else
192
+ r3 = _nt_match_question
193
+ if r3
194
+ r0 = r3
195
+ else
196
+ r4 = _nt_fill_in_question
197
+ if r4
198
+ r0 = r4
199
+ else
200
+ r5 = _nt_short_answer_question
201
+ if r5
202
+ r0 = r5
203
+ else
204
+ r6 = _nt_mutiple_choice_question
205
+ if r6
206
+ r0 = r6
207
+ else
208
+ r7 = _nt_numeric_question
209
+ if r7
210
+ r0 = r7
211
+ else
212
+ r8 = _nt_description_question
213
+ if r8
214
+ r0 = r8
215
+ else
216
+ @index = i0
217
+ r0 = nil
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+
227
+ node_cache[:question][start_index] = r0
228
+
229
+ r0
230
+ end
231
+
232
+ module EssayQuestion0
233
+ def question_text
234
+ elements[3]
235
+ end
236
+
237
+ end
238
+
239
+ def _nt_essay_question
240
+ start_index = index
241
+ if node_cache[:essay_question].has_key?(index)
242
+ cached = node_cache[:essay_question][index]
243
+ @index = cached.interval.end if cached
244
+ return cached
245
+ end
246
+
247
+ i0, s0 = index, []
248
+ r2 = _nt_comment
249
+ if r2
250
+ r1 = r2
251
+ else
252
+ r1 = instantiate_node(SyntaxNode,input, index...index)
253
+ end
254
+ s0 << r1
255
+ if r1
256
+ r4 = _nt_title
257
+ if r4
258
+ r3 = r4
259
+ else
260
+ r3 = instantiate_node(SyntaxNode,input, index...index)
261
+ end
262
+ s0 << r3
263
+ if r3
264
+ r6 = _nt_space
265
+ if r6
266
+ r5 = r6
267
+ else
268
+ r5 = instantiate_node(SyntaxNode,input, index...index)
269
+ end
270
+ s0 << r5
271
+ if r5
272
+ r7 = _nt_question_text
273
+ s0 << r7
274
+ if r7
275
+ if has_terminal?('{', false, index)
276
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
277
+ @index += 1
278
+ else
279
+ terminal_parse_failure('{')
280
+ r8 = nil
281
+ end
282
+ s0 << r8
283
+ if r8
284
+ r10 = _nt_nbsp
285
+ if r10
286
+ r9 = r10
287
+ else
288
+ r9 = instantiate_node(SyntaxNode,input, index...index)
289
+ end
290
+ s0 << r9
291
+ if r9
292
+ if has_terminal?('}', false, index)
293
+ r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
294
+ @index += 1
295
+ else
296
+ terminal_parse_failure('}')
297
+ r11 = nil
298
+ end
299
+ s0 << r11
300
+ end
301
+ end
302
+ end
303
+ end
304
+ end
305
+ end
306
+ if s0.last
307
+ r0 = instantiate_node(EssayQuestion,input, i0...index, s0)
308
+ r0.extend(EssayQuestion0)
309
+ else
310
+ @index = i0
311
+ r0 = nil
312
+ end
313
+
314
+ node_cache[:essay_question][start_index] = r0
315
+
316
+ r0
317
+ end
318
+
319
+ module TrueFalseQuestion0
320
+ def question_text
321
+ elements[3]
322
+ end
323
+
324
+ def answer_list
325
+ elements[6]
326
+ end
327
+
328
+ end
329
+
330
+ def _nt_true_false_question
331
+ start_index = index
332
+ if node_cache[:true_false_question].has_key?(index)
333
+ cached = node_cache[:true_false_question][index]
334
+ @index = cached.interval.end if cached
335
+ return cached
336
+ end
337
+
338
+ i0, s0 = index, []
339
+ r2 = _nt_comment
340
+ if r2
341
+ r1 = r2
342
+ else
343
+ r1 = instantiate_node(SyntaxNode,input, index...index)
344
+ end
345
+ s0 << r1
346
+ if r1
347
+ r4 = _nt_title
348
+ if r4
349
+ r3 = r4
350
+ else
351
+ r3 = instantiate_node(SyntaxNode,input, index...index)
352
+ end
353
+ s0 << r3
354
+ if r3
355
+ r6 = _nt_space
356
+ if r6
357
+ r5 = r6
358
+ else
359
+ r5 = instantiate_node(SyntaxNode,input, index...index)
360
+ end
361
+ s0 << r5
362
+ if r5
363
+ r7 = _nt_question_text
364
+ s0 << r7
365
+ if r7
366
+ if has_terminal?('{', false, index)
367
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
368
+ @index += 1
369
+ else
370
+ terminal_parse_failure('{')
371
+ r8 = nil
372
+ end
373
+ s0 << r8
374
+ if r8
375
+ r10 = _nt_space
376
+ if r10
377
+ r9 = r10
378
+ else
379
+ r9 = instantiate_node(SyntaxNode,input, index...index)
380
+ end
381
+ s0 << r9
382
+ if r9
383
+ i11 = index
384
+ r12 = _nt_true_answer
385
+ if r12
386
+ r11 = r12
387
+ else
388
+ r13 = _nt_false_answer
389
+ if r13
390
+ r11 = r13
391
+ else
392
+ @index = i11
393
+ r11 = nil
394
+ end
395
+ end
396
+ s0 << r11
397
+ if r11
398
+ r15 = _nt_space
399
+ if r15
400
+ r14 = r15
401
+ else
402
+ r14 = instantiate_node(SyntaxNode,input, index...index)
403
+ end
404
+ s0 << r14
405
+ if r14
406
+ if has_terminal?('}', false, index)
407
+ r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
408
+ @index += 1
409
+ else
410
+ terminal_parse_failure('}')
411
+ r16 = nil
412
+ end
413
+ s0 << r16
414
+ end
415
+ end
416
+ end
417
+ end
418
+ end
419
+ end
420
+ end
421
+ end
422
+ if s0.last
423
+ r0 = instantiate_node(TrueFalseQuestion,input, i0...index, s0)
424
+ r0.extend(TrueFalseQuestion0)
425
+ else
426
+ @index = i0
427
+ r0 = nil
428
+ end
429
+
430
+ node_cache[:true_false_question][start_index] = r0
431
+
432
+ r0
433
+ end
434
+
435
+ module ShortAnswerQuestion0
436
+ def question_text
437
+ elements[3]
438
+ end
439
+
440
+ def answer_list
441
+ elements[6]
442
+ end
443
+
444
+ end
445
+
446
+ def _nt_short_answer_question
447
+ start_index = index
448
+ if node_cache[:short_answer_question].has_key?(index)
449
+ cached = node_cache[:short_answer_question][index]
450
+ @index = cached.interval.end if cached
451
+ return cached
452
+ end
453
+
454
+ i0, s0 = index, []
455
+ r2 = _nt_comment
456
+ if r2
457
+ r1 = r2
458
+ else
459
+ r1 = instantiate_node(SyntaxNode,input, index...index)
460
+ end
461
+ s0 << r1
462
+ if r1
463
+ r4 = _nt_title
464
+ if r4
465
+ r3 = r4
466
+ else
467
+ r3 = instantiate_node(SyntaxNode,input, index...index)
468
+ end
469
+ s0 << r3
470
+ if r3
471
+ r6 = _nt_space
472
+ if r6
473
+ r5 = r6
474
+ else
475
+ r5 = instantiate_node(SyntaxNode,input, index...index)
476
+ end
477
+ s0 << r5
478
+ if r5
479
+ r7 = _nt_question_text
480
+ s0 << r7
481
+ if r7
482
+ if has_terminal?('{', false, index)
483
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
484
+ @index += 1
485
+ else
486
+ terminal_parse_failure('{')
487
+ r8 = nil
488
+ end
489
+ s0 << r8
490
+ if r8
491
+ r10 = _nt_space
492
+ if r10
493
+ r9 = r10
494
+ else
495
+ r9 = instantiate_node(SyntaxNode,input, index...index)
496
+ end
497
+ s0 << r9
498
+ if r9
499
+ s11, i11 = [], index
500
+ loop do
501
+ r12 = _nt_right_answer
502
+ if r12
503
+ s11 << r12
504
+ else
505
+ break
506
+ end
507
+ end
508
+ if s11.empty?
509
+ @index = i11
510
+ r11 = nil
511
+ else
512
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
513
+ end
514
+ s0 << r11
515
+ if r11
516
+ r14 = _nt_space
517
+ if r14
518
+ r13 = r14
519
+ else
520
+ r13 = instantiate_node(SyntaxNode,input, index...index)
521
+ end
522
+ s0 << r13
523
+ if r13
524
+ if has_terminal?('}', false, index)
525
+ r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
526
+ @index += 1
527
+ else
528
+ terminal_parse_failure('}')
529
+ r15 = nil
530
+ end
531
+ s0 << r15
532
+ end
533
+ end
534
+ end
535
+ end
536
+ end
537
+ end
538
+ end
539
+ end
540
+ if s0.last
541
+ r0 = instantiate_node(ShortAnswerQuestion,input, i0...index, s0)
542
+ r0.extend(ShortAnswerQuestion0)
543
+ else
544
+ @index = i0
545
+ r0 = nil
546
+ end
547
+
548
+ node_cache[:short_answer_question][start_index] = r0
549
+
550
+ r0
551
+ end
552
+
553
+ module MutipleChoiceQuestion0
554
+ def question_text
555
+ elements[3]
556
+ end
557
+
558
+ def answer_list
559
+ elements[6]
560
+ end
561
+
562
+ end
563
+
564
+ def _nt_mutiple_choice_question
565
+ start_index = index
566
+ if node_cache[:mutiple_choice_question].has_key?(index)
567
+ cached = node_cache[:mutiple_choice_question][index]
568
+ @index = cached.interval.end if cached
569
+ return cached
570
+ end
571
+
572
+ i0, s0 = index, []
573
+ r2 = _nt_comment
574
+ if r2
575
+ r1 = r2
576
+ else
577
+ r1 = instantiate_node(SyntaxNode,input, index...index)
578
+ end
579
+ s0 << r1
580
+ if r1
581
+ r4 = _nt_title
582
+ if r4
583
+ r3 = r4
584
+ else
585
+ r3 = instantiate_node(SyntaxNode,input, index...index)
586
+ end
587
+ s0 << r3
588
+ if r3
589
+ r6 = _nt_space
590
+ if r6
591
+ r5 = r6
592
+ else
593
+ r5 = instantiate_node(SyntaxNode,input, index...index)
594
+ end
595
+ s0 << r5
596
+ if r5
597
+ r7 = _nt_question_text
598
+ s0 << r7
599
+ if r7
600
+ if has_terminal?('{', false, index)
601
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
602
+ @index += 1
603
+ else
604
+ terminal_parse_failure('{')
605
+ r8 = nil
606
+ end
607
+ s0 << r8
608
+ if r8
609
+ r10 = _nt_space
610
+ if r10
611
+ r9 = r10
612
+ else
613
+ r9 = instantiate_node(SyntaxNode,input, index...index)
614
+ end
615
+ s0 << r9
616
+ if r9
617
+ s11, i11 = [], index
618
+ loop do
619
+ i12 = index
620
+ r13 = _nt_wrong_answer
621
+ if r13
622
+ r12 = r13
623
+ else
624
+ r14 = _nt_right_answer
625
+ if r14
626
+ r12 = r14
627
+ else
628
+ @index = i12
629
+ r12 = nil
630
+ end
631
+ end
632
+ if r12
633
+ s11 << r12
634
+ else
635
+ break
636
+ end
637
+ end
638
+ if s11.empty?
639
+ @index = i11
640
+ r11 = nil
641
+ else
642
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
643
+ end
644
+ s0 << r11
645
+ if r11
646
+ r16 = _nt_space
647
+ if r16
648
+ r15 = r16
649
+ else
650
+ r15 = instantiate_node(SyntaxNode,input, index...index)
651
+ end
652
+ s0 << r15
653
+ if r15
654
+ if has_terminal?('}', false, index)
655
+ r17 = instantiate_node(SyntaxNode,input, index...(index + 1))
656
+ @index += 1
657
+ else
658
+ terminal_parse_failure('}')
659
+ r17 = nil
660
+ end
661
+ s0 << r17
662
+ end
663
+ end
664
+ end
665
+ end
666
+ end
667
+ end
668
+ end
669
+ end
670
+ if s0.last
671
+ r0 = instantiate_node(MultipleChoiceQuestion,input, i0...index, s0)
672
+ r0.extend(MutipleChoiceQuestion0)
673
+ else
674
+ @index = i0
675
+ r0 = nil
676
+ end
677
+
678
+ node_cache[:mutiple_choice_question][start_index] = r0
679
+
680
+ r0
681
+ end
682
+
683
+ module NumericQuestion0
684
+ def question_text
685
+ elements[3]
686
+ end
687
+
688
+ def answer_list
689
+ elements[6]
690
+ end
691
+
692
+ end
693
+
694
+ def _nt_numeric_question
695
+ start_index = index
696
+ if node_cache[:numeric_question].has_key?(index)
697
+ cached = node_cache[:numeric_question][index]
698
+ @index = cached.interval.end if cached
699
+ return cached
700
+ end
701
+
702
+ i0, s0 = index, []
703
+ r2 = _nt_comment
704
+ if r2
705
+ r1 = r2
706
+ else
707
+ r1 = instantiate_node(SyntaxNode,input, index...index)
708
+ end
709
+ s0 << r1
710
+ if r1
711
+ r4 = _nt_title
712
+ if r4
713
+ r3 = r4
714
+ else
715
+ r3 = instantiate_node(SyntaxNode,input, index...index)
716
+ end
717
+ s0 << r3
718
+ if r3
719
+ r6 = _nt_space
720
+ if r6
721
+ r5 = r6
722
+ else
723
+ r5 = instantiate_node(SyntaxNode,input, index...index)
724
+ end
725
+ s0 << r5
726
+ if r5
727
+ r7 = _nt_question_text
728
+ s0 << r7
729
+ if r7
730
+ if has_terminal?('{#', false, index)
731
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 2))
732
+ @index += 2
733
+ else
734
+ terminal_parse_failure('{#')
735
+ r8 = nil
736
+ end
737
+ s0 << r8
738
+ if r8
739
+ r10 = _nt_space
740
+ if r10
741
+ r9 = r10
742
+ else
743
+ r9 = instantiate_node(SyntaxNode,input, index...index)
744
+ end
745
+ s0 << r9
746
+ if r9
747
+ s11, i11 = [], index
748
+ loop do
749
+ r12 = _nt_numeric_answer
750
+ if r12
751
+ s11 << r12
752
+ else
753
+ break
754
+ end
755
+ end
756
+ if s11.empty?
757
+ @index = i11
758
+ r11 = nil
759
+ else
760
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
761
+ end
762
+ s0 << r11
763
+ if r11
764
+ if has_terminal?('}', false, index)
765
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
766
+ @index += 1
767
+ else
768
+ terminal_parse_failure('}')
769
+ r13 = nil
770
+ end
771
+ s0 << r13
772
+ end
773
+ end
774
+ end
775
+ end
776
+ end
777
+ end
778
+ end
779
+ if s0.last
780
+ r0 = instantiate_node(NumericQuestion,input, i0...index, s0)
781
+ r0.extend(NumericQuestion0)
782
+ else
783
+ @index = i0
784
+ r0 = nil
785
+ end
786
+
787
+ node_cache[:numeric_question][start_index] = r0
788
+
789
+ r0
790
+ end
791
+
792
+ module MatchQuestion0
793
+ def question_text
794
+ elements[3]
795
+ end
796
+
797
+ def answer_list
798
+ elements[6]
799
+ end
800
+
801
+ end
802
+
803
+ def _nt_match_question
804
+ start_index = index
805
+ if node_cache[:match_question].has_key?(index)
806
+ cached = node_cache[:match_question][index]
807
+ @index = cached.interval.end if cached
808
+ return cached
809
+ end
810
+
811
+ i0, s0 = index, []
812
+ r2 = _nt_comment
813
+ if r2
814
+ r1 = r2
815
+ else
816
+ r1 = instantiate_node(SyntaxNode,input, index...index)
817
+ end
818
+ s0 << r1
819
+ if r1
820
+ r4 = _nt_title
821
+ if r4
822
+ r3 = r4
823
+ else
824
+ r3 = instantiate_node(SyntaxNode,input, index...index)
825
+ end
826
+ s0 << r3
827
+ if r3
828
+ r6 = _nt_space
829
+ if r6
830
+ r5 = r6
831
+ else
832
+ r5 = instantiate_node(SyntaxNode,input, index...index)
833
+ end
834
+ s0 << r5
835
+ if r5
836
+ r7 = _nt_question_text
837
+ s0 << r7
838
+ if r7
839
+ if has_terminal?('{', false, index)
840
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
841
+ @index += 1
842
+ else
843
+ terminal_parse_failure('{')
844
+ r8 = nil
845
+ end
846
+ s0 << r8
847
+ if r8
848
+ r10 = _nt_space
849
+ if r10
850
+ r9 = r10
851
+ else
852
+ r9 = instantiate_node(SyntaxNode,input, index...index)
853
+ end
854
+ s0 << r9
855
+ if r9
856
+ s11, i11 = [], index
857
+ loop do
858
+ r12 = _nt_match_answer
859
+ if r12
860
+ s11 << r12
861
+ else
862
+ break
863
+ end
864
+ end
865
+ if s11.empty?
866
+ @index = i11
867
+ r11 = nil
868
+ else
869
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
870
+ end
871
+ s0 << r11
872
+ if r11
873
+ if has_terminal?('}', false, index)
874
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
875
+ @index += 1
876
+ else
877
+ terminal_parse_failure('}')
878
+ r13 = nil
879
+ end
880
+ s0 << r13
881
+ end
882
+ end
883
+ end
884
+ end
885
+ end
886
+ end
887
+ end
888
+ if s0.last
889
+ r0 = instantiate_node(MatchQuestion,input, i0...index, s0)
890
+ r0.extend(MatchQuestion0)
891
+ else
892
+ @index = i0
893
+ r0 = nil
894
+ end
895
+
896
+ node_cache[:match_question][start_index] = r0
897
+
898
+ r0
899
+ end
900
+
901
+ module FillInQuestion0
902
+ end
903
+
904
+ module FillInQuestion1
905
+ end
906
+
907
+ module FillInQuestion2
908
+ def question_text
909
+ elements[3]
910
+ end
911
+
912
+ def answer_list
913
+ elements[6]
914
+ end
915
+
916
+ end
917
+
918
+ def _nt_fill_in_question
919
+ start_index = index
920
+ if node_cache[:fill_in_question].has_key?(index)
921
+ cached = node_cache[:fill_in_question][index]
922
+ @index = cached.interval.end if cached
923
+ return cached
924
+ end
925
+
926
+ i0, s0 = index, []
927
+ r2 = _nt_comment
928
+ if r2
929
+ r1 = r2
930
+ else
931
+ r1 = instantiate_node(SyntaxNode,input, index...index)
932
+ end
933
+ s0 << r1
934
+ if r1
935
+ r4 = _nt_title
936
+ if r4
937
+ r3 = r4
938
+ else
939
+ r3 = instantiate_node(SyntaxNode,input, index...index)
940
+ end
941
+ s0 << r3
942
+ if r3
943
+ r6 = _nt_space
944
+ if r6
945
+ r5 = r6
946
+ else
947
+ r5 = instantiate_node(SyntaxNode,input, index...index)
948
+ end
949
+ s0 << r5
950
+ if r5
951
+ r7 = _nt_question_text
952
+ s0 << r7
953
+ if r7
954
+ if has_terminal?('{', false, index)
955
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
956
+ @index += 1
957
+ else
958
+ terminal_parse_failure('{')
959
+ r8 = nil
960
+ end
961
+ s0 << r8
962
+ if r8
963
+ r10 = _nt_space
964
+ if r10
965
+ r9 = r10
966
+ else
967
+ r9 = instantiate_node(SyntaxNode,input, index...index)
968
+ end
969
+ s0 << r9
970
+ if r9
971
+ s11, i11 = [], index
972
+ loop do
973
+ i12 = index
974
+ r13 = _nt_wrong_answer
975
+ if r13
976
+ r12 = r13
977
+ else
978
+ r14 = _nt_right_answer
979
+ if r14
980
+ r12 = r14
981
+ else
982
+ @index = i12
983
+ r12 = nil
984
+ end
985
+ end
986
+ if r12
987
+ s11 << r12
988
+ else
989
+ break
990
+ end
991
+ end
992
+ if s11.empty?
993
+ @index = i11
994
+ r11 = nil
995
+ else
996
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
997
+ end
998
+ s0 << r11
999
+ if r11
1000
+ r16 = _nt_space
1001
+ if r16
1002
+ r15 = r16
1003
+ else
1004
+ r15 = instantiate_node(SyntaxNode,input, index...index)
1005
+ end
1006
+ s0 << r15
1007
+ if r15
1008
+ if has_terminal?('}', false, index)
1009
+ r17 = instantiate_node(SyntaxNode,input, index...(index + 1))
1010
+ @index += 1
1011
+ else
1012
+ terminal_parse_failure('}')
1013
+ r17 = nil
1014
+ end
1015
+ s0 << r17
1016
+ if r17
1017
+ s18, i18 = [], index
1018
+ loop do
1019
+ i19, s19 = index, []
1020
+ i20 = index
1021
+ if has_terminal?('\G[\\r\\n]', true, index)
1022
+ r21 = true
1023
+ @index += 1
1024
+ else
1025
+ r21 = nil
1026
+ end
1027
+ if r21
1028
+ r20 = nil
1029
+ else
1030
+ @index = i20
1031
+ r20 = instantiate_node(SyntaxNode,input, index...index)
1032
+ end
1033
+ s19 << r20
1034
+ if r20
1035
+ i22 = index
1036
+ i23, s23 = index, []
1037
+ if has_terminal?("\\", false, index)
1038
+ r24 = instantiate_node(SyntaxNode,input, index...(index + 1))
1039
+ @index += 1
1040
+ else
1041
+ terminal_parse_failure("\\")
1042
+ r24 = nil
1043
+ end
1044
+ s23 << r24
1045
+ if r24
1046
+ if has_terminal?('\G[=~{}#:]', true, index)
1047
+ r25 = true
1048
+ @index += 1
1049
+ else
1050
+ r25 = nil
1051
+ end
1052
+ s23 << r25
1053
+ end
1054
+ if s23.last
1055
+ r23 = instantiate_node(SyntaxNode,input, i23...index, s23)
1056
+ r23.extend(FillInQuestion0)
1057
+ else
1058
+ @index = i23
1059
+ r23 = nil
1060
+ end
1061
+ if r23
1062
+ r22 = r23
1063
+ else
1064
+ if index < input_length
1065
+ r26 = instantiate_node(SyntaxNode,input, index...(index + 1))
1066
+ @index += 1
1067
+ else
1068
+ terminal_parse_failure("any character")
1069
+ r26 = nil
1070
+ end
1071
+ if r26
1072
+ r22 = r26
1073
+ else
1074
+ @index = i22
1075
+ r22 = nil
1076
+ end
1077
+ end
1078
+ s19 << r22
1079
+ end
1080
+ if s19.last
1081
+ r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
1082
+ r19.extend(FillInQuestion1)
1083
+ else
1084
+ @index = i19
1085
+ r19 = nil
1086
+ end
1087
+ if r19
1088
+ s18 << r19
1089
+ else
1090
+ break
1091
+ end
1092
+ end
1093
+ if s18.empty?
1094
+ @index = i18
1095
+ r18 = nil
1096
+ else
1097
+ r18 = instantiate_node(SyntaxNode,input, i18...index, s18)
1098
+ end
1099
+ s0 << r18
1100
+ end
1101
+ end
1102
+ end
1103
+ end
1104
+ end
1105
+ end
1106
+ end
1107
+ end
1108
+ end
1109
+ if s0.last
1110
+ r0 = instantiate_node(FillInQuestion,input, i0...index, s0)
1111
+ r0.extend(FillInQuestion2)
1112
+ else
1113
+ @index = i0
1114
+ r0 = nil
1115
+ end
1116
+
1117
+ node_cache[:fill_in_question][start_index] = r0
1118
+
1119
+ r0
1120
+ end
1121
+
1122
+ module DescriptionQuestion0
1123
+ def question_text
1124
+ elements[3]
1125
+ end
1126
+ end
1127
+
1128
+ def _nt_description_question
1129
+ start_index = index
1130
+ if node_cache[:description_question].has_key?(index)
1131
+ cached = node_cache[:description_question][index]
1132
+ @index = cached.interval.end if cached
1133
+ return cached
1134
+ end
1135
+
1136
+ i0, s0 = index, []
1137
+ r2 = _nt_comment
1138
+ if r2
1139
+ r1 = r2
1140
+ else
1141
+ r1 = instantiate_node(SyntaxNode,input, index...index)
1142
+ end
1143
+ s0 << r1
1144
+ if r1
1145
+ r4 = _nt_title
1146
+ if r4
1147
+ r3 = r4
1148
+ else
1149
+ r3 = instantiate_node(SyntaxNode,input, index...index)
1150
+ end
1151
+ s0 << r3
1152
+ if r3
1153
+ r6 = _nt_space
1154
+ if r6
1155
+ r5 = r6
1156
+ else
1157
+ r5 = instantiate_node(SyntaxNode,input, index...index)
1158
+ end
1159
+ s0 << r5
1160
+ if r5
1161
+ r7 = _nt_question_text
1162
+ s0 << r7
1163
+ end
1164
+ end
1165
+ end
1166
+ if s0.last
1167
+ r0 = instantiate_node(DescriptionQuestion,input, i0...index, s0)
1168
+ r0.extend(DescriptionQuestion0)
1169
+ else
1170
+ @index = i0
1171
+ r0 = nil
1172
+ end
1173
+
1174
+ node_cache[:description_question][start_index] = r0
1175
+
1176
+ r0
1177
+ end
1178
+
1179
+ module Number0
1180
+ end
1181
+
1182
+ module Number1
1183
+ end
1184
+
1185
+ def _nt_number
1186
+ start_index = index
1187
+ if node_cache[:number].has_key?(index)
1188
+ cached = node_cache[:number][index]
1189
+ @index = cached.interval.end if cached
1190
+ return cached
1191
+ end
1192
+
1193
+ i0, s0 = index, []
1194
+ if has_terminal?('\G[+-]', true, index)
1195
+ r2 = true
1196
+ @index += 1
1197
+ else
1198
+ r2 = nil
1199
+ end
1200
+ if r2
1201
+ r1 = r2
1202
+ else
1203
+ r1 = instantiate_node(SyntaxNode,input, index...index)
1204
+ end
1205
+ s0 << r1
1206
+ if r1
1207
+ s3, i3 = [], index
1208
+ loop do
1209
+ if has_terminal?('\G[\\d]', true, index)
1210
+ r4 = true
1211
+ @index += 1
1212
+ else
1213
+ r4 = nil
1214
+ end
1215
+ if r4
1216
+ s3 << r4
1217
+ else
1218
+ break
1219
+ end
1220
+ end
1221
+ if s3.empty?
1222
+ @index = i3
1223
+ r3 = nil
1224
+ else
1225
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
1226
+ end
1227
+ s0 << r3
1228
+ if r3
1229
+ i6, s6 = index, []
1230
+ i7 = index
1231
+ if has_terminal?("..", false, index)
1232
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 2))
1233
+ @index += 2
1234
+ else
1235
+ terminal_parse_failure("..")
1236
+ r8 = nil
1237
+ end
1238
+ if r8
1239
+ r7 = nil
1240
+ else
1241
+ @index = i7
1242
+ r7 = instantiate_node(SyntaxNode,input, index...index)
1243
+ end
1244
+ s6 << r7
1245
+ if r7
1246
+ if has_terminal?(".", false, index)
1247
+ r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
1248
+ @index += 1
1249
+ else
1250
+ terminal_parse_failure(".")
1251
+ r9 = nil
1252
+ end
1253
+ s6 << r9
1254
+ if r9
1255
+ s10, i10 = [], index
1256
+ loop do
1257
+ if has_terminal?('\G[\\d]', true, index)
1258
+ r11 = true
1259
+ @index += 1
1260
+ else
1261
+ r11 = nil
1262
+ end
1263
+ if r11
1264
+ s10 << r11
1265
+ else
1266
+ break
1267
+ end
1268
+ end
1269
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1270
+ s6 << r10
1271
+ end
1272
+ end
1273
+ if s6.last
1274
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
1275
+ r6.extend(Number0)
1276
+ else
1277
+ @index = i6
1278
+ r6 = nil
1279
+ end
1280
+ if r6
1281
+ r5 = r6
1282
+ else
1283
+ r5 = instantiate_node(SyntaxNode,input, index...index)
1284
+ end
1285
+ s0 << r5
1286
+ end
1287
+ end
1288
+ if s0.last
1289
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1290
+ r0.extend(Number1)
1291
+ else
1292
+ @index = i0
1293
+ r0 = nil
1294
+ end
1295
+
1296
+ node_cache[:number][start_index] = r0
1297
+
1298
+ r0
1299
+ end
1300
+
1301
+ module Weight0
1302
+ end
1303
+
1304
+ def _nt_weight
1305
+ start_index = index
1306
+ if node_cache[:weight].has_key?(index)
1307
+ cached = node_cache[:weight][index]
1308
+ @index = cached.interval.end if cached
1309
+ return cached
1310
+ end
1311
+
1312
+ i0, s0 = index, []
1313
+ if has_terminal?("%", false, index)
1314
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
1315
+ @index += 1
1316
+ else
1317
+ terminal_parse_failure("%")
1318
+ r1 = nil
1319
+ end
1320
+ s0 << r1
1321
+ if r1
1322
+ if has_terminal?('\G[+-]', true, index)
1323
+ r3 = true
1324
+ @index += 1
1325
+ else
1326
+ r3 = nil
1327
+ end
1328
+ if r3
1329
+ r2 = r3
1330
+ else
1331
+ r2 = instantiate_node(SyntaxNode,input, index...index)
1332
+ end
1333
+ s0 << r2
1334
+ if r2
1335
+ if has_terminal?('\G[1]', true, index)
1336
+ r5 = true
1337
+ @index += 1
1338
+ else
1339
+ r5 = nil
1340
+ end
1341
+ if r5
1342
+ r4 = r5
1343
+ else
1344
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1345
+ end
1346
+ s0 << r4
1347
+ if r4
1348
+ if has_terminal?('\G[\\d]', true, index)
1349
+ r7 = true
1350
+ @index += 1
1351
+ else
1352
+ r7 = nil
1353
+ end
1354
+ if r7
1355
+ r6 = r7
1356
+ else
1357
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1358
+ end
1359
+ s0 << r6
1360
+ if r6
1361
+ if has_terminal?('\G[\\d]', true, index)
1362
+ r8 = true
1363
+ @index += 1
1364
+ else
1365
+ r8 = nil
1366
+ end
1367
+ s0 << r8
1368
+ if r8
1369
+ if has_terminal?(".", false, index)
1370
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
1371
+ @index += 1
1372
+ else
1373
+ terminal_parse_failure(".")
1374
+ r10 = nil
1375
+ end
1376
+ if r10
1377
+ r9 = r10
1378
+ else
1379
+ r9 = instantiate_node(SyntaxNode,input, index...index)
1380
+ end
1381
+ s0 << r9
1382
+ if r9
1383
+ if has_terminal?('\G[\\d]', true, index)
1384
+ r12 = true
1385
+ @index += 1
1386
+ else
1387
+ r12 = nil
1388
+ end
1389
+ if r12
1390
+ r11 = r12
1391
+ else
1392
+ r11 = instantiate_node(SyntaxNode,input, index...index)
1393
+ end
1394
+ s0 << r11
1395
+ if r11
1396
+ if has_terminal?('\G[\\d]', true, index)
1397
+ r14 = true
1398
+ @index += 1
1399
+ else
1400
+ r14 = nil
1401
+ end
1402
+ if r14
1403
+ r13 = r14
1404
+ else
1405
+ r13 = instantiate_node(SyntaxNode,input, index...index)
1406
+ end
1407
+ s0 << r13
1408
+ if r13
1409
+ if has_terminal?("%", false, index)
1410
+ r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
1411
+ @index += 1
1412
+ else
1413
+ terminal_parse_failure("%")
1414
+ r15 = nil
1415
+ end
1416
+ s0 << r15
1417
+ end
1418
+ end
1419
+ end
1420
+ end
1421
+ end
1422
+ end
1423
+ end
1424
+ end
1425
+ if s0.last
1426
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1427
+ r0.extend(Weight0)
1428
+ else
1429
+ @index = i0
1430
+ r0 = nil
1431
+ end
1432
+
1433
+ node_cache[:weight][start_index] = r0
1434
+
1435
+ r0
1436
+ end
1437
+
1438
+ module NumericAnswer0
1439
+ def value
1440
+ elements[0]
1441
+ end
1442
+
1443
+ end
1444
+
1445
+ module NumericAnswer1
1446
+ def answer
1447
+ {:maximum => value.maximum, :minimum => value.minimum}
1448
+ end
1449
+ end
1450
+
1451
+ def _nt_numeric_answer
1452
+ start_index = index
1453
+ if node_cache[:numeric_answer].has_key?(index)
1454
+ cached = node_cache[:numeric_answer][index]
1455
+ @index = cached.interval.end if cached
1456
+ return cached
1457
+ end
1458
+
1459
+ i0, s0 = index, []
1460
+ i1 = index
1461
+ r2 = _nt_range
1462
+ if r2
1463
+ r1 = r2
1464
+ else
1465
+ r3 = _nt_numeric_with_tolerance
1466
+ if r3
1467
+ r1 = r3
1468
+ else
1469
+ @index = i1
1470
+ r1 = nil
1471
+ end
1472
+ end
1473
+ s0 << r1
1474
+ if r1
1475
+ r5 = _nt_space
1476
+ if r5
1477
+ r4 = r5
1478
+ else
1479
+ r4 = instantiate_node(SyntaxNode,input, index...index)
1480
+ end
1481
+ s0 << r4
1482
+ if r4
1483
+ r7 = _nt_feedback
1484
+ if r7
1485
+ r6 = r7
1486
+ else
1487
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1488
+ end
1489
+ s0 << r6
1490
+ if r6
1491
+ r9 = _nt_space
1492
+ if r9
1493
+ r8 = r9
1494
+ else
1495
+ r8 = instantiate_node(SyntaxNode,input, index...index)
1496
+ end
1497
+ s0 << r8
1498
+ end
1499
+ end
1500
+ end
1501
+ if s0.last
1502
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1503
+ r0.extend(NumericAnswer0)
1504
+ r0.extend(NumericAnswer1)
1505
+ else
1506
+ @index = i0
1507
+ r0 = nil
1508
+ end
1509
+
1510
+ node_cache[:numeric_answer][start_index] = r0
1511
+
1512
+ r0
1513
+ end
1514
+
1515
+ module NumericWithTolerance0
1516
+ def number
1517
+ elements[1]
1518
+ end
1519
+ end
1520
+
1521
+ module NumericWithTolerance1
1522
+ def number
1523
+ elements[2]
1524
+ end
1525
+
1526
+ end
1527
+
1528
+ module NumericWithTolerance2
1529
+ def maximum
1530
+ ans = Float(elements[2].text_value)
1531
+ ans += Float(elements[3].elements[1].text_value) unless elements[3].text_value.blank?
1532
+ return ans
1533
+ end
1534
+
1535
+ def minimum
1536
+ ans = Float(elements[2].text_value)
1537
+ ans -= Float(elements[3].elements[1].text_value) unless elements[3].text_value.blank?
1538
+ return ans
1539
+ end
1540
+ end
1541
+
1542
+ def _nt_numeric_with_tolerance
1543
+ start_index = index
1544
+ if node_cache[:numeric_with_tolerance].has_key?(index)
1545
+ cached = node_cache[:numeric_with_tolerance][index]
1546
+ @index = cached.interval.end if cached
1547
+ return cached
1548
+ end
1549
+
1550
+ i0, s0 = index, []
1551
+ if has_terminal?("=", false, index)
1552
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
1553
+ @index += 1
1554
+ else
1555
+ terminal_parse_failure("=")
1556
+ r2 = nil
1557
+ end
1558
+ if r2
1559
+ r1 = r2
1560
+ else
1561
+ r1 = instantiate_node(SyntaxNode,input, index...index)
1562
+ end
1563
+ s0 << r1
1564
+ if r1
1565
+ r4 = _nt_weight
1566
+ if r4
1567
+ r3 = r4
1568
+ else
1569
+ r3 = instantiate_node(SyntaxNode,input, index...index)
1570
+ end
1571
+ s0 << r3
1572
+ if r3
1573
+ r5 = _nt_number
1574
+ s0 << r5
1575
+ if r5
1576
+ i7, s7 = index, []
1577
+ if has_terminal?(':', false, index)
1578
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
1579
+ @index += 1
1580
+ else
1581
+ terminal_parse_failure(':')
1582
+ r8 = nil
1583
+ end
1584
+ s7 << r8
1585
+ if r8
1586
+ r9 = _nt_number
1587
+ s7 << r9
1588
+ end
1589
+ if s7.last
1590
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1591
+ r7.extend(NumericWithTolerance0)
1592
+ else
1593
+ @index = i7
1594
+ r7 = nil
1595
+ end
1596
+ if r7
1597
+ r6 = r7
1598
+ else
1599
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1600
+ end
1601
+ s0 << r6
1602
+ end
1603
+ end
1604
+ end
1605
+ if s0.last
1606
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1607
+ r0.extend(NumericWithTolerance1)
1608
+ r0.extend(NumericWithTolerance2)
1609
+ else
1610
+ @index = i0
1611
+ r0 = nil
1612
+ end
1613
+
1614
+ node_cache[:numeric_with_tolerance][start_index] = r0
1615
+
1616
+ r0
1617
+ end
1618
+
1619
+ module Range0
1620
+ def number1
1621
+ elements[0]
1622
+ end
1623
+
1624
+ def number2
1625
+ elements[2]
1626
+ end
1627
+ end
1628
+
1629
+ module Range1
1630
+ def maximum
1631
+ Float(elements[0].text_value)
1632
+ end
1633
+
1634
+ def minimum
1635
+ Float(elements[2].text_value)
1636
+ end
1637
+ end
1638
+
1639
+ def _nt_range
1640
+ start_index = index
1641
+ if node_cache[:range].has_key?(index)
1642
+ cached = node_cache[:range][index]
1643
+ @index = cached.interval.end if cached
1644
+ return cached
1645
+ end
1646
+
1647
+ i0, s0 = index, []
1648
+ r1 = _nt_number
1649
+ s0 << r1
1650
+ if r1
1651
+ if has_terminal?('..', false, index)
1652
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 2))
1653
+ @index += 2
1654
+ else
1655
+ terminal_parse_failure('..')
1656
+ r2 = nil
1657
+ end
1658
+ s0 << r2
1659
+ if r2
1660
+ r3 = _nt_number
1661
+ s0 << r3
1662
+ end
1663
+ end
1664
+ if s0.last
1665
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1666
+ r0.extend(Range0)
1667
+ r0.extend(Range1)
1668
+ else
1669
+ @index = i0
1670
+ r0 = nil
1671
+ end
1672
+
1673
+ node_cache[:range][start_index] = r0
1674
+
1675
+ r0
1676
+ end
1677
+
1678
+ module WrongAnswer0
1679
+ end
1680
+
1681
+ module WrongAnswer1
1682
+ end
1683
+
1684
+ module WrongAnswer2
1685
+ end
1686
+
1687
+ module WrongAnswer3
1688
+ def answer
1689
+ ans = { :value => elements[2].text_value.rstrip, :correct => false, :feedback => elements[4].text_value.rstrip[1..-1] }
1690
+ ans[:weight] = Float(elements[1].text_value[1..-2]) if elements[1].text_value != ""
1691
+ return ans
1692
+ end
1693
+ end
1694
+
1695
+ def _nt_wrong_answer
1696
+ start_index = index
1697
+ if node_cache[:wrong_answer].has_key?(index)
1698
+ cached = node_cache[:wrong_answer][index]
1699
+ @index = cached.interval.end if cached
1700
+ return cached
1701
+ end
1702
+
1703
+ i0, s0 = index, []
1704
+ if has_terminal?("~", false, index)
1705
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
1706
+ @index += 1
1707
+ else
1708
+ terminal_parse_failure("~")
1709
+ r1 = nil
1710
+ end
1711
+ s0 << r1
1712
+ if r1
1713
+ r3 = _nt_weight
1714
+ if r3
1715
+ r2 = r3
1716
+ else
1717
+ r2 = instantiate_node(SyntaxNode,input, index...index)
1718
+ end
1719
+ s0 << r2
1720
+ if r2
1721
+ s4, i4 = [], index
1722
+ loop do
1723
+ i5, s5 = index, []
1724
+ i6 = index
1725
+ if has_terminal?('\G[=~}#]', true, index)
1726
+ r7 = true
1727
+ @index += 1
1728
+ else
1729
+ r7 = nil
1730
+ end
1731
+ if r7
1732
+ r6 = nil
1733
+ else
1734
+ @index = i6
1735
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1736
+ end
1737
+ s5 << r6
1738
+ if r6
1739
+ i8 = index
1740
+ i9, s9 = index, []
1741
+ if has_terminal?("\\", false, index)
1742
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
1743
+ @index += 1
1744
+ else
1745
+ terminal_parse_failure("\\")
1746
+ r10 = nil
1747
+ end
1748
+ s9 << r10
1749
+ if r10
1750
+ if has_terminal?('\G[=~{}#:]', true, index)
1751
+ r11 = true
1752
+ @index += 1
1753
+ else
1754
+ r11 = nil
1755
+ end
1756
+ s9 << r11
1757
+ end
1758
+ if s9.last
1759
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1760
+ r9.extend(WrongAnswer0)
1761
+ else
1762
+ @index = i9
1763
+ r9 = nil
1764
+ end
1765
+ if r9
1766
+ r8 = r9
1767
+ else
1768
+ if index < input_length
1769
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
1770
+ @index += 1
1771
+ else
1772
+ terminal_parse_failure("any character")
1773
+ r12 = nil
1774
+ end
1775
+ if r12
1776
+ r8 = r12
1777
+ else
1778
+ @index = i8
1779
+ r8 = nil
1780
+ end
1781
+ end
1782
+ s5 << r8
1783
+ end
1784
+ if s5.last
1785
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
1786
+ r5.extend(WrongAnswer1)
1787
+ else
1788
+ @index = i5
1789
+ r5 = nil
1790
+ end
1791
+ if r5
1792
+ s4 << r5
1793
+ else
1794
+ break
1795
+ end
1796
+ end
1797
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1798
+ s0 << r4
1799
+ if r4
1800
+ r14 = _nt_space
1801
+ if r14
1802
+ r13 = r14
1803
+ else
1804
+ r13 = instantiate_node(SyntaxNode,input, index...index)
1805
+ end
1806
+ s0 << r13
1807
+ if r13
1808
+ r16 = _nt_feedback
1809
+ if r16
1810
+ r15 = r16
1811
+ else
1812
+ r15 = instantiate_node(SyntaxNode,input, index...index)
1813
+ end
1814
+ s0 << r15
1815
+ end
1816
+ end
1817
+ end
1818
+ end
1819
+ if s0.last
1820
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1821
+ r0.extend(WrongAnswer2)
1822
+ r0.extend(WrongAnswer3)
1823
+ else
1824
+ @index = i0
1825
+ r0 = nil
1826
+ end
1827
+
1828
+ node_cache[:wrong_answer][start_index] = r0
1829
+
1830
+ r0
1831
+ end
1832
+
1833
+ module RightAnswer0
1834
+ end
1835
+
1836
+ module RightAnswer1
1837
+ end
1838
+
1839
+ module RightAnswer2
1840
+ end
1841
+
1842
+ module RightAnswer3
1843
+ def answer
1844
+ ans = { :value => elements[2].text_value.rstrip, :correct => true, :feedback => elements[4].text_value.rstrip[1..-1] }
1845
+ ans[:weight] = Float(elements[1].text_value[1..-2]) if elements[1].text_value != ""
1846
+ return ans
1847
+ end
1848
+ end
1849
+
1850
+ def _nt_right_answer
1851
+ start_index = index
1852
+ if node_cache[:right_answer].has_key?(index)
1853
+ cached = node_cache[:right_answer][index]
1854
+ @index = cached.interval.end if cached
1855
+ return cached
1856
+ end
1857
+
1858
+ i0, s0 = index, []
1859
+ if has_terminal?("=", false, index)
1860
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
1861
+ @index += 1
1862
+ else
1863
+ terminal_parse_failure("=")
1864
+ r1 = nil
1865
+ end
1866
+ s0 << r1
1867
+ if r1
1868
+ r3 = _nt_weight
1869
+ if r3
1870
+ r2 = r3
1871
+ else
1872
+ r2 = instantiate_node(SyntaxNode,input, index...index)
1873
+ end
1874
+ s0 << r2
1875
+ if r2
1876
+ s4, i4 = [], index
1877
+ loop do
1878
+ i5, s5 = index, []
1879
+ i6 = index
1880
+ if has_terminal?('\G[=~}#]', true, index)
1881
+ r7 = true
1882
+ @index += 1
1883
+ else
1884
+ r7 = nil
1885
+ end
1886
+ if r7
1887
+ r6 = nil
1888
+ else
1889
+ @index = i6
1890
+ r6 = instantiate_node(SyntaxNode,input, index...index)
1891
+ end
1892
+ s5 << r6
1893
+ if r6
1894
+ i8 = index
1895
+ i9, s9 = index, []
1896
+ if has_terminal?("\\", false, index)
1897
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
1898
+ @index += 1
1899
+ else
1900
+ terminal_parse_failure("\\")
1901
+ r10 = nil
1902
+ end
1903
+ s9 << r10
1904
+ if r10
1905
+ if has_terminal?('\G[=~{}#:]', true, index)
1906
+ r11 = true
1907
+ @index += 1
1908
+ else
1909
+ r11 = nil
1910
+ end
1911
+ s9 << r11
1912
+ end
1913
+ if s9.last
1914
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
1915
+ r9.extend(RightAnswer0)
1916
+ else
1917
+ @index = i9
1918
+ r9 = nil
1919
+ end
1920
+ if r9
1921
+ r8 = r9
1922
+ else
1923
+ if index < input_length
1924
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
1925
+ @index += 1
1926
+ else
1927
+ terminal_parse_failure("any character")
1928
+ r12 = nil
1929
+ end
1930
+ if r12
1931
+ r8 = r12
1932
+ else
1933
+ @index = i8
1934
+ r8 = nil
1935
+ end
1936
+ end
1937
+ s5 << r8
1938
+ end
1939
+ if s5.last
1940
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
1941
+ r5.extend(RightAnswer1)
1942
+ else
1943
+ @index = i5
1944
+ r5 = nil
1945
+ end
1946
+ if r5
1947
+ s4 << r5
1948
+ else
1949
+ break
1950
+ end
1951
+ end
1952
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1953
+ s0 << r4
1954
+ if r4
1955
+ r14 = _nt_space
1956
+ if r14
1957
+ r13 = r14
1958
+ else
1959
+ r13 = instantiate_node(SyntaxNode,input, index...index)
1960
+ end
1961
+ s0 << r13
1962
+ if r13
1963
+ r16 = _nt_feedback
1964
+ if r16
1965
+ r15 = r16
1966
+ else
1967
+ r15 = instantiate_node(SyntaxNode,input, index...index)
1968
+ end
1969
+ s0 << r15
1970
+ end
1971
+ end
1972
+ end
1973
+ end
1974
+ if s0.last
1975
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1976
+ r0.extend(RightAnswer2)
1977
+ r0.extend(RightAnswer3)
1978
+ else
1979
+ @index = i0
1980
+ r0 = nil
1981
+ end
1982
+
1983
+ node_cache[:right_answer][start_index] = r0
1984
+
1985
+ r0
1986
+ end
1987
+
1988
+ module MatchAnswer0
1989
+ end
1990
+
1991
+ module MatchAnswer1
1992
+ end
1993
+
1994
+ module MatchAnswer2
1995
+ end
1996
+
1997
+ module MatchAnswer3
1998
+ end
1999
+
2000
+ module MatchAnswer4
2001
+ end
2002
+
2003
+ module MatchAnswer5
2004
+ def answer
2005
+ { elements[1].text_value.strip => elements[3].text_value.strip }
2006
+ end
2007
+ end
2008
+
2009
+ def _nt_match_answer
2010
+ start_index = index
2011
+ if node_cache[:match_answer].has_key?(index)
2012
+ cached = node_cache[:match_answer][index]
2013
+ @index = cached.interval.end if cached
2014
+ return cached
2015
+ end
2016
+
2017
+ i0, s0 = index, []
2018
+ if has_terminal?("=", false, index)
2019
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
2020
+ @index += 1
2021
+ else
2022
+ terminal_parse_failure("=")
2023
+ r1 = nil
2024
+ end
2025
+ s0 << r1
2026
+ if r1
2027
+ s2, i2 = [], index
2028
+ loop do
2029
+ i3, s3 = index, []
2030
+ i4 = index
2031
+ if has_terminal?("->", false, index)
2032
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
2033
+ @index += 2
2034
+ else
2035
+ terminal_parse_failure("->")
2036
+ r5 = nil
2037
+ end
2038
+ if r5
2039
+ r4 = nil
2040
+ else
2041
+ @index = i4
2042
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2043
+ end
2044
+ s3 << r4
2045
+ if r4
2046
+ i6 = index
2047
+ if has_terminal?('\G[=~}#]', true, index)
2048
+ r7 = true
2049
+ @index += 1
2050
+ else
2051
+ r7 = nil
2052
+ end
2053
+ if r7
2054
+ r6 = nil
2055
+ else
2056
+ @index = i6
2057
+ r6 = instantiate_node(SyntaxNode,input, index...index)
2058
+ end
2059
+ s3 << r6
2060
+ if r6
2061
+ i8 = index
2062
+ i9, s9 = index, []
2063
+ if has_terminal?("\\", false, index)
2064
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
2065
+ @index += 1
2066
+ else
2067
+ terminal_parse_failure("\\")
2068
+ r10 = nil
2069
+ end
2070
+ s9 << r10
2071
+ if r10
2072
+ if has_terminal?('\G[=~{}#:]', true, index)
2073
+ r11 = true
2074
+ @index += 1
2075
+ else
2076
+ r11 = nil
2077
+ end
2078
+ s9 << r11
2079
+ end
2080
+ if s9.last
2081
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
2082
+ r9.extend(MatchAnswer0)
2083
+ else
2084
+ @index = i9
2085
+ r9 = nil
2086
+ end
2087
+ if r9
2088
+ r8 = r9
2089
+ else
2090
+ if index < input_length
2091
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
2092
+ @index += 1
2093
+ else
2094
+ terminal_parse_failure("any character")
2095
+ r12 = nil
2096
+ end
2097
+ if r12
2098
+ r8 = r12
2099
+ else
2100
+ @index = i8
2101
+ r8 = nil
2102
+ end
2103
+ end
2104
+ s3 << r8
2105
+ end
2106
+ end
2107
+ if s3.last
2108
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2109
+ r3.extend(MatchAnswer1)
2110
+ else
2111
+ @index = i3
2112
+ r3 = nil
2113
+ end
2114
+ if r3
2115
+ s2 << r3
2116
+ else
2117
+ break
2118
+ end
2119
+ end
2120
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2121
+ s0 << r2
2122
+ if r2
2123
+ if has_terminal?("->", false, index)
2124
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 2))
2125
+ @index += 2
2126
+ else
2127
+ terminal_parse_failure("->")
2128
+ r13 = nil
2129
+ end
2130
+ s0 << r13
2131
+ if r13
2132
+ s14, i14 = [], index
2133
+ loop do
2134
+ i15, s15 = index, []
2135
+ i16 = index
2136
+ if has_terminal?('\G[=~}#]', true, index)
2137
+ r17 = true
2138
+ @index += 1
2139
+ else
2140
+ r17 = nil
2141
+ end
2142
+ if r17
2143
+ r16 = nil
2144
+ else
2145
+ @index = i16
2146
+ r16 = instantiate_node(SyntaxNode,input, index...index)
2147
+ end
2148
+ s15 << r16
2149
+ if r16
2150
+ i18 = index
2151
+ i19, s19 = index, []
2152
+ if has_terminal?("\\", false, index)
2153
+ r20 = instantiate_node(SyntaxNode,input, index...(index + 1))
2154
+ @index += 1
2155
+ else
2156
+ terminal_parse_failure("\\")
2157
+ r20 = nil
2158
+ end
2159
+ s19 << r20
2160
+ if r20
2161
+ if has_terminal?('\G[=~{}#:]', true, index)
2162
+ r21 = true
2163
+ @index += 1
2164
+ else
2165
+ r21 = nil
2166
+ end
2167
+ s19 << r21
2168
+ end
2169
+ if s19.last
2170
+ r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
2171
+ r19.extend(MatchAnswer2)
2172
+ else
2173
+ @index = i19
2174
+ r19 = nil
2175
+ end
2176
+ if r19
2177
+ r18 = r19
2178
+ else
2179
+ if index < input_length
2180
+ r22 = instantiate_node(SyntaxNode,input, index...(index + 1))
2181
+ @index += 1
2182
+ else
2183
+ terminal_parse_failure("any character")
2184
+ r22 = nil
2185
+ end
2186
+ if r22
2187
+ r18 = r22
2188
+ else
2189
+ @index = i18
2190
+ r18 = nil
2191
+ end
2192
+ end
2193
+ s15 << r18
2194
+ end
2195
+ if s15.last
2196
+ r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
2197
+ r15.extend(MatchAnswer3)
2198
+ else
2199
+ @index = i15
2200
+ r15 = nil
2201
+ end
2202
+ if r15
2203
+ s14 << r15
2204
+ else
2205
+ break
2206
+ end
2207
+ end
2208
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
2209
+ s0 << r14
2210
+ if r14
2211
+ r24 = _nt_space
2212
+ if r24
2213
+ r23 = r24
2214
+ else
2215
+ r23 = instantiate_node(SyntaxNode,input, index...index)
2216
+ end
2217
+ s0 << r23
2218
+ end
2219
+ end
2220
+ end
2221
+ end
2222
+ if s0.last
2223
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2224
+ r0.extend(MatchAnswer4)
2225
+ r0.extend(MatchAnswer5)
2226
+ else
2227
+ @index = i0
2228
+ r0 = nil
2229
+ end
2230
+
2231
+ node_cache[:match_answer][start_index] = r0
2232
+
2233
+ r0
2234
+ end
2235
+
2236
+ module TrueAnswer0
2237
+ end
2238
+
2239
+ module TrueAnswer1
2240
+ def answer
2241
+ {:value => true, :correct => true, :feedback => elements[2].text_value.rstrip[1..-1]}
2242
+ end
2243
+ end
2244
+
2245
+ def _nt_true_answer
2246
+ start_index = index
2247
+ if node_cache[:true_answer].has_key?(index)
2248
+ cached = node_cache[:true_answer][index]
2249
+ @index = cached.interval.end if cached
2250
+ return cached
2251
+ end
2252
+
2253
+ i0, s0 = index, []
2254
+ i1 = index
2255
+ if has_terminal?("TRUE", false, index)
2256
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 4))
2257
+ @index += 4
2258
+ else
2259
+ terminal_parse_failure("TRUE")
2260
+ r2 = nil
2261
+ end
2262
+ if r2
2263
+ r1 = r2
2264
+ else
2265
+ if has_terminal?("T", false, index)
2266
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
2267
+ @index += 1
2268
+ else
2269
+ terminal_parse_failure("T")
2270
+ r3 = nil
2271
+ end
2272
+ if r3
2273
+ r1 = r3
2274
+ else
2275
+ @index = i1
2276
+ r1 = nil
2277
+ end
2278
+ end
2279
+ s0 << r1
2280
+ if r1
2281
+ r5 = _nt_space
2282
+ if r5
2283
+ r4 = r5
2284
+ else
2285
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2286
+ end
2287
+ s0 << r4
2288
+ if r4
2289
+ r7 = _nt_feedback
2290
+ if r7
2291
+ r6 = r7
2292
+ else
2293
+ r6 = instantiate_node(SyntaxNode,input, index...index)
2294
+ end
2295
+ s0 << r6
2296
+ end
2297
+ end
2298
+ if s0.last
2299
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2300
+ r0.extend(TrueAnswer0)
2301
+ r0.extend(TrueAnswer1)
2302
+ else
2303
+ @index = i0
2304
+ r0 = nil
2305
+ end
2306
+
2307
+ node_cache[:true_answer][start_index] = r0
2308
+
2309
+ r0
2310
+ end
2311
+
2312
+ module FalseAnswer0
2313
+ end
2314
+
2315
+ module FalseAnswer1
2316
+ def answer
2317
+ {:value => false, :correct => true, :feedback => elements[2].text_value.rstrip[1..-1]}
2318
+ end
2319
+ end
2320
+
2321
+ def _nt_false_answer
2322
+ start_index = index
2323
+ if node_cache[:false_answer].has_key?(index)
2324
+ cached = node_cache[:false_answer][index]
2325
+ @index = cached.interval.end if cached
2326
+ return cached
2327
+ end
2328
+
2329
+ i0, s0 = index, []
2330
+ i1 = index
2331
+ if has_terminal?("FALSE", false, index)
2332
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 5))
2333
+ @index += 5
2334
+ else
2335
+ terminal_parse_failure("FALSE")
2336
+ r2 = nil
2337
+ end
2338
+ if r2
2339
+ r1 = r2
2340
+ else
2341
+ if has_terminal?("F", false, index)
2342
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
2343
+ @index += 1
2344
+ else
2345
+ terminal_parse_failure("F")
2346
+ r3 = nil
2347
+ end
2348
+ if r3
2349
+ r1 = r3
2350
+ else
2351
+ @index = i1
2352
+ r1 = nil
2353
+ end
2354
+ end
2355
+ s0 << r1
2356
+ if r1
2357
+ r5 = _nt_space
2358
+ if r5
2359
+ r4 = r5
2360
+ else
2361
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2362
+ end
2363
+ s0 << r4
2364
+ if r4
2365
+ r7 = _nt_feedback
2366
+ if r7
2367
+ r6 = r7
2368
+ else
2369
+ r6 = instantiate_node(SyntaxNode,input, index...index)
2370
+ end
2371
+ s0 << r6
2372
+ end
2373
+ end
2374
+ if s0.last
2375
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2376
+ r0.extend(FalseAnswer0)
2377
+ r0.extend(FalseAnswer1)
2378
+ else
2379
+ @index = i0
2380
+ r0 = nil
2381
+ end
2382
+
2383
+ node_cache[:false_answer][start_index] = r0
2384
+
2385
+ r0
2386
+ end
2387
+
2388
+ module Comment0
2389
+ end
2390
+
2391
+ module Comment1
2392
+ def line_break
2393
+ elements[2]
2394
+ end
2395
+
2396
+ end
2397
+
2398
+ def _nt_comment
2399
+ start_index = index
2400
+ if node_cache[:comment].has_key?(index)
2401
+ cached = node_cache[:comment][index]
2402
+ @index = cached.interval.end if cached
2403
+ return cached
2404
+ end
2405
+
2406
+ i0, s0 = index, []
2407
+ if has_terminal?("//", false, index)
2408
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
2409
+ @index += 2
2410
+ else
2411
+ terminal_parse_failure("//")
2412
+ r1 = nil
2413
+ end
2414
+ s0 << r1
2415
+ if r1
2416
+ s2, i2 = [], index
2417
+ loop do
2418
+ i3, s3 = index, []
2419
+ i4 = index
2420
+ r5 = _nt_line_break
2421
+ if r5
2422
+ r4 = nil
2423
+ else
2424
+ @index = i4
2425
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2426
+ end
2427
+ s3 << r4
2428
+ if r4
2429
+ if index < input_length
2430
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
2431
+ @index += 1
2432
+ else
2433
+ terminal_parse_failure("any character")
2434
+ r6 = nil
2435
+ end
2436
+ s3 << r6
2437
+ end
2438
+ if s3.last
2439
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2440
+ r3.extend(Comment0)
2441
+ else
2442
+ @index = i3
2443
+ r3 = nil
2444
+ end
2445
+ if r3
2446
+ s2 << r3
2447
+ else
2448
+ break
2449
+ end
2450
+ end
2451
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2452
+ s0 << r2
2453
+ if r2
2454
+ r7 = _nt_line_break
2455
+ s0 << r7
2456
+ if r7
2457
+ r9 = _nt_comment
2458
+ if r9
2459
+ r8 = r9
2460
+ else
2461
+ r8 = instantiate_node(SyntaxNode,input, index...index)
2462
+ end
2463
+ s0 << r8
2464
+ end
2465
+ end
2466
+ end
2467
+ if s0.last
2468
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2469
+ r0.extend(Comment1)
2470
+ else
2471
+ @index = i0
2472
+ r0 = nil
2473
+ end
2474
+
2475
+ node_cache[:comment][start_index] = r0
2476
+
2477
+ r0
2478
+ end
2479
+
2480
+ module Title0
2481
+ end
2482
+
2483
+ module Title1
2484
+ end
2485
+
2486
+ module Title2
2487
+ end
2488
+
2489
+ def _nt_title
2490
+ start_index = index
2491
+ if node_cache[:title].has_key?(index)
2492
+ cached = node_cache[:title][index]
2493
+ @index = cached.interval.end if cached
2494
+ return cached
2495
+ end
2496
+
2497
+ i0, s0 = index, []
2498
+ if has_terminal?('::', false, index)
2499
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
2500
+ @index += 2
2501
+ else
2502
+ terminal_parse_failure('::')
2503
+ r1 = nil
2504
+ end
2505
+ s0 << r1
2506
+ if r1
2507
+ s2, i2 = [], index
2508
+ loop do
2509
+ i3, s3 = index, []
2510
+ i4 = index
2511
+ if has_terminal?("::", false, index)
2512
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
2513
+ @index += 2
2514
+ else
2515
+ terminal_parse_failure("::")
2516
+ r5 = nil
2517
+ end
2518
+ if r5
2519
+ r4 = nil
2520
+ else
2521
+ @index = i4
2522
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2523
+ end
2524
+ s3 << r4
2525
+ if r4
2526
+ i6 = index
2527
+ i7, s7 = index, []
2528
+ if has_terminal?("\\", false, index)
2529
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
2530
+ @index += 1
2531
+ else
2532
+ terminal_parse_failure("\\")
2533
+ r8 = nil
2534
+ end
2535
+ s7 << r8
2536
+ if r8
2537
+ if has_terminal?('\G[=~{}#:]', true, index)
2538
+ r9 = true
2539
+ @index += 1
2540
+ else
2541
+ r9 = nil
2542
+ end
2543
+ s7 << r9
2544
+ end
2545
+ if s7.last
2546
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
2547
+ r7.extend(Title0)
2548
+ else
2549
+ @index = i7
2550
+ r7 = nil
2551
+ end
2552
+ if r7
2553
+ r6 = r7
2554
+ else
2555
+ if index < input_length
2556
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
2557
+ @index += 1
2558
+ else
2559
+ terminal_parse_failure("any character")
2560
+ r10 = nil
2561
+ end
2562
+ if r10
2563
+ r6 = r10
2564
+ else
2565
+ @index = i6
2566
+ r6 = nil
2567
+ end
2568
+ end
2569
+ s3 << r6
2570
+ end
2571
+ if s3.last
2572
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2573
+ r3.extend(Title1)
2574
+ else
2575
+ @index = i3
2576
+ r3 = nil
2577
+ end
2578
+ if r3
2579
+ s2 << r3
2580
+ else
2581
+ break
2582
+ end
2583
+ end
2584
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2585
+ s0 << r2
2586
+ if r2
2587
+ if has_terminal?('::', false, index)
2588
+ r11 = instantiate_node(SyntaxNode,input, index...(index + 2))
2589
+ @index += 2
2590
+ else
2591
+ terminal_parse_failure('::')
2592
+ r11 = nil
2593
+ end
2594
+ s0 << r11
2595
+ if r11
2596
+ r13 = _nt_line_break
2597
+ if r13
2598
+ r12 = r13
2599
+ else
2600
+ r12 = instantiate_node(SyntaxNode,input, index...index)
2601
+ end
2602
+ s0 << r12
2603
+ end
2604
+ end
2605
+ end
2606
+ if s0.last
2607
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2608
+ r0.extend(Title2)
2609
+ else
2610
+ @index = i0
2611
+ r0 = nil
2612
+ end
2613
+
2614
+ node_cache[:title][start_index] = r0
2615
+
2616
+ r0
2617
+ end
2618
+
2619
+ module QuestionText0
2620
+ end
2621
+
2622
+ module QuestionText1
2623
+ end
2624
+
2625
+ module QuestionText2
2626
+ def markup
2627
+ elements[0]
2628
+ end
2629
+
2630
+ end
2631
+
2632
+ def _nt_question_text
2633
+ start_index = index
2634
+ if node_cache[:question_text].has_key?(index)
2635
+ cached = node_cache[:question_text][index]
2636
+ @index = cached.interval.end if cached
2637
+ return cached
2638
+ end
2639
+
2640
+ i0, s0 = index, []
2641
+ r2 = _nt_markup
2642
+ if r2
2643
+ r1 = r2
2644
+ else
2645
+ r1 = instantiate_node(SyntaxNode,input, index...index)
2646
+ end
2647
+ s0 << r1
2648
+ if r1
2649
+ s3, i3 = [], index
2650
+ loop do
2651
+ i4, s4 = index, []
2652
+ i5 = index
2653
+ if has_terminal?("{", false, index)
2654
+ r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
2655
+ @index += 1
2656
+ else
2657
+ terminal_parse_failure("{")
2658
+ r6 = nil
2659
+ end
2660
+ if r6
2661
+ r5 = nil
2662
+ else
2663
+ @index = i5
2664
+ r5 = instantiate_node(SyntaxNode,input, index...index)
2665
+ end
2666
+ s4 << r5
2667
+ if r5
2668
+ i7 = index
2669
+ r8 = _nt_blank_line
2670
+ if r8
2671
+ r7 = nil
2672
+ else
2673
+ @index = i7
2674
+ r7 = instantiate_node(SyntaxNode,input, index...index)
2675
+ end
2676
+ s4 << r7
2677
+ if r7
2678
+ i9 = index
2679
+ i10, s10 = index, []
2680
+ if has_terminal?("\\", false, index)
2681
+ r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
2682
+ @index += 1
2683
+ else
2684
+ terminal_parse_failure("\\")
2685
+ r11 = nil
2686
+ end
2687
+ s10 << r11
2688
+ if r11
2689
+ if has_terminal?('\G[=~{}#:]', true, index)
2690
+ r12 = true
2691
+ @index += 1
2692
+ else
2693
+ r12 = nil
2694
+ end
2695
+ s10 << r12
2696
+ end
2697
+ if s10.last
2698
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
2699
+ r10.extend(QuestionText0)
2700
+ else
2701
+ @index = i10
2702
+ r10 = nil
2703
+ end
2704
+ if r10
2705
+ r9 = r10
2706
+ else
2707
+ if index < input_length
2708
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
2709
+ @index += 1
2710
+ else
2711
+ terminal_parse_failure("any character")
2712
+ r13 = nil
2713
+ end
2714
+ if r13
2715
+ r9 = r13
2716
+ else
2717
+ @index = i9
2718
+ r9 = nil
2719
+ end
2720
+ end
2721
+ s4 << r9
2722
+ end
2723
+ end
2724
+ if s4.last
2725
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
2726
+ r4.extend(QuestionText1)
2727
+ else
2728
+ @index = i4
2729
+ r4 = nil
2730
+ end
2731
+ if r4
2732
+ s3 << r4
2733
+ else
2734
+ break
2735
+ end
2736
+ end
2737
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2738
+ s0 << r3
2739
+ end
2740
+ if s0.last
2741
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2742
+ r0.extend(QuestionText2)
2743
+ else
2744
+ @index = i0
2745
+ r0 = nil
2746
+ end
2747
+
2748
+ node_cache[:question_text][start_index] = r0
2749
+
2750
+ r0
2751
+ end
2752
+
2753
+ module Markup0
2754
+ end
2755
+
2756
+ module Markup1
2757
+ end
2758
+
2759
+ module Markup2
2760
+ end
2761
+
2762
+ def _nt_markup
2763
+ start_index = index
2764
+ if node_cache[:markup].has_key?(index)
2765
+ cached = node_cache[:markup][index]
2766
+ @index = cached.interval.end if cached
2767
+ return cached
2768
+ end
2769
+
2770
+ i0, s0 = index, []
2771
+ if has_terminal?("[", false, index)
2772
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
2773
+ @index += 1
2774
+ else
2775
+ terminal_parse_failure("[")
2776
+ r1 = nil
2777
+ end
2778
+ s0 << r1
2779
+ if r1
2780
+ s2, i2 = [], index
2781
+ loop do
2782
+ i3, s3 = index, []
2783
+ i4 = index
2784
+ if has_terminal?("]", false, index)
2785
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
2786
+ @index += 1
2787
+ else
2788
+ terminal_parse_failure("]")
2789
+ r5 = nil
2790
+ end
2791
+ if r5
2792
+ r4 = nil
2793
+ else
2794
+ @index = i4
2795
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2796
+ end
2797
+ s3 << r4
2798
+ if r4
2799
+ i6 = index
2800
+ r7 = _nt_blank_line
2801
+ if r7
2802
+ r6 = nil
2803
+ else
2804
+ @index = i6
2805
+ r6 = instantiate_node(SyntaxNode,input, index...index)
2806
+ end
2807
+ s3 << r6
2808
+ if r6
2809
+ i8 = index
2810
+ i9, s9 = index, []
2811
+ if has_terminal?("\\", false, index)
2812
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
2813
+ @index += 1
2814
+ else
2815
+ terminal_parse_failure("\\")
2816
+ r10 = nil
2817
+ end
2818
+ s9 << r10
2819
+ if r10
2820
+ if has_terminal?('\G[=~{}#:]', true, index)
2821
+ r11 = true
2822
+ @index += 1
2823
+ else
2824
+ r11 = nil
2825
+ end
2826
+ s9 << r11
2827
+ end
2828
+ if s9.last
2829
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
2830
+ r9.extend(Markup0)
2831
+ else
2832
+ @index = i9
2833
+ r9 = nil
2834
+ end
2835
+ if r9
2836
+ r8 = r9
2837
+ else
2838
+ if index < input_length
2839
+ r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
2840
+ @index += 1
2841
+ else
2842
+ terminal_parse_failure("any character")
2843
+ r12 = nil
2844
+ end
2845
+ if r12
2846
+ r8 = r12
2847
+ else
2848
+ @index = i8
2849
+ r8 = nil
2850
+ end
2851
+ end
2852
+ s3 << r8
2853
+ end
2854
+ end
2855
+ if s3.last
2856
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2857
+ r3.extend(Markup1)
2858
+ else
2859
+ @index = i3
2860
+ r3 = nil
2861
+ end
2862
+ if r3
2863
+ s2 << r3
2864
+ else
2865
+ break
2866
+ end
2867
+ end
2868
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2869
+ s0 << r2
2870
+ if r2
2871
+ if has_terminal?("]", false, index)
2872
+ r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
2873
+ @index += 1
2874
+ else
2875
+ terminal_parse_failure("]")
2876
+ r13 = nil
2877
+ end
2878
+ s0 << r13
2879
+ end
2880
+ end
2881
+ if s0.last
2882
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
2883
+ r0.extend(Markup2)
2884
+ else
2885
+ @index = i0
2886
+ r0 = nil
2887
+ end
2888
+
2889
+ node_cache[:markup][start_index] = r0
2890
+
2891
+ r0
2892
+ end
2893
+
2894
+ module Feedback0
2895
+ end
2896
+
2897
+ module Feedback1
2898
+ end
2899
+
2900
+ module Feedback2
2901
+ end
2902
+
2903
+ def _nt_feedback
2904
+ start_index = index
2905
+ if node_cache[:feedback].has_key?(index)
2906
+ cached = node_cache[:feedback][index]
2907
+ @index = cached.interval.end if cached
2908
+ return cached
2909
+ end
2910
+
2911
+ i0, s0 = index, []
2912
+ if has_terminal?("#", false, index)
2913
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
2914
+ @index += 1
2915
+ else
2916
+ terminal_parse_failure("#")
2917
+ r1 = nil
2918
+ end
2919
+ s0 << r1
2920
+ if r1
2921
+ s2, i2 = [], index
2922
+ loop do
2923
+ i3, s3 = index, []
2924
+ i4 = index
2925
+ if has_terminal?('\G[=~}#]', true, index)
2926
+ r5 = true
2927
+ @index += 1
2928
+ else
2929
+ r5 = nil
2930
+ end
2931
+ if r5
2932
+ r4 = nil
2933
+ else
2934
+ @index = i4
2935
+ r4 = instantiate_node(SyntaxNode,input, index...index)
2936
+ end
2937
+ s3 << r4
2938
+ if r4
2939
+ i6 = index
2940
+ i7, s7 = index, []
2941
+ if has_terminal?("\\", false, index)
2942
+ r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
2943
+ @index += 1
2944
+ else
2945
+ terminal_parse_failure("\\")
2946
+ r8 = nil
2947
+ end
2948
+ s7 << r8
2949
+ if r8
2950
+ if has_terminal?('\G[=~{}#:]', true, index)
2951
+ r9 = true
2952
+ @index += 1
2953
+ else
2954
+ r9 = nil
2955
+ end
2956
+ s7 << r9
2957
+ end
2958
+ if s7.last
2959
+ r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
2960
+ r7.extend(Feedback0)
2961
+ else
2962
+ @index = i7
2963
+ r7 = nil
2964
+ end
2965
+ if r7
2966
+ r6 = r7
2967
+ else
2968
+ if index < input_length
2969
+ r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
2970
+ @index += 1
2971
+ else
2972
+ terminal_parse_failure("any character")
2973
+ r10 = nil
2974
+ end
2975
+ if r10
2976
+ r6 = r10
2977
+ else
2978
+ @index = i6
2979
+ r6 = nil
2980
+ end
2981
+ end
2982
+ s3 << r6
2983
+ end
2984
+ if s3.last
2985
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2986
+ r3.extend(Feedback1)
2987
+ else
2988
+ @index = i3
2989
+ r3 = nil
2990
+ end
2991
+ if r3
2992
+ s2 << r3
2993
+ else
2994
+ break
2995
+ end
2996
+ end
2997
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2998
+ s0 << r2
2999
+ end
3000
+ if s0.last
3001
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3002
+ r0.extend(Feedback2)
3003
+ else
3004
+ @index = i0
3005
+ r0 = nil
3006
+ end
3007
+
3008
+ node_cache[:feedback][start_index] = r0
3009
+
3010
+ r0
3011
+ end
3012
+
3013
+ def _nt_line_break
3014
+ start_index = index
3015
+ if node_cache[:line_break].has_key?(index)
3016
+ cached = node_cache[:line_break][index]
3017
+ @index = cached.interval.end if cached
3018
+ return cached
3019
+ end
3020
+
3021
+ i0 = index
3022
+ if has_terminal?("\r\n", false, index)
3023
+ r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
3024
+ @index += 2
3025
+ else
3026
+ terminal_parse_failure("\r\n")
3027
+ r1 = nil
3028
+ end
3029
+ if r1
3030
+ r0 = r1
3031
+ else
3032
+ if has_terminal?("\n", false, index)
3033
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
3034
+ @index += 1
3035
+ else
3036
+ terminal_parse_failure("\n")
3037
+ r2 = nil
3038
+ end
3039
+ if r2
3040
+ r0 = r2
3041
+ else
3042
+ @index = i0
3043
+ r0 = nil
3044
+ end
3045
+ end
3046
+
3047
+ node_cache[:line_break][start_index] = r0
3048
+
3049
+ r0
3050
+ end
3051
+
3052
+ def _nt_nbsp
3053
+ start_index = index
3054
+ if node_cache[:nbsp].has_key?(index)
3055
+ cached = node_cache[:nbsp][index]
3056
+ @index = cached.interval.end if cached
3057
+ return cached
3058
+ end
3059
+
3060
+ s0, i0 = [], index
3061
+ loop do
3062
+ i1 = index
3063
+ if has_terminal?(" ", false, index)
3064
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
3065
+ @index += 1
3066
+ else
3067
+ terminal_parse_failure(" ")
3068
+ r2 = nil
3069
+ end
3070
+ if r2
3071
+ r1 = r2
3072
+ else
3073
+ if has_terminal?("\t", false, index)
3074
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
3075
+ @index += 1
3076
+ else
3077
+ terminal_parse_failure("\t")
3078
+ r3 = nil
3079
+ end
3080
+ if r3
3081
+ r1 = r3
3082
+ else
3083
+ @index = i1
3084
+ r1 = nil
3085
+ end
3086
+ end
3087
+ if r1
3088
+ s0 << r1
3089
+ else
3090
+ break
3091
+ end
3092
+ end
3093
+ if s0.empty?
3094
+ @index = i0
3095
+ r0 = nil
3096
+ else
3097
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3098
+ end
3099
+
3100
+ node_cache[:nbsp][start_index] = r0
3101
+
3102
+ r0
3103
+ end
3104
+
3105
+ def _nt_space
3106
+ start_index = index
3107
+ if node_cache[:space].has_key?(index)
3108
+ cached = node_cache[:space][index]
3109
+ @index = cached.interval.end if cached
3110
+ return cached
3111
+ end
3112
+
3113
+ s0, i0 = [], index
3114
+ loop do
3115
+ i1 = index
3116
+ if has_terminal?(" ", false, index)
3117
+ r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
3118
+ @index += 1
3119
+ else
3120
+ terminal_parse_failure(" ")
3121
+ r2 = nil
3122
+ end
3123
+ if r2
3124
+ r1 = r2
3125
+ else
3126
+ if has_terminal?("\t", false, index)
3127
+ r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
3128
+ @index += 1
3129
+ else
3130
+ terminal_parse_failure("\t")
3131
+ r3 = nil
3132
+ end
3133
+ if r3
3134
+ r1 = r3
3135
+ else
3136
+ if has_terminal?("\r", false, index)
3137
+ r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
3138
+ @index += 1
3139
+ else
3140
+ terminal_parse_failure("\r")
3141
+ r4 = nil
3142
+ end
3143
+ if r4
3144
+ r1 = r4
3145
+ else
3146
+ if has_terminal?("\n", false, index)
3147
+ r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
3148
+ @index += 1
3149
+ else
3150
+ terminal_parse_failure("\n")
3151
+ r5 = nil
3152
+ end
3153
+ if r5
3154
+ r1 = r5
3155
+ else
3156
+ @index = i1
3157
+ r1 = nil
3158
+ end
3159
+ end
3160
+ end
3161
+ end
3162
+ if r1
3163
+ s0 << r1
3164
+ else
3165
+ break
3166
+ end
3167
+ end
3168
+ if s0.empty?
3169
+ @index = i0
3170
+ r0 = nil
3171
+ else
3172
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3173
+ end
3174
+
3175
+ node_cache[:space][start_index] = r0
3176
+
3177
+ r0
3178
+ end
3179
+
3180
+ module BlankLine0
3181
+ def line_break1
3182
+ elements[0]
3183
+ end
3184
+
3185
+ def line_break2
3186
+ elements[2]
3187
+ end
3188
+
3189
+ end
3190
+
3191
+ def _nt_blank_line
3192
+ start_index = index
3193
+ if node_cache[:blank_line].has_key?(index)
3194
+ cached = node_cache[:blank_line][index]
3195
+ @index = cached.interval.end if cached
3196
+ return cached
3197
+ end
3198
+
3199
+ i0, s0 = index, []
3200
+ r1 = _nt_line_break
3201
+ s0 << r1
3202
+ if r1
3203
+ r3 = _nt_nbsp
3204
+ if r3
3205
+ r2 = r3
3206
+ else
3207
+ r2 = instantiate_node(SyntaxNode,input, index...index)
3208
+ end
3209
+ s0 << r2
3210
+ if r2
3211
+ r4 = _nt_line_break
3212
+ s0 << r4
3213
+ if r4
3214
+ r6 = _nt_space
3215
+ if r6
3216
+ r5 = r6
3217
+ else
3218
+ r5 = instantiate_node(SyntaxNode,input, index...index)
3219
+ end
3220
+ s0 << r5
3221
+ end
3222
+ end
3223
+ end
3224
+ if s0.last
3225
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
3226
+ r0.extend(BlankLine0)
3227
+ else
3228
+ @index = i0
3229
+ r0 = nil
3230
+ end
3231
+
3232
+ node_cache[:blank_line][start_index] = r0
3233
+
3234
+ r0
3235
+ end
3236
+
3237
+ end
3238
+
3239
+ class GiftParser < Treetop::Runtime::CompiledParser
3240
+ include Gift
3241
+ end
3242
+