Skip to content

Populate ScriptTokenStream and precise token bounds during AST construction #34

Closed

Description

@fupacat

Summary

During static analysis in SonarQube, issue reporting relies on TSqlFragment.firstTokenIndex, TSqlFragment.lastTokenIndex, and TSqlFragment.ScriptTokenStream (or token line/column positions) to highlight exact issue text ranges.

Problem

When parsing scripts via TSqlParser.parse(sql):

  1. TSqlScript.ScriptTokenStream is empty (size == 0).
  2. Child statement and expression nodes (TSqlFragment) have firstTokenIndex and lastTokenIndex set to 0, preventing downstream static analyzers from computing exact source line and column spans (file.newRange(startLine, startCol, endLine, endCol)).
  3. This causes issue highlights to fall back to statement or line 1 boundaries.

Proposed Solution

  1. Ensure the underlying lexer token stream is preserved and attached to the root TSqlScript.ScriptTokenStream.
  2. Ensure UpdateTokenInfo(first, last) is properly called during ANTLR AST node construction to set firstTokenIndex and lastTokenIndex on all parsed fragment nodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions