antelope 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16bfd59509232d2d3ac2ae7a2fd3be25254836da
4
- data.tar.gz: 28f7a1a19695c03a3f22e0d4b4bcf3ddea518fd4
3
+ metadata.gz: 589dbe0a0efbde62a5437b07ade45e68dc624d13
4
+ data.tar.gz: 2b3e774c00a75aa76bb37288621c5d6e094dc9ea
5
5
  SHA512:
6
- metadata.gz: c89393e3efb8f38b932aefd49a5b7800879ca7d9a4bcbdc4a23f075f6bae1f5eb758904b6c602856834bb281ebf910ad0ffeb4af4fc2f6212c9813af121253e0
7
- data.tar.gz: 62bebf9be801f6408ed4603e401aab55d7e38224dd428073874255ba20e3b1892b9f79e5abb56a4a5bd9de8bbb55501f0c6854a2261ea99526e6b79f420eac67
6
+ metadata.gz: e0ab4508a37e1d0d32ec8a3c715d8ba3117e8a94b3aa370e16ec8a22d2183c86f4ad2c290d89c18736e3f10d120412922e0eb0466aec79c36dabcaf2aac354c3
7
+ data.tar.gz: 95c5614a000b96260bc277cc8cfff24505fb8d5ae6d7780ededb1178f92c3bce97525961004ee63f54ea319901add91f6a63abf68a0fd9c559680aedd014de56
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.2
3
4
  - 2.1.0
4
5
  - 2.0.0
5
6
  - 1.9.3
6
7
  - jruby-19mode
7
8
  script: bundle exec rspec -f d spec
9
+ sudo: false
@@ -118,7 +118,7 @@ module Antelope
118
118
  rules = state.rules.
119
119
  select { |r| r.active == active && r.succ? }.
120
120
  map(&:succ).to_set
121
- s = states.find { |st| rules <= st.rules } || begin
121
+ s = states.find { |st| rules.subset? st.rules } || begin
122
122
  s = State.new << rules
123
123
  compute_closure(s)
124
124
  states << s
@@ -21,7 +21,7 @@ module Antelope
21
21
  @line = 1
22
22
  @scanner.pos = 0
23
23
  until @scanner.eos?
24
- scan_tag || scan_until_tag || error!
24
+ scan_tag || scan_until_tag || scan_until_end
25
25
  end
26
26
 
27
27
  @tokens
@@ -30,7 +30,7 @@ module Antelope
30
30
  rescue SyntaxError => e
31
31
  start = [@scanner.pos - 8, 0].max
32
32
  stop = [@scanner.pos + 8, @scanner.string.length].min
33
- snip = @scanner.string[start..stop].strip.inspect
33
+ snip = @scanner.string[start..stop].inspect
34
34
  char = @scanner.string[@scanner.pos]
35
35
  char = if char
36
36
  char.inspect
@@ -38,8 +38,8 @@ module Antelope
38
38
  "EOF"
39
39
  end
40
40
 
41
- new_line = "#{@source}:#{@line}: unexpected #{char} " \
42
- "(near #{snip})"
41
+ new_line = "#{@source}:#{@line}:#{@scanner.pos}: "\
42
+ "unexpected #{char} (near #{snip})"
43
43
 
44
44
  raise e, e.message, [new_line, *e.backtrace]
45
45
  end
@@ -47,41 +47,36 @@ module Antelope
47
47
  private
48
48
 
49
49
  def scan_until_tag
50
- if value = @scanner.scan_until(/(\n|\%|\{|\}|\\)/)
50
+ case
51
+ when value = @scanner.scan_until(/(\%|\{|\}|\\)/)
51
52
  @scanner.pos -= 1
52
53
  tokens << [:text, value[0..-2]]
53
54
  end
54
55
  end
55
56
 
57
+ def scan_until_end
58
+ tokens << [:text, @scanner.scan(/.+/m)]
59
+ end
60
+
56
61
  def scan_tag
57
62
  case
58
63
  when @scanner.scan(/\\(\{\{|\}\}|\%)/)
59
64
  tokens << [:text, @scanner[1]]
60
- when @scanner.scan(/\n?\%\{/)
61
- update_line
62
- tokens << [:newline] if @scanner[0][0] == "\n"
65
+ when @scanner.scan(/\%\{/)
63
66
  scan_tag_start(:output_tag, :_, /\}/)
64
- when @scanner.scan(/\n\%/)
65
- update_line
66
- error! unless value = @scanner.scan_until(/\n/)
67
- @scanner.pos -= 1
67
+ when @scanner.scan(/\%/)
68
68
  tokens << [:tag, value]
69
- when @scanner.scan(/\n?\{\{=/)
69
+ when @scanner.scan(/\{\{=/)
70
70
  update_line
71
71
  scan_tag_start(:output_tag)
72
- when @scanner.scan(/\n?\{\{!/)
72
+ when @scanner.scan(/\{\{!/)
73
73
  update_line
74
74
  scan_tag_start(:comment_tag)
75
- when @scanner.scan(/\n?\{\{/)
76
- update_line
75
+ when @scanner.scan(/\{\{/)
77
76
  scan_tag_start(:tag)
78
- when @scanner.scan(/\n?\}\}/)
79
- update_line
77
+ when @scanner.scan(/\}\}/)
80
78
  @scanner.pos -= 2
81
79
  error!
82
- when @scanner.scan(/\n/)
83
- update_line
84
- tokens << [:newline]
85
80
  when @scanner.scan(/\{|\}|\%|\\/)
86
81
  tokens << [:text, @scanner[0]]
87
82
  else
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Antelope
4
4
  # The current running version of antelope.
5
- VERSION = "0.1.9".freeze
5
+ VERSION = "0.1.10".freeze
6
6
  end
@@ -6,7 +6,7 @@ describe Ace::Compiler do
6
6
  %}
7
7
 
8
8
  %require "#{VERSION}"
9
- %type "ruby"
9
+ %language "ruby"
10
10
 
11
11
  %terminal NUMBER
12
12
  %terminal SEMICOLON ";"
@@ -4,8 +4,8 @@ describe Ace::Scanner do
4
4
  expect(scan("%test \"a\" hi\n%%\nt: d { { } }\n%%\nhi\n")).to eq [
5
5
  [:directive, "test", ["a", "hi"]],
6
6
  [:second],
7
- [:label, "t"],
8
- [:part, "d"],
7
+ [:label, "t", nil],
8
+ [:part, "d", nil],
9
9
  [:block, "{ { } }"],
10
10
  [:third],
11
11
  [:copy, "\nhi\n"]
@@ -1,7 +1,7 @@
1
1
  describe Generation::Constructor do
2
2
  let(:grammar) { double("grammar") }
3
3
  let(:terminal) { token(:TERMINAL) }
4
- let(:epsilon) { token(nil, nil, :epsilon) }
4
+ let(:epsilon) { token(:epsilon) }
5
5
 
6
6
  subject { described_class.new(grammar) }
7
7
 
@@ -73,7 +73,7 @@ describe Generation::Constructor do
73
73
  end
74
74
 
75
75
  context "when given an array" do
76
- let(:terminal2) { token(:TERMINAL2) }
76
+ let(:terminal2) { token(:terminal, :TERMINAL2) }
77
77
 
78
78
  it "generates a set" do
79
79
  expect(subject.first([epsilon, terminal])).
@@ -85,11 +85,14 @@ describe Generation::Constructor do
85
85
 
86
86
  context "when given a nonterminal" do
87
87
  let(:grammar) { with_recognizer }
88
- let(:nonterminal) { token(:e, nil, :nonterminal) }
88
+ let(:nonterminal) { token(:nonterminal, :e) }
89
89
 
90
+ before do
91
+ p grammar.terminals
92
+ end
90
93
  it "generates a set" do
91
94
  expect(subject.first(nonterminal)).
92
- to eq [token(:IDENT), token(:STAR, "*")].to_set
95
+ to eq [token(:terminal, :IDENT), token(:terminal, :STAR, "*")].to_set
93
96
  end
94
97
  end
95
98
 
@@ -109,7 +112,7 @@ describe Generation::Constructor do
109
112
 
110
113
  context "when given a nonterminal" do
111
114
  let(:grammar) { with_recognizer }
112
- let(:nonterminal) { token(:l, nil, :nonterminal) }
115
+ let(:nonterminal) { token(:nonterminal, :l) }
113
116
 
114
117
  before do
115
118
  subject.productions.merge grammar.productions.values.flatten
@@ -117,15 +120,17 @@ describe Generation::Constructor do
117
120
 
118
121
  it "generates a set" do
119
122
  expect(subject.follow(nonterminal)).to eq [
120
- token(:EQUALS, "="),
121
- token(:"$")
123
+ token(:terminal, :EQUALS, "="),
124
+ token(:terminal, :"$end")
122
125
  ].to_set
123
126
  end
124
127
  end
125
128
  end
126
129
 
127
- def token(name = nil, value = nil, type = :terminal)
130
+
131
+
132
+ def token(type, name = nil, value = nil, ttype = nil, id = nil)
128
133
  type = Ace::Token.const_get(type.to_s.capitalize)
129
- type.new(name, value)
134
+ type.new(name, ttype, id, value)
130
135
  end
131
136
  end
@@ -29,9 +29,9 @@ _out << "hello\\n"
29
29
  _out << begin
30
30
  something
31
31
  end.to_s
32
- _out << "world\\n\\n"
32
+ _out << "\\nworld\\n\\n"
33
33
  thing
34
- _out << "a\\n\\n"
34
+ _out << "\\na\\n\\n"
35
35
  _out
36
36
  TEST
37
37
  end
@@ -1,4 +1,4 @@
1
- %type "ruby"
1
+ %language <ruby>
2
2
 
3
3
  %terminal IDENT
4
4
  %terminal STAR "*"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antelope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie