babel_bridge 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nodes/node.rb +3 -0
- data/lib/parser.rb +12 -3
- data/lib/tools.rb +2 -2
- data/lib/version.rb +1 -1
- data/spec/tools_spec.rb +13 -13
- metadata +1 -2
data/lib/nodes/node.rb
CHANGED
data/lib/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module BabelBridge
|
2
4
|
# primary object used by the client
|
3
5
|
# Used to generate the grammer with .rule methods
|
@@ -166,11 +168,18 @@ class Parser
|
|
166
168
|
# parser active at a time
|
167
169
|
attr_accessor :failure_index
|
168
170
|
attr_accessor :expecting_list
|
169
|
-
attr_accessor :src
|
171
|
+
attr_accessor :src, :source_file
|
170
172
|
attr_accessor :parse_cache
|
171
173
|
attr_accessor :failed_parse # gets set if the entire input was not matched
|
172
174
|
|
173
|
-
def
|
175
|
+
def relative_source_file
|
176
|
+
source_file && @relative_source_file ||= Pathname.new(File.expand_path(source_file)).relative_path_from(Pathname.getwd)
|
177
|
+
end
|
178
|
+
|
179
|
+
# options:
|
180
|
+
# :source_file => string
|
181
|
+
def initialize(options={})
|
182
|
+
@source_file = options[:source_file]
|
174
183
|
reset_parser_tracking
|
175
184
|
end
|
176
185
|
|
@@ -314,7 +323,7 @@ Parse path at failure:
|
|
314
323
|
Expecting#{expecting_list.length>1 ? ' one of' : ''}:
|
315
324
|
#{Tools.uniform_tabs(Tools.indent(expecting_list.values.collect do |a|
|
316
325
|
list=node_list_string(nodes_interesting_parse_path(a[:node]),common_root,options)
|
317
|
-
"#{a[:pattern].inspect}\t#{list}"
|
326
|
+
"#{a[:pattern].inspect}\t #{list}"
|
318
327
|
end.sort.join("\n")," "))}
|
319
328
|
ENDTXT
|
320
329
|
end
|
data/lib/tools.rb
CHANGED
@@ -11,12 +11,12 @@ class Tools
|
|
11
11
|
max_fields = lines.collect {|line| line.length}.max
|
12
12
|
max_fields.times do |field|
|
13
13
|
max_field_length = lines.collect {|line| (line[field]||"").length}.max
|
14
|
-
formatter = "%-#{max_field_length}s
|
14
|
+
formatter = "%-#{max_field_length}s"
|
15
15
|
lines.each_with_index do |line,i|
|
16
16
|
lines[i][field] = formatter%line[field] if line[field]
|
17
17
|
end
|
18
18
|
end
|
19
|
-
lines.collect {|line|line.join}.join("\n")
|
19
|
+
lines.collect {|line|line.join.rstrip}.join("\n")
|
20
20
|
end
|
21
21
|
|
22
22
|
# return the line and column of a given offset into this string
|
data/lib/version.rb
CHANGED
data/spec/tools_spec.rb
CHANGED
@@ -4,18 +4,18 @@ describe "Tools::" do
|
|
4
4
|
include TestParserGenerator
|
5
5
|
|
6
6
|
|
7
|
-
it "
|
8
|
-
""
|
9
|
-
" "
|
10
|
-
"a\nbb\nccc"
|
11
|
-
"a\nbb\nccc"
|
12
|
-
"a\nbb\nccc"
|
13
|
-
"a\nbb\nccc"
|
14
|
-
"a\nbb\nccc"
|
15
|
-
"a\nbb\nccc"
|
16
|
-
"a\nbb\nccc"
|
17
|
-
"a\nbb\nccc"
|
18
|
-
"a\nbb\nccc"
|
19
|
-
"a\nbb\nccc"
|
7
|
+
it "line_column" do
|
8
|
+
BabelBridge::Tools.line_column("", 0).should == [1,1]
|
9
|
+
BabelBridge::Tools.line_column(" ", 0).should == [1,1]
|
10
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 0).should == [1,1]
|
11
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 1).should == [1,2]
|
12
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 2).should == [2,1]
|
13
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 3).should == [2,2]
|
14
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 4).should == [2,3]
|
15
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 5).should == [3,1]
|
16
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 6).should == [3,2]
|
17
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 7).should == [3,3]
|
18
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 8).should == [3,4]
|
19
|
+
BabelBridge::Tools.line_column("a\nbb\nccc", 9).should == [3,4]
|
20
20
|
end
|
21
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babel_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -130,4 +130,3 @@ signing_key:
|
|
130
130
|
specification_version: 3
|
131
131
|
summary: A Ruby-based parser-generator based on Parsing Expression Grammars.
|
132
132
|
test_files: []
|
133
|
-
has_rdoc: false
|