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.
@@ -44,6 +44,9 @@ class Node
44
44
  @column
45
45
  end
46
46
 
47
+ def source_file; parser.source_file; end
48
+ def relative_source_file; parser.relative_source_file; end
49
+
47
50
  def to_s
48
51
  text
49
52
  end
@@ -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 initialize
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
@@ -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
@@ -1,4 +1,4 @@
1
1
  module BabelBridge
2
2
  # last release: 0.4.1
3
- VERSION = "0.5.0"
3
+ VERSION = "0.5.1"
4
4
  end
@@ -4,18 +4,18 @@ describe "Tools::" do
4
4
  include TestParserGenerator
5
5
 
6
6
 
7
- it "line_col" do
8
- "". line_col(0).should == [1,1]
9
- " ". line_col(0).should == [1,1]
10
- "a\nbb\nccc". line_col(0).should == [1,1]
11
- "a\nbb\nccc". line_col(1).should == [1,2]
12
- "a\nbb\nccc". line_col(2).should == [2,1]
13
- "a\nbb\nccc". line_col(3).should == [2,2]
14
- "a\nbb\nccc". line_col(4).should == [2,3]
15
- "a\nbb\nccc". line_col(5).should == [3,1]
16
- "a\nbb\nccc". line_col(6).should == [3,2]
17
- "a\nbb\nccc". line_col(7).should == [3,3]
18
- "a\nbb\nccc". line_col(8).should == [3,4]
19
- "a\nbb\nccc". line_col(9).should == [3,4]
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.0
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