Skip to content

Commit 99d3d84

Browse files
authored
Merge pull request #15 from SAY-5/fix-tparens-end-position
fix: include closing paren in TParens end position
2 parents d0b9047 + d3d77e5 commit 99d3d84

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Compiler/Parse/Type.gren

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ term =
171171
|> Parser.skip (Parser.chompChar '(' (ExpectedChar '('))
172172
|> Parser.skip spaceParser
173173
|> Parser.keep expression
174-
|> Parser.keep Parser.getPosition
175174
|> Parser.skip (Parser.chompChar ')' (ExpectedChar ')'))
175+
|> Parser.keep Parser.getPosition
176176
, Parser.succeed (\record end -> SourcePosition.at start end record)
177177
|> Parser.keep recordParser
178178
|> Parser.keep Parser.getPosition

tests/src/Test/Compiler/Parse/Type.gren

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ tests =
9191
{ row = 1, col = 3 }
9292
(AST.TVar "a")
9393
)
94+
, test "Parenthesized end position includes closing paren" <| \_ ->
95+
Parser.run PT.expression Context.empty "(a)"
96+
|> expectLocatedExpression
97+
(SourcePosition.at
98+
{ row = 1, col = 1 }
99+
{ row = 1, col = 4 }
100+
(AST.TParens <|
101+
SourcePosition.at
102+
{ row = 1, col = 2 }
103+
{ row = 1, col = 3 }
104+
(AST.TVar "a")
105+
)
106+
)
94107
, test "Empty Record" <| \_ ->
95108
Parser.run PT.expression Context.empty "{ }"
96109
|> expectExpression
@@ -286,3 +299,13 @@ expectExpression expected result =
286299

287300
Ok { value } ->
288301
Expect.equal expected value
302+
303+
304+
expectLocatedExpression : (SourcePosition.Located a) -> Result (Array (Parser.DeadEnd c e)) (SourcePosition.Located a) -> Expectation
305+
expectLocatedExpression expected result =
306+
when result is
307+
Err err ->
308+
Expect.fail (Debug.toString err)
309+
310+
Ok value ->
311+
Expect.equal expected value

0 commit comments

Comments
 (0)