ascoders / ascoders/syntax-parser

SQL 语句前面存在空白行时,错误提示未能在正确的位置显示

Open
#12 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
479
Forks
43
PR merge metrics
No merged PRs in 30d

Description

当 SQL 语句前面存在空白行时,解析结果中的 error.suggestions.token 为`null`,导致无法正确提示发生错误的位置,现象如下:
![image](https://user-images.githubusercontent.com/5096493/79543244-b3179f00-80bf-11ea-8ed6-473dd1f9e347.png)

解析结果如下:
```json
{
"success": false,
"ast": null,
"cursorKeyPath": [],
"nextMatchings": [
{
"type": "string",
"value": "UPDATE"
},
{
"type": "string",
"value": "set"
},
{
"type": "string",
"value": "insert"
},
{
"type": "string",
"value": "create"
},
{
"type": "string",
"value": "select"
}
],
"error": {
"suggestions": [
{
"type": "string",
"value": "select"
},
{
"type": "string",
"value": "create"
},
{
"type": "string",
"value": "insert"
},
{
"type": "string",
"value": "set"
},
{
"type": "string",
"value": "UPDATE"
}
],
"token": null,
"reason": "incomplete"
},
"debugInfo": {
"tokens": [
{
"type": "word",
"value": "selec",
"position": [
2,
6
]
}
],
"callVisiterCount": 38,
"costs": {
"lexer": 0,
"parser": 0
}
}
}
```

Demo 中关于错误提示位置的处理:
https://github.com/ascoders/syntax-parser/blob/5818f52f7dbdcef610d2600aa1fb04b4a9e55fb7/src/demo/monaco-plugin/index.ts#L60-L72

期望结果:
未完整的语句,error.suggestion.token 能给出错误位置的token,如`{type: "string", value: "selec", position: [1, 6]}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the error-position handling in src/demo/monaco-plugin/index.ts at the linked lines, then trace how the parser produces error.suggestions.token for incomplete SQL. Reproduce the case with leading blank lines and verify that the returned token identifies the incomplete `selec` text at the correct position.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.