antelope 0.2.2 → 0.2.3

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: b92cf3cc4e8746993ec89f21f9eb97646787cbf1
4
- data.tar.gz: 2739de2a0326fa116232b6f6be22e1b771d87225
3
+ metadata.gz: 60074794e65864ae5447727e4984cde3a504f0a2
4
+ data.tar.gz: 30f5789883e6d9ed457f39cfbe9bb2e403e73e94
5
5
  SHA512:
6
- metadata.gz: 1bca5d306f74efc0f25f4823e288221e3b5c708a2f6a15e870254df602c617bfac7482c5871b6241a17c2fd81cad4bb83a132c7c04a44c2c035e14604faf85cd
7
- data.tar.gz: 22b68475fe03066f181006e21763707dd01102143998634b8938597d771a9bca7a776f5980702a55db87db6ad923b63434c14dd12be925a2d1c0cf40ccdf9653
6
+ metadata.gz: 6a0f05690c5a8cf167e2eac1dade2394b5d0e74c23b457c5aed225ad8416c9fd5aec77bb3ec60e9b6ac6c1d9bfcf62604accff5f1ed8d94f06b5cc746d10ca14
7
+ data.tar.gz: 8773be8140d656cbada7cd82dcf601577a3bbc0ec335d9bb07a0200ca2cafc538b19609c2c83ca98ae1b51e8945b04cb49616f9dc1a9f09fb409c224088fa852
data/bin/antelope CHANGED
@@ -4,4 +4,4 @@ $: << File.expand_path("../../lib", __FILE__)
4
4
  require "antelope"
5
5
  require "antelope/cli"
6
6
 
7
- Antelope::CLI.start(ARGV)
7
+ Antelope::CLI.start
@@ -99,7 +99,7 @@ module Antelope
99
99
  left = Token::Nonterminal.new(rule[:label])
100
100
  items = rule[:set].map { |_| find_token(_[0]) }
101
101
  prec = if rule[:prec].empty?
102
- items.select(&:terminal?).last
102
+ items.select(&:terminal?).first
103
103
  else
104
104
  rule[:prec].intern
105
105
  end
@@ -22,7 +22,7 @@ module Antelope
22
22
  def scan_first_part
23
23
  until @scanner.check(CONTENT_BOUNDRY)
24
24
  scan_first_copy || scan_first_directive ||
25
- scan_whitespace || error!
25
+ scan_whitespace || scan_comment || error!
26
26
  end
27
27
  end
28
28
 
@@ -32,7 +32,8 @@ module Antelope
32
32
  tokens << [:second]
33
33
 
34
34
  until @scanner.check(CONTENT_BOUNDRY)
35
- scan_second_rule || scan_whitespace || error!
35
+ scan_second_rule || scan_whitespace || scan_comment ||
36
+ error!
36
37
  end
37
38
  end
38
39
 
@@ -77,7 +78,7 @@ module Antelope
77
78
  while body
78
79
  scan_second_rule_prec || scan_second_rule_part ||
79
80
  scan_second_rule_or || scan_second_rule_block ||
80
- scan_whitespace || (body = false)
81
+ scan_whitespace || scan_comment || (body = false)
81
82
  end
82
83
  @scanner.scan(/;/)
83
84
  end
@@ -120,6 +120,16 @@ module Antelope
120
120
  end
121
121
  end
122
122
 
123
+ # Scans for a comment. If the next token is a number sign (#),
124
+ # it will consume all characters until the next newline.
125
+ #
126
+ # @return [Boolean] if a comment was matched.
127
+ def scan_comment
128
+ if @scanner.scan(/\#(.*)\n/)
129
+ @line += 1
130
+ end
131
+ end
132
+
123
133
  private
124
134
 
125
135
  # Raises an error.
@@ -176,10 +176,6 @@ module Antelope
176
176
  end
177
177
  end
178
178
 
179
- def ==(other)
180
- hash == other.hash if other.respond_to?(:hash)
181
- end
182
-
183
179
  alias_method :eql?, :==
184
180
 
185
181
  # Compares this class and another object, fuzzily. If the other
data/lib/antelope/cli.rb CHANGED
@@ -29,6 +29,11 @@ module Antelope
29
29
  end
30
30
  end
31
31
 
32
+ desc "version", "Displays the running version of antelope"
33
+ def version
34
+ puts "Antelope version #{Antelope::VERSION}"
35
+ end
36
+
32
37
  private
33
38
 
34
39
  # Compiles the given file, and then generates. If an error
@@ -68,29 +68,31 @@ module Antelope
68
68
  # @see Nullable#nullable?
69
69
  def generate_follow_set(token)
70
70
  # Set it to the empty set so we don't end up recursing.
71
- set = @follows[token] = Set.new
71
+ @follows[token] = Set.new
72
+ set = Set.new
72
73
 
73
74
  productions.each do |rule|
74
75
  items = rule.items
76
+ i = 0
75
77
 
76
78
  # Find all of the positions within the rule that our token
77
79
  # occurs, and then increment that position by one.
78
- positions = items.each_with_index.
79
- find_all { |t, _| t == token }.
80
- map(&:last).map(&:succ)
80
+ while i < items.size
81
+ next i += 1 unless items[i] == token
82
+ position = i.succ
81
83
 
82
- # Find the FIRST set of every item after our token, and
83
- # put that in our set.
84
- positions.map { |pos| first(items[pos..-1]) }.
85
- inject(set, :merge)
84
+ # Find the FIRST set of every item after our token, and
85
+ # put that in our set.
86
+ set.merge first(items[position..-1])
86
87
 
87
- positions.each do |pos|
88
88
  # If we're at the end of the rule...
89
- if pos == items.size || nullable?(items[pos..-1])
89
+ if position == items.size || nullable?(items[position..-1])
90
90
  # Then add the FOLLOW set of the left-hand side to our
91
91
  # set.
92
92
  set.merge follow(rule.label)
93
93
  end
94
+
95
+ i += 1
94
96
  end
95
97
  end
96
98
 
@@ -97,7 +97,8 @@ module Antelope
97
97
  # @return [void]
98
98
  # @see Follow#follow
99
99
  def augment_rules(state)
100
- state.rules.select { |x| x.position.zero? }.each do |rule|
100
+ state.rules.each do |rule|
101
+ next unless rule.position.zero?
101
102
  current_state = state
102
103
 
103
104
  label = rule.left.dup
@@ -95,7 +95,10 @@ module Antelope
95
95
  next
96
96
  end
97
97
 
98
- terminal = grammar.precedence_for(on)
98
+ terminal = if states[state].transitions.key?(on)
99
+ states[state].rules.
100
+ detect { |rule| rule.active.name == on }.precedence
101
+ end
99
102
  rule_part, other_part = data.sort_by { |(t, _)| t }
100
103
 
101
104
  conflict = proc do |result|
@@ -118,8 +121,6 @@ module Antelope
118
121
  detect { |rule| rule.active.name == on }
119
122
  })
120
123
 
121
- #conflicts[state][on] = [result, rule_part, other_part,
122
- # terminal, @rules[rule_part[1]].prec]
123
124
  conflicts[state][on] = hash
124
125
  end
125
126
 
@@ -1,17 +1,16 @@
1
1
  Productions:
2
2
  %len = grammar.all_productions.size.to_s.size
3
- %productions = grammar.all_productions.
4
- % map { |x| ["#{x.label} → #{x.items.join(' ')}", x.block] }
5
- %body = productions.map { |_| _.first.size }.max
6
- %productions.each_with_index do |prod, i|
7
- {{= sprintf("%#{len}s", i)}} {{= sprintf("%-#{body}s", prod[0])}} %{prod[1]}
3
+ %productions = recognizer.states.map(&:rules).inject(:merge).
4
+ % select(&:final?).map { |x| [x.to_s(false), x.production.block] }
5
+ %body = productions.map { |_| _[0].size }.max
6
+ %productions.each do |prod|
7
+ {{= sprintf("%-#{body}s", prod[0]) }} %{prod[1]}
8
8
  %end
9
9
 
10
- %if table.any? { |_, i| tableizer.conflicts[i].any? }
11
- No errors :)
12
- %else
10
+ % if table.each_with_index.any? { |_, i| tableizer.conflicts[i].each.
11
+ % select { |(_, v)| v[:result] == 0 || directives.output.verbose }.any? }
13
12
  Error:
14
- % table.each_with_index do |v, i|
13
+ % table.each_with_index do |_, i|
15
14
  % conflicts = tableizer.conflicts[i].each.
16
15
  % select { |(_, v)| v[:result] == 0 || directives.output.verbose }
17
16
  % next unless conflicts.any?
@@ -30,4 +29,6 @@ Error:
30
29
  % end
31
30
  % end
32
31
  % end
32
+ %else
33
+ No errors :)
33
34
  %end
@@ -1,10 +1,10 @@
1
1
  Productions:
2
2
  %len = grammar.all_productions.size.to_s.size
3
- %productions = grammar.all_productions.
4
- % map { |x| ["#{x.label} → #{x.items.join(' ')}", x.block] }
5
- %body = productions.map { |_| _.first.size }.max
6
- %productions.each_with_index do |prod, i|
7
- {{= sprintf("%#{len}s", i)}} {{= sprintf("%-#{body}s", prod[0])}} %{prod[1]}
3
+ %productions = recognizer.states.map(&:rules).inject(:merge).
4
+ % select(&:final?).map { |x| [x.to_s(false), x.production.block] }
5
+ %body = productions.map { |_| _[0].size }.max
6
+ %productions.each do |prod|
7
+ {{= sprintf("%-#{body}s", prod[0]) }} %{prod[1]}
8
8
  %end
9
9
 
10
10
  %if unused_symbols.any?
@@ -23,7 +23,6 @@ module Antelope
23
23
  end
24
24
 
25
25
  def result(binding = TOPLEVEL_BINDING.dup)
26
- # sue me.
27
26
  eval(parse, binding, fake_name, 0)
28
27
  end
29
28
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Antelope
4
4
  # The current running version of antelope.
5
- VERSION = "0.2.2".freeze
5
+ VERSION = "0.2.3".freeze
6
6
  end
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie