Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RD-11232 sql compiler crash parser computes a wrong line col #465

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class RawSqlSyntaxAnalyzer(val positions: Positions) extends Parsers(positions)
val source = StringSource(s)
val rawErrorListener = new RawSqlErrorListener()

val lexer = new PsqlLexer(CharStreams.fromString(s))
val striped = s.stripTrailing().stripSuffix("\r\n").stripSuffix("\n").stripSuffix("\r")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no risk there's another token later and we start to shift offsets?

Ah it's the whole code that gets stripped?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stripTrainling should remove all white space, no?
Why does it need the stripSuffix's after?

val lexer = new PsqlLexer(CharStreams.fromString(striped))
lexer.removeErrorListeners()
lexer.addErrorListener(rawErrorListener)

Expand Down
27 changes: 27 additions & 0 deletions sql-client/src/test/scala/raw/client/sql/TestSqlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,31 @@ class TestSqlParser extends AnyFunSuite {
}
}

test("newline after comment") {
val code = """select
| id,
| key,
| summary,
| project_key,
| status,
| assignee_display_name,
| assignee_account_id
|from
| "jira-danai".jira_backlog_issue
| limit 2
|--where
|-- assignee_display_name = 'yann';
| """.stripMargin
val result = doTest(code)
checkStartEnd(result)
}

private def checkStartEnd(result: ParseProgramResult) = {
val SqlProgramNode(stmt) = result.tree
assert(result.positions.getStart(stmt).isDefined)
assert(result.positions.getFinish(stmt).isDefined)
assert(result.positions.getStart(stmt).flatMap(_.optOffset).isDefined)
assert(result.positions.getFinish(stmt).flatMap(_.optOffset).isDefined)
}

}