Skip to content

Commit

Permalink
fix LITERAL types returning true for is_opener and is_closer
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Jul 25, 2019
1 parent a76fb76 commit 71c3e90
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
*_fmt.jl
6 changes: 3 additions & 3 deletions src/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function is_prev_newline(x::PTree)
is_prev_newline(x.nodes[end])
end

is_closer(x::PTree) = x.val == "}" || x.val == ")" || x.val == "]"
is_closer(x::PTree) = x.typ === CSTParser.PUNCTUATION && (x.val == "}" || x.val == ")" || x.val == "]")
is_closer(x::CSTParser.EXPR) = x.kind === Tokens.RBRACE || x.kind === Tokens.RPAREN || x.kind === Tokens.RSQUARE

is_opener(x::PTree) = x.val == "{" || x.val == "(" || x.val == "["
is_opener(x::PTree) = x.typ === CSTParser.PUNCTUATION && (x.val == "{" || x.val == "(" || x.val == "[")
is_opener(x::CSTParser.EXPR) = x.kind === Tokens.LBRACE || x.kind === Tokens.LPAREN || x.kind === Tokens.LSQUARE

function pretty(x::CSTParser.EXPR, s::State)
Expand Down Expand Up @@ -356,7 +356,7 @@ function p_literal(x, s; include_quotes=true)
end
end

@info "" include_quotes lines x.val loc loc[2] sidx
# @info "" include_quotes lines x.val loc loc[2] sidx

t = PTree(CSTParser.StringH, -1, -1, 0, 0, nothing, PTree[], Ref(x))
for (i, l) in enumerate(lines)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,20 @@ end
\""")"""
@test format(str, 2, 10) == str_

str_ = """
str = \"""
begin
arg
end\"""
"""

str = """
str = \"""
begin
arg
end\"""
"""
@test format(str_) == str
end

@testset "notcode" begin
Expand Down

0 comments on commit 71c3e90

Please sign in to comment.