Skip to content

Commit 5cd4b20

Browse files
authored
Add source positional information to the AST (#63)
1 parent 4c5baf2 commit 5cd4b20

1,136 files changed

Lines changed: 455053 additions & 6753 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TsqlAstParser/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ class AstToJsonConverter
9494
["$type"] = node.GetType().Name
9595
};
9696

97+
// Emit positional information for fragments that have real tokens.
98+
// Synthesized fragments (no source tokens) have StartOffset == -1.
99+
if (node.StartOffset >= 0)
100+
{
101+
result["StartOffset"] = node.StartOffset;
102+
result["FragmentLength"] = node.FragmentLength;
103+
result["StartLine"] = node.StartLine;
104+
result["StartColumn"] = node.StartColumn;
105+
}
106+
97107
var type = node.GetType();
98108
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
99109

ast/adhoc_table_reference.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ast
44
// Syntax: OPENDATASOURCE('provider', 'connstr').'object'
55
// Uses AdHocDataSource from execute_statement.go
66
type AdHocTableReference struct {
7+
Fragment
78
DataSource *AdHocDataSource `json:"DataSource,omitempty"`
89
Object *SchemaObjectNameOrValueExpression `json:"Object,omitempty"`
910
Alias *Identifier `json:"Alias,omitempty"`
@@ -15,6 +16,7 @@ func (*AdHocTableReference) tableReference() {}
1516

1617
// SchemaObjectNameOrValueExpression represents either a schema object name or a value expression
1718
type SchemaObjectNameOrValueExpression struct {
19+
Fragment
1820
SchemaObjectName *SchemaObjectName `json:"SchemaObjectName,omitempty"`
1921
ValueExpression ScalarExpression `json:"ValueExpression,omitempty"`
2022
}

ast/alter_authorization_statement.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ast
22

33
// AlterAuthorizationStatement represents an ALTER AUTHORIZATION statement
44
type AlterAuthorizationStatement struct {
5+
Fragment
56
SecurityTargetObject *SecurityTargetObject
67
ToSchemaOwner bool
78
PrincipalName *Identifier

ast/alter_availability_group_statement.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package ast
22

33
// AlterAvailabilityGroupStatement represents ALTER AVAILABILITY GROUP statement
44
type AlterAvailabilityGroupStatement struct {
5-
Name *Identifier
6-
StatementType string // "Action", "AddDatabase", "RemoveDatabase", "AddReplica", "ModifyReplica", "RemoveReplica", "Set"
7-
Action AvailabilityGroupAction
8-
Databases []*Identifier
9-
Replicas []*AvailabilityReplica
10-
Options []AvailabilityGroupOption
5+
Fragment
6+
Name *Identifier
7+
StatementType string // "Action", "AddDatabase", "RemoveDatabase", "AddReplica", "ModifyReplica", "RemoveReplica", "Set"
8+
Action AvailabilityGroupAction
9+
Databases []*Identifier
10+
Replicas []*AvailabilityReplica
11+
Options []AvailabilityGroupOption
1112
}
1213

1314
func (s *AlterAvailabilityGroupStatement) node() {}
@@ -21,6 +22,7 @@ type AvailabilityGroupAction interface {
2122

2223
// AlterAvailabilityGroupAction represents simple actions like JOIN, ONLINE, OFFLINE
2324
type AlterAvailabilityGroupAction struct {
25+
Fragment
2426
ActionType string // "Join", "ForceFailoverAllowDataLoss", "Online", "Offline"
2527
}
2628

@@ -29,6 +31,7 @@ func (a *AlterAvailabilityGroupAction) availabilityGroupAction() {}
2931

3032
// AlterAvailabilityGroupFailoverAction represents FAILOVER action with options
3133
type AlterAvailabilityGroupFailoverAction struct {
34+
Fragment
3235
ActionType string // "Failover"
3336
Options []*AlterAvailabilityGroupFailoverOption
3437
}
@@ -38,6 +41,7 @@ func (a *AlterAvailabilityGroupFailoverAction) availabilityGroupAction() {}
3841

3942
// AlterAvailabilityGroupFailoverOption represents an option for failover action
4043
type AlterAvailabilityGroupFailoverOption struct {
44+
Fragment
4145
OptionKind string // "Target"
4246
Value ScalarExpression // StringLiteral for target server
4347
}

ast/alter_credential_statement.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ast
22

33
// AlterCredentialStatement represents an ALTER CREDENTIAL statement.
44
type AlterCredentialStatement struct {
5+
Fragment
56
Name *Identifier
67
Identity ScalarExpression
78
Secret ScalarExpression

0 commit comments

Comments
 (0)