Skip to content

Commit

Permalink
+ slices inspect as "string"@1234
Browse files Browse the repository at this point in the history
This enhances perception of slices as being 'just strings'. It also
makes output easier to read.
  • Loading branch information
kschiess committed Mar 1, 2011
1 parent 075f148 commit f05e00b
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 34 deletions.
16 changes: 8 additions & 8 deletions example/output/comments.out
@@ -1,8 +1,8 @@
[{:exp=>{:a=>slice("a", 3)}}, [{:exp=>{:a=>"a"@3}},
{:line=>slice("// line comment", 7)}, {:line=>"// line comment"@7},
{:exp=>{:a=>slice("a", 25)}}, {:exp=>{:a=>"a"@25}},
{:exp=>{:a=>slice("a", 27)}}, {:exp=>{:a=>"a"@27}},
{:exp=>[{:a=>slice("a", 29)}, {:line=>slice("// line comment", 31)}]}, {:exp=>[{:a=>"a"@29}, {:line=>"// line comment"@31}]},
{:exp=>[{:a=>slice("a", 49)}, {:multi=>slice("/* inline comment */", 51)}]}, {:exp=>[{:a=>"a"@49}, {:multi=>"/* inline comment */"@51}]},
{:exp=>{:a=>slice("a", 72)}}, {:exp=>{:a=>"a"@72}},
{:multi=>slice("/* multiline\n comment */", 77)}] {:multi=>"/* multiline\n comment */"@77}]
2 changes: 1 addition & 1 deletion example/output/documentation.out
@@ -1 +1 @@
slice("aaaa", 0) "aaaa"@0

This comment has been minimized.

Copy link
@ktlund

ktlund Mar 25, 2011

dette er en test

This comment has been minimized.

Copy link
@floere

floere Mar 25, 2011

Contributor

test lyktes :)

6 changes: 3 additions & 3 deletions example/output/erb.out
@@ -1,6 +1,6 @@
{:text=>[{:text=>slice("The value of x is ", 0)}, {:expression=>{:ruby=>slice(" x ", 21)}}, {:text=>slice(".", 26)}]} {:text=>[{:text=>"The value of x is "@0}, {:expression=>{:ruby=>" x "@21}}, {:text=>"."@26}]}
{:text=>[{:code=>{:ruby=>slice(" 1 + 2 ", 2)}}]} {:text=>[{:code=>{:ruby=>" 1 + 2 "@2}}]}
{:text=>[{:comment=>{:ruby=>slice(" commented ", 3)}}]} {:text=>[{:comment=>{:ruby=>" commented "@3}}]}
The not printed result of "a = 2". The not printed result of "a = 2".
The not printed non-evaluated comment "a = 1", see the value of a below. The not printed non-evaluated comment "a = 1", see the value of a below.
The nicely printed result. The nicely printed result.
Expand Down
14 changes: 7 additions & 7 deletions example/output/ip_address.out
@@ -1,9 +1,9 @@
0.0.0.0 -> {:ipv4=>slice("0.0.0.0", 0)} 0.0.0.0 -> {:ipv4=>"0.0.0.0"@0}
255.255.255.255 -> {:ipv4=>slice("255.255.255.255", 0)} 255.255.255.255 -> {:ipv4=>"255.255.255.255"@0}
255.255.255 -> Failed: Expected one of [IPV4, IPV6]. at line 1 char 1. 255.255.255 -> Failed: Expected one of [IPV4, IPV6]. at line 1 char 1.
1:2:3:4:5:6:7:8 -> {:ipv6=>slice("1:2:3:4:5:6:7:8", 0)} 1:2:3:4:5:6:7:8 -> {:ipv6=>"1:2:3:4:5:6:7:8"@0}
12AD:34FC:A453:1922:: -> {:ipv6=>slice("12AD:34FC:A453:1922::", 0)} 12AD:34FC:A453:1922:: -> {:ipv6=>"12AD:34FC:A453:1922::"@0}
12AD::34FC -> {:ipv6=>slice("12AD::34FC", 0)} 12AD::34FC -> {:ipv6=>"12AD::34FC"@0}
12AD:: -> {:ipv6=>slice("12AD::", 0)} 12AD:: -> {:ipv6=>"12AD::"@0}
:: -> {:ipv6=>slice("::", 0)} :: -> {:ipv6=>"::"@0}
1:2 -> Failed: Expected one of [IPV4, IPV6]. at line 1 char 1. 1:2 -> Failed: Expected one of [IPV4, IPV6]. at line 1 char 1.
4 changes: 2 additions & 2 deletions example/output/local.out
@@ -1,3 +1,3 @@
{:e=>slice("a", 0), :rec=>{:e=>slice("a", 1), :rec=>{:e=>slice("a", 2), :rec=>{:e=>slice("a", 3), :rec=>nil}}}} {:e=>"a"@0, :rec=>{:e=>"a"@1, :rec=>{:e=>"a"@2, :rec=>{:e=>"a"@3, :rec=>nil}}}}
e2:'aa' !. / e1:'a' rec:B e2:'aa' !. / e1:'a' rec:B
{:e1=>slice("a", 0), :rec=>{:e1=>slice("a", 1), :rec=>{:e2=>slice("aa", 2)}}} {:e1=>"a"@0, :rec=>{:e1=>"a"@1, :rec=>{:e2=>"aa"@2}}}
5 changes: 1 addition & 4 deletions example/output/minilisp.out
Expand Up @@ -2,7 +2,4 @@
:test, :test,
[:lambda, [:lambda,
[], [],
[:begin, [:begin, [:display, "something"@54], [:display, 1], [:display, 3.08]]]]
[:display, slice("something", 54)],
[:display, 1],
[:display, 3.08]]]]
6 changes: 3 additions & 3 deletions example/output/parens.out
@@ -1,8 +1,8 @@
(): {:l=>slice("(", 0), :m=>nil, :r=>slice(")", 1)} (1 parens) (): {:l=>"("@0, :m=>nil, :r=>")"@1} (1 parens)


(()): {:l=>slice("(", 0), :m=>{:l=>slice("(", 1), :m=>nil, :r=>slice(")", 2)}, :r=>slice(")", 3)} (2 parens) (()): {:l=>"("@0, :m=>{:l=>"("@1, :m=>nil, :r=>")"@2}, :r=>")"@3} (2 parens)


((((())))): {:l=>slice("(", 0), :m=>{:l=>slice("(", 1), :m=>{:l=>slice("(", 2), :m=>{:l=>slice("(", 3), :m=>{:l=>slice("(", 4), :m=>nil, :r=>slice(")", 5)}, :r=>slice(")", 6)}, :r=>slice(")", 7)}, :r=>slice(")", 8)}, :r=>slice(")", 9)} (5 parens) ((((())))): {:l=>"("@0, :m=>{:l=>"("@1, :m=>{:l=>"("@2, :m=>{:l=>"("@3, :m=>{:l=>"("@4, :m=>nil, :r=>")"@5}, :r=>")"@6}, :r=>")"@7}, :r=>")"@8}, :r=>")"@9} (5 parens)


((()): Failed to match sequence (l:'(' m:(BALANCED?)) at line 1 char 6. ((()): Failed to match sequence (l:'(' m:(BALANCED?)) at line 1 char 6.


2 changes: 1 addition & 1 deletion example/output/simple_xml.out
@@ -1,2 +1,2 @@
"verified" "verified"
{:o=>{:name=>slice("b", 1)}, :i=>"verified", :c=>{:name=>slice("a", 33)}} {:o=>{:name=>"b"@1}, :i=>"verified", :c=>{:name=>"a"@33}}
6 changes: 3 additions & 3 deletions example/output/string_parser.out
@@ -1,3 +1,3 @@
[#<struct IntLit text=slice("123", 0)>, [#<struct IntLit text="123"@0>,
#<struct IntLit text=slice("12345", 4)>, #<struct IntLit text="12345"@4>,
#<struct StringLit text=slice(" Some String with \\\"escapes\\\"", 11)>] #<struct StringLit text=" Some String with \\\"escapes\\\""@11>]
2 changes: 1 addition & 1 deletion lib/parslet/slice.rb
Expand Up @@ -105,7 +105,7 @@ def to_f


# Inspection & Debugging --------------------------------------------------- # Inspection & Debugging ---------------------------------------------------
def inspect def inspect
"slice(#{str.inspect}, #{offset})" str.inspect << "@#{offset}"
end end
end end


Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/examples_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
require 'open3' require 'open3'


describe "Regression examples from example/ directory" do describe "Regression on" do
Dir["example/*.rb"].each do |example| Dir["example/*.rb"].each do |example|
context example do context example do
# Generates a product path for a given example file. # Generates a product path for a given example file.
Expand Down
10 changes: 10 additions & 0 deletions spec/parslet/slice_spec.rb
Expand Up @@ -143,5 +143,15 @@
end end
end end
end end
describe "inspection and string conversion" do
describe "#inspect" do
subject { slice.inspect }
it { should == '"foobar"@40' }
end
describe "#to_s" do
subject { slice.to_s }
it { should == 'foobar' }
end
end
end end
end end

0 comments on commit f05e00b

Please sign in to comment.