treetop 1.6.7 → 1.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/doc/sitegen.rb +13 -0
- data/doc/syntactic_recognition.markdown +2 -2
- data/lib/treetop/compiler/grammar_compiler.rb +6 -3
- data/lib/treetop/compiler/metagrammar.rb +97 -77
- data/lib/treetop/compiler/metagrammar.treetop +1 -1
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/test_grammar.tt +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5cf78875bffce2e5a417f380e3c1b2e96ad9397
|
4
|
+
data.tar.gz: bf189a3e2bdd867b296e8872f33cd5b617e7c72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148bdfbd93703196ce7ff227bf28af6cfdb62caa1f3f45bf59f69d9691e49709d7df2c1b088c8e01a933bd8012d38c5ad8678998e845048ccbf5650913086f55
|
7
|
+
data.tar.gz: c8bf7bd1b095ed2eee7c8cddb7872070be1c51cf37b448e10c7fd4d359c93e90afcc48a4cfd073f4aca9ad6189f6bb8cfa448cdf963a6c203315a7bd07b44b89
|
data/README.md
CHANGED
data/doc/sitegen.rb
CHANGED
@@ -63,3 +63,16 @@ class Layout < Erector::Widget
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
class String
|
68
|
+
def underscore
|
69
|
+
camel_cased_word = self
|
70
|
+
return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
|
71
|
+
word = camel_cased_word.to_s.gsub('::'.freeze, '/'.freeze)
|
72
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
73
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
74
|
+
word.tr!("-".freeze, "_".freeze)
|
75
|
+
word.downcase!
|
76
|
+
word
|
77
|
+
end
|
78
|
+
end
|
@@ -32,9 +32,9 @@ The main keywords are:
|
|
32
32
|
|
33
33
|
* `rule` : This defines a parsing rule within the grammar. It is followed by a name by which this rule can be referenced within other rules. It is then followed by a parsing expression defining the rule.
|
34
34
|
|
35
|
-
A grammar may be surrounded by one or more nested `module` statements, which provides a namespace for the generated Ruby parser.
|
35
|
+
A grammar may be surrounded by one or more nested `module` or `class` statements, which provides a namespace for the generated Ruby parser. Note that you cannot specify a superclass for a class, so if your class has a superclass, it must be declared elsewhere and loaded first.
|
36
36
|
|
37
|
-
Treetop will emit a module called `GrammarName` and a parser class called `GrammarNameParser` (in the
|
37
|
+
Treetop will emit a module called `GrammarName` and a parser class called `GrammarNameParser` (in the namespace, if specified).
|
38
38
|
|
39
39
|
#Parsing Expressions
|
40
40
|
Each rule associates a name with a _parsing expression_. Parsing expressions are a generalization of vanilla regular expressions. Their key feature is the ability to reference other expressions in the grammar by name.
|
@@ -33,10 +33,13 @@ module Treetop
|
|
33
33
|
|
34
34
|
# compile a treetop source file and load it
|
35
35
|
def self.load(path)
|
36
|
-
|
37
|
-
|
36
|
+
unless path =~ Treetop::Polyglot::VALID_GRAMMAR_EXT_REGEXP
|
37
|
+
ext = Treetop::Polyglot::VALID_GRAMMAR_EXT.select {|ext| File.exist?(path+".#{ext}")}.shift
|
38
|
+
path += ".#{ext}" unless ext.nil?
|
39
|
+
end
|
40
|
+
File.open(path) do |source_file|
|
38
41
|
source = source_file.read
|
39
|
-
source.gsub!(/\b__FILE__\b/, %Q{"#{
|
42
|
+
source.gsub!(/\b__FILE__\b/, %Q{"#{path}"})
|
40
43
|
load_from_string(source)
|
41
44
|
end
|
42
45
|
end
|
@@ -320,102 +320,122 @@ module Treetop
|
|
320
320
|
|
321
321
|
i0, s0 = index, []
|
322
322
|
i1, s1 = index, []
|
323
|
+
i2 = index
|
323
324
|
if (match_len = has_terminal?('module', false, index))
|
324
|
-
|
325
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
325
326
|
@index += match_len
|
326
327
|
else
|
327
328
|
terminal_parse_failure('\'module\'')
|
328
|
-
|
329
|
+
r3 = nil
|
330
|
+
end
|
331
|
+
if r3
|
332
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
333
|
+
r2 = r3
|
334
|
+
else
|
335
|
+
if (match_len = has_terminal?('class', false, index))
|
336
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
337
|
+
@index += match_len
|
338
|
+
else
|
339
|
+
terminal_parse_failure('\'class\'')
|
340
|
+
r4 = nil
|
341
|
+
end
|
342
|
+
if r4
|
343
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
344
|
+
r2 = r4
|
345
|
+
else
|
346
|
+
@index = i2
|
347
|
+
r2 = nil
|
348
|
+
end
|
329
349
|
end
|
330
350
|
s1 << r2
|
331
351
|
if r2
|
332
|
-
|
333
|
-
s1 <<
|
334
|
-
if
|
335
|
-
|
352
|
+
r5 = _nt_space
|
353
|
+
s1 << r5
|
354
|
+
if r5
|
355
|
+
i6, s6 = index, []
|
336
356
|
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
337
|
-
|
357
|
+
r7 = true
|
338
358
|
@index += 1
|
339
359
|
else
|
340
360
|
terminal_parse_failure('[A-Z]')
|
341
|
-
|
361
|
+
r7 = nil
|
342
362
|
end
|
343
|
-
|
344
|
-
if
|
345
|
-
|
363
|
+
s6 << r7
|
364
|
+
if r7
|
365
|
+
s8, i8 = [], index
|
346
366
|
loop do
|
347
|
-
|
348
|
-
if
|
349
|
-
|
367
|
+
r9 = _nt_alphanumeric_char
|
368
|
+
if r9
|
369
|
+
s8 << r9
|
350
370
|
else
|
351
371
|
break
|
352
372
|
end
|
353
373
|
end
|
354
|
-
|
355
|
-
|
356
|
-
if
|
357
|
-
|
374
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
375
|
+
s6 << r8
|
376
|
+
if r8
|
377
|
+
s10, i10 = [], index
|
358
378
|
loop do
|
359
|
-
|
379
|
+
i11, s11 = index, []
|
360
380
|
if (match_len = has_terminal?('::', false, index))
|
361
|
-
|
381
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
362
382
|
@index += match_len
|
363
383
|
else
|
364
384
|
terminal_parse_failure('\'::\'')
|
365
|
-
|
385
|
+
r12 = nil
|
366
386
|
end
|
367
|
-
|
368
|
-
if
|
387
|
+
s11 << r12
|
388
|
+
if r12
|
369
389
|
if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
|
370
|
-
|
390
|
+
r13 = true
|
371
391
|
@index += 1
|
372
392
|
else
|
373
393
|
terminal_parse_failure('[A-Z]')
|
374
|
-
|
394
|
+
r13 = nil
|
375
395
|
end
|
376
|
-
|
377
|
-
if
|
378
|
-
|
396
|
+
s11 << r13
|
397
|
+
if r13
|
398
|
+
s14, i14 = [], index
|
379
399
|
loop do
|
380
|
-
|
381
|
-
if
|
382
|
-
|
400
|
+
r15 = _nt_alphanumeric_char
|
401
|
+
if r15
|
402
|
+
s14 << r15
|
383
403
|
else
|
384
404
|
break
|
385
405
|
end
|
386
406
|
end
|
387
|
-
|
388
|
-
|
407
|
+
r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
|
408
|
+
s11 << r14
|
389
409
|
end
|
390
410
|
end
|
391
|
-
if
|
392
|
-
|
393
|
-
|
411
|
+
if s11.last
|
412
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
413
|
+
r11.extend(ModuleDeclaration0)
|
394
414
|
else
|
395
|
-
@index =
|
396
|
-
|
415
|
+
@index = i11
|
416
|
+
r11 = nil
|
397
417
|
end
|
398
|
-
if
|
399
|
-
|
418
|
+
if r11
|
419
|
+
s10 << r11
|
400
420
|
else
|
401
421
|
break
|
402
422
|
end
|
403
423
|
end
|
404
|
-
|
405
|
-
|
424
|
+
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
425
|
+
s6 << r10
|
406
426
|
end
|
407
427
|
end
|
408
|
-
if
|
409
|
-
|
410
|
-
|
428
|
+
if s6.last
|
429
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
430
|
+
r6.extend(ModuleDeclaration1)
|
411
431
|
else
|
412
|
-
@index =
|
413
|
-
|
432
|
+
@index = i6
|
433
|
+
r6 = nil
|
414
434
|
end
|
415
|
-
s1 <<
|
416
|
-
if
|
417
|
-
|
418
|
-
s1 <<
|
435
|
+
s1 << r6
|
436
|
+
if r6
|
437
|
+
r16 = _nt_space
|
438
|
+
s1 << r16
|
419
439
|
end
|
420
440
|
end
|
421
441
|
end
|
@@ -428,44 +448,44 @@ module Treetop
|
|
428
448
|
end
|
429
449
|
s0 << r1
|
430
450
|
if r1
|
431
|
-
|
432
|
-
|
433
|
-
if
|
434
|
-
|
435
|
-
|
451
|
+
i17 = index
|
452
|
+
r18 = _nt_module_declaration
|
453
|
+
if r18
|
454
|
+
r18 = SyntaxNode.new(input, (index-1)...index) if r18 == true
|
455
|
+
r17 = r18
|
436
456
|
else
|
437
|
-
|
438
|
-
if
|
439
|
-
|
440
|
-
|
457
|
+
r19 = _nt_grammar
|
458
|
+
if r19
|
459
|
+
r19 = SyntaxNode.new(input, (index-1)...index) if r19 == true
|
460
|
+
r17 = r19
|
441
461
|
else
|
442
|
-
@index =
|
443
|
-
|
462
|
+
@index = i17
|
463
|
+
r17 = nil
|
444
464
|
end
|
445
465
|
end
|
446
|
-
s0 <<
|
447
|
-
if
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
if
|
466
|
+
s0 << r17
|
467
|
+
if r17
|
468
|
+
i20, s20 = index, []
|
469
|
+
r21 = _nt_space
|
470
|
+
s20 << r21
|
471
|
+
if r21
|
452
472
|
if (match_len = has_terminal?('end', false, index))
|
453
|
-
|
473
|
+
r22 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
454
474
|
@index += match_len
|
455
475
|
else
|
456
476
|
terminal_parse_failure('\'end\'')
|
457
|
-
|
477
|
+
r22 = nil
|
458
478
|
end
|
459
|
-
|
479
|
+
s20 << r22
|
460
480
|
end
|
461
|
-
if
|
462
|
-
|
463
|
-
|
481
|
+
if s20.last
|
482
|
+
r20 = instantiate_node(SyntaxNode,input, i20...index, s20)
|
483
|
+
r20.extend(ModuleDeclaration3)
|
464
484
|
else
|
465
|
-
@index =
|
466
|
-
|
485
|
+
@index = i20
|
486
|
+
r20 = nil
|
467
487
|
end
|
468
|
-
s0 <<
|
488
|
+
s0 << r20
|
469
489
|
end
|
470
490
|
end
|
471
491
|
if s0.last
|
@@ -18,7 +18,7 @@ module Treetop
|
|
18
18
|
end
|
19
19
|
|
20
20
|
rule module_declaration
|
21
|
-
module_prefix:('module' space name:([A-Z] alphanumeric_char* ('::' [A-Z] alphanumeric_char*)*) space) module_contents:(module_declaration / grammar) suffix:(space 'end') {
|
21
|
+
module_prefix:(('module'/'class') space name:([A-Z] alphanumeric_char* ('::' [A-Z] alphanumeric_char*)*) space) module_contents:(module_declaration / grammar) suffix:(space 'end') {
|
22
22
|
def compile
|
23
23
|
module_prefix.text_value + module_contents.compile + suffix.text_value
|
24
24
|
end
|
data/lib/treetop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treetop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sobo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-07-
|
12
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polyglot
|