treetop 1.6.7 → 1.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55889da79805c465a6953a7675a8c3e43b5c1fc3
4
- data.tar.gz: 18120ebea1f4c6f03da9b8122c8dc8a5174cff58
3
+ metadata.gz: f5cf78875bffce2e5a417f380e3c1b2e96ad9397
4
+ data.tar.gz: bf189a3e2bdd867b296e8872f33cd5b617e7c72a
5
5
  SHA512:
6
- metadata.gz: 345067c98fe054a4b4f9a24269f9b2ce2a1c52fbd26a6438d75fa0d94a8f73b31c26a91a0bf2b025687ca2fcb5848f4ae73d10bf21197271a796daf909558486
7
- data.tar.gz: c1a6ed80de69eb537b9c769a8052f1a1ca74759d367ce7f46a400469ffe61510cd71bc005249fe9d21162c8c96eaa61ccf01d54ba164c8d1fe4b377e2b3f21d3
6
+ metadata.gz: 148bdfbd93703196ce7ff227bf28af6cfdb62caa1f3f45bf59f69d9691e49709d7df2c1b088c8e01a933bd8012d38c5ad8678998e845048ccbf5650913086f55
7
+ data.tar.gz: c8bf7bd1b095ed2eee7c8cddb7872070be1c51cf37b448e10c7fd4d359c93e90afcc48a4cfd073f4aca9ad6189f6bb8cfa448cdf963a6c203315a7bd07b44b89
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/cjheath/treetop.svg)](https://travis-ci.org/cjheath/treetop)
2
+
1
3
  Support
2
4
  =======
3
5
 
@@ -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 module namespace, if specified).
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
- adjusted_path = path =~ /\.(treetop|tt)\Z/ ? path : path + '.treetop'
37
- File.open(adjusted_path) do |source_file|
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{"#{adjusted_path}"})
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
- r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
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
- r2 = nil
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
- r3 = _nt_space
333
- s1 << r3
334
- if r3
335
- i4, s4 = index, []
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
- r5 = true
357
+ r7 = true
338
358
  @index += 1
339
359
  else
340
360
  terminal_parse_failure('[A-Z]')
341
- r5 = nil
361
+ r7 = nil
342
362
  end
343
- s4 << r5
344
- if r5
345
- s6, i6 = [], index
363
+ s6 << r7
364
+ if r7
365
+ s8, i8 = [], index
346
366
  loop do
347
- r7 = _nt_alphanumeric_char
348
- if r7
349
- s6 << r7
367
+ r9 = _nt_alphanumeric_char
368
+ if r9
369
+ s8 << r9
350
370
  else
351
371
  break
352
372
  end
353
373
  end
354
- r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
355
- s4 << r6
356
- if r6
357
- s8, i8 = [], index
374
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
375
+ s6 << r8
376
+ if r8
377
+ s10, i10 = [], index
358
378
  loop do
359
- i9, s9 = index, []
379
+ i11, s11 = index, []
360
380
  if (match_len = has_terminal?('::', false, index))
361
- r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
381
+ r12 = instantiate_node(SyntaxNode,input, index...(index + match_len))
362
382
  @index += match_len
363
383
  else
364
384
  terminal_parse_failure('\'::\'')
365
- r10 = nil
385
+ r12 = nil
366
386
  end
367
- s9 << r10
368
- if r10
387
+ s11 << r12
388
+ if r12
369
389
  if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
370
- r11 = true
390
+ r13 = true
371
391
  @index += 1
372
392
  else
373
393
  terminal_parse_failure('[A-Z]')
374
- r11 = nil
394
+ r13 = nil
375
395
  end
376
- s9 << r11
377
- if r11
378
- s12, i12 = [], index
396
+ s11 << r13
397
+ if r13
398
+ s14, i14 = [], index
379
399
  loop do
380
- r13 = _nt_alphanumeric_char
381
- if r13
382
- s12 << r13
400
+ r15 = _nt_alphanumeric_char
401
+ if r15
402
+ s14 << r15
383
403
  else
384
404
  break
385
405
  end
386
406
  end
387
- r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
388
- s9 << r12
407
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
408
+ s11 << r14
389
409
  end
390
410
  end
391
- if s9.last
392
- r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
393
- r9.extend(ModuleDeclaration0)
411
+ if s11.last
412
+ r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
413
+ r11.extend(ModuleDeclaration0)
394
414
  else
395
- @index = i9
396
- r9 = nil
415
+ @index = i11
416
+ r11 = nil
397
417
  end
398
- if r9
399
- s8 << r9
418
+ if r11
419
+ s10 << r11
400
420
  else
401
421
  break
402
422
  end
403
423
  end
404
- r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
405
- s4 << r8
424
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
425
+ s6 << r10
406
426
  end
407
427
  end
408
- if s4.last
409
- r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
410
- r4.extend(ModuleDeclaration1)
428
+ if s6.last
429
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
430
+ r6.extend(ModuleDeclaration1)
411
431
  else
412
- @index = i4
413
- r4 = nil
432
+ @index = i6
433
+ r6 = nil
414
434
  end
415
- s1 << r4
416
- if r4
417
- r14 = _nt_space
418
- s1 << r14
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
- i15 = index
432
- r16 = _nt_module_declaration
433
- if r16
434
- r16 = SyntaxNode.new(input, (index-1)...index) if r16 == true
435
- r15 = r16
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
- r17 = _nt_grammar
438
- if r17
439
- r17 = SyntaxNode.new(input, (index-1)...index) if r17 == true
440
- r15 = r17
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 = i15
443
- r15 = nil
462
+ @index = i17
463
+ r17 = nil
444
464
  end
445
465
  end
446
- s0 << r15
447
- if r15
448
- i18, s18 = index, []
449
- r19 = _nt_space
450
- s18 << r19
451
- if r19
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
- r20 = instantiate_node(SyntaxNode,input, index...(index + match_len))
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
- r20 = nil
477
+ r22 = nil
458
478
  end
459
- s18 << r20
479
+ s20 << r22
460
480
  end
461
- if s18.last
462
- r18 = instantiate_node(SyntaxNode,input, i18...index, s18)
463
- r18.extend(ModuleDeclaration3)
481
+ if s20.last
482
+ r20 = instantiate_node(SyntaxNode,input, i20...index, s20)
483
+ r20.extend(ModuleDeclaration3)
464
484
  else
465
- @index = i18
466
- r18 = nil
485
+ @index = i20
486
+ r20 = nil
467
487
  end
468
- s0 << r18
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
@@ -2,7 +2,7 @@ module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 6
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,7 +1,7 @@
1
- module Test
1
+ class Test
2
2
  grammar Grammar
3
3
  rule foo
4
4
  'foo'
5
5
  end
6
6
  end
7
- end
7
+ end
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.7
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-20 00:00:00.000000000 Z
12
+ date: 2016-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polyglot