Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f0bacbc6b332
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 79e8215eb27f
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 16, 2016

  1. Copy the full SHA
    5eeb2ba View commit details
  2. Copy the full SHA
    79e8215 View commit details
Showing with 30 additions and 4 deletions.
  1. +1 −1 spec/compiler/normalize/and_spec.cr
  2. +1 −1 spec/compiler/normalize/or_spec.cr
  3. +6 −0 spec/compiler/parser/to_s_spec.cr
  4. +22 −2 src/compiler/crystal/syntax/to_s.cr
2 changes: 1 addition & 1 deletion spec/compiler/normalize/and_spec.cr
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ describe "Normalize: and" do
end

it "normalizes and with ! on var.is_a?(...)" do
assert_expand_second "a = 1; !a.is_a?(Int32) && b", "if !a.is_a?(Int32)\n b\nelse\n !a.is_a?(Int32)\nend"
assert_expand_second "a = 1; !a.is_a?(Int32) && b", "if !(a.is_a?(Int32))\n b\nelse\n !(a.is_a?(Int32))\nend"
end

it "normalizes and with is_a? on exp" do
2 changes: 1 addition & 1 deletion spec/compiler/normalize/or_spec.cr
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ describe "Normalize: or" do
end

it "normalizes or with ! on var.is_a?(...)" do
assert_expand_second "a = 1; !a.is_a?(Int32) || b", "if !a.is_a?(Int32)\n !a.is_a?(Int32)\nelse\n b\nend"
assert_expand_second "a = 1; !a.is_a?(Int32) || b", "if !(a.is_a?(Int32))\n !(a.is_a?(Int32))\nelse\n b\nend"
end
end
6 changes: 6 additions & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
@@ -75,4 +75,10 @@ describe "ASTNode#to_s" do
expect_to_s %(def foo("bar baz" qux)\nend)
expect_to_s "foo()"
expect_to_s "/a/x"
expect_to_s "1_f32", "1_f32"
expect_to_s "1_f64", "1_f64"
expect_to_s "1.0", "1.0"
expect_to_s "1e10_f64", "1e10"
expect_to_s "!a"
expect_to_s "!(1 < 2)"
end
24 changes: 22 additions & 2 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
@@ -51,12 +51,31 @@ module Crystal

def visit(node : NumberLiteral)
@str << node.value
if node.kind != :i32 && node.kind != :f64

if needs_suffix?(node)
@str << "_"
@str << node.kind.to_s
end
end

def needs_suffix?(node : NumberLiteral)
case node.kind
when :i32
return false
when :f64
# If there's no '.' nor 'e', for example in `1_f64`,
# we need to include it (#3315)
node.value.each_char do |char|
case char
when '.', 'e'
return false
end
end
end

true
end

def visit(node : CharLiteral)
node.value.inspect(@str)
end
@@ -1029,7 +1048,8 @@ module Crystal

def visit(node : Not)
@str << "!"
node.exp.accept self
need_parens = need_parens(node.exp)
in_parenthesis(need_parens, node.exp)
false
end