diff --git a/.gitignore b/.gitignore index 8f685a5..e937f39 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,6 @@ bin # Go workspace file go.work -go.work.sum \ No newline at end of file +go.work.sum + +ksl-vscode-extension/node_modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index d4deb83..e908a79 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,13 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Attach to Process", + "type": "go", + "request": "attach", + "mode": "local", + "processId": 0 + }, { "type": "antlr-debug", "request": "launch", diff --git a/go.mod b/go.mod index 4c7d294..32dfe39 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,24 @@ require ( github.com/authzed/spicedb v1.33.0 ) +require ( + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/gorilla/websocket v1.5.1 // indirect + github.com/iancoleman/strcase v0.3.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/sasha-s/go-deadlock v0.3.1 // indirect + github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect + github.com/tliron/commonlog v0.2.8 // indirect + github.com/tliron/kutil v0.3.11 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/term v0.20.0 // indirect +) + require ( github.com/authzed/authzed-go v0.11.2-0.20240507202708-8b150c491e4a // indirect github.com/authzed/cel-go v0.20.2 // indirect @@ -25,6 +43,7 @@ require ( github.com/rs/zerolog v1.32.0 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect github.com/stretchr/testify v1.9.0 // indirect + github.com/tliron/glsp v0.2.2 golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect diff --git a/go.sum b/go.sum index ea50d63..f827760 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/authzed/cel-go v0.20.2 h1:GlmLecGry7Z8HU0k+hmaHHUV05ZHrsFxduXHtIePvck github.com/authzed/cel-go v0.20.2/go.mod h1:pJHVFWbqUHV1J+klQoZubdKswlbxcsbojda3mye9kiU= github.com/authzed/spicedb v1.33.0 h1:HHEvUMEdenbb8gm194L6BB+jaabRRJT5mx1Bqf+QQz8= github.com/authzed/spicedb v1.33.0/go.mod h1:nYYRk+VeH559jKqSKNr70Uh64Sc9vdLjNQTGZtfeHQc= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -21,31 +23,52 @@ github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3Bop github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM= +github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= +github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/jzelinskie/stringz v0.0.3 h1:0GhG3lVMYrYtIvRbxvQI6zqRTT1P1xyQlpa0FhfUXas= github.com/jzelinskie/stringz v0.0.3/go.mod h1:hHYbgxJuNLRw91CmpuFsYEOyQqpDVFg8pvEh23vy4P0= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/planetscale/vtprotobuf v0.6.0 h1:nBeETjudeJ5ZgBHUz1fVHvbqUKnYOXNhsIEabROxmNA= github.com/planetscale/vtprotobuf v0.6.0/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= +github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= +github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U= +github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo= github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -56,6 +79,14 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tliron/commonlog v0.2.8 h1:vpKrEsZX4nlneC9673pXpeKqv3cFLxwpzNEZF1qiaQQ= +github.com/tliron/commonlog v0.2.8/go.mod h1:HgQZrJEuiKLLRvUixtPWGcmTmWWtKkCtywF6x9X5Spw= +github.com/tliron/glsp v0.2.2 h1:IKPfwpE8Lu8yB6Dayta+IyRMAbTVunudeauEgjXBt+c= +github.com/tliron/glsp v0.2.2/go.mod h1:GMVWDNeODxHzmDPvYbYTCs7yHVaEATfYtXiYJ9w1nBg= +github.com/tliron/kutil v0.3.11 h1:kongR0dhrrn9FR/3QRFoUfQe27t78/xQvrU9aXIy5bk= +github.com/tliron/kutil v0.3.11/go.mod h1:4IqOAAdpJuDxYbJxMv4nL8LSH0mPofSrdwIv8u99PDc= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= @@ -65,6 +96,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be h1:Zz7rLWqp0ApfsR/l7+zSHhY3PMiH2xqgxlfYfAfNpoU= diff --git a/internal/ksl-lsp/main.go b/internal/ksl-lsp/main.go new file mode 100644 index 0000000..b13a976 --- /dev/null +++ b/internal/ksl-lsp/main.go @@ -0,0 +1,181 @@ +package main + +import ( + "strings" + "unicode" + + "github.com/project-kessel/ksl-schema-language/pkg/ksl" + "github.com/tliron/commonlog" + "github.com/tliron/glsp" + protocol "github.com/tliron/glsp/protocol_3_16" + "github.com/tliron/glsp/server" + + // Must include a backend implementation + // See CommonLog for other options: https://github.com/tliron/commonlog + _ "github.com/tliron/commonlog/simple" +) + +const lsName = "KSL" + +var ( + version string = "0.0.1" + handler protocol.Handler +) + +type SourceFile struct { + Text string +} + +var files = map[string]*SourceFile{} + +func NewSourceFile(text string) *SourceFile { + return &SourceFile{ + Text: text, + } +} + +func main() { + // This increases logging verbosity (optional) + commonlog.Configure(1, nil) + _ = files + handler = protocol.Handler{ + Initialize: initialize, + Initialized: initialized, + Shutdown: shutdown, + SetTrace: setTrace, + TextDocumentCompletion: textDocumentCompletion, + TextDocumentDidOpen: textDocumentDidOpen, + TextDocumentDidChange: textDocumentDidChange, + TextDocumentDidClose: textDocumentDidClose, + } + + server := server.NewServer(&handler, lsName, false) + + server.RunStdio() +} + +func initialize(context *glsp.Context, params *protocol.InitializeParams) (any, error) { + capabilities := handler.CreateServerCapabilities() + + capabilities.CompletionProvider.TriggerCharacters = append(capabilities.CompletionProvider.TriggerCharacters, " ") + + return protocol.InitializeResult{ + Capabilities: capabilities, + ServerInfo: &protocol.InitializeResultServerInfo{ + Name: lsName, + Version: &version, + }, + }, nil +} + +func initialized(context *glsp.Context, params *protocol.InitializedParams) error { + commonlog.NewInfoMessage(0, "Initialized!") + return nil +} + +func shutdown(context *glsp.Context) error { + protocol.SetTraceValue(protocol.TraceValueOff) + return nil +} + +func setTrace(context *glsp.Context, params *protocol.SetTraceParams) error { + protocol.SetTraceValue(params.Value) + return nil +} + +func textDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) { + file, ok := files[params.TextDocument.URI] + if !ok { + return nil, nil + } + + index := params.Position.IndexIn(file.Text) + fragment := file.Text[:index] + fragment = strings.TrimRightFunc(fragment, unicode.IsLetter) + tokens, rule, err := ksl.GetNextTokens(strings.NewReader(fragment)) + if err != nil { + return nil, err + } + + completionItems := []protocol.CompletionItem{} + + for _, token := range tokens { + if token.Literal != nil { + completionItems = append(completionItems, literalCompletion(*token.Literal)) + } else { + switch token.Name { + case "ACCESS": + for _, kw := range []string{"public", "internal"} { + completionItems = append(completionItems, literalCompletion(kw)) + } + if rule == "relation" { + completionItems = append(completionItems, literalCompletion("private")) + } + case "CARDINALITY": + for _, kw := range []string{"AtMostOne", "ExactlyOne", "AtLeastOne", "Any"} { + completionItems = append(completionItems, literalCompletion(kw)) + } + } + } + } + + return completionItems, nil +} + +func literalCompletion(name string) protocol.CompletionItem { + kind := protocol.CompletionItemKindKeyword + + return protocol.CompletionItem{ + Label: name, + Kind: &kind, + Detail: &name, + InsertText: &name, + CommitCharacters: []string{" "}, + } +} + +func textDocumentDidOpen(context *glsp.Context, params *protocol.DidOpenTextDocumentParams) error { + uri := params.TextDocument.URI + sourceFile := SourceFile{ + Text: params.TextDocument.Text, + } + files[uri] = &sourceFile + return nil +} + +func textDocumentDidChange(context *glsp.Context, params *protocol.DidChangeTextDocumentParams) error { + sourceFile, ok := Get(params.TextDocument.URI) + if !ok { + return nil + } + + sourceFile.ApplyChanges(params.ContentChanges) + + return nil +} + +func textDocumentDidClose(context *glsp.Context, params *protocol.DidCloseTextDocumentParams) error { + Close(params.TextDocument.URI) + return nil +} + +func (s *SourceFile) ApplyChanges(changes []interface{}) { + for _, change := range changes { + switch c := change.(type) { + case protocol.TextDocumentContentChangeEvent: + startIndex, endIndex := c.Range.IndexesIn(s.Text) + s.Text = s.Text[:startIndex] + c.Text + s.Text[endIndex:] + case protocol.TextDocumentContentChangeEventWhole: + s.Text = c.Text + } + } +} + +func Get(URI string) (*SourceFile, bool) { + f, ok := files[URI] + return f, ok +} + +func Close(URI string) { + delete(files, URI) +} diff --git a/ksl-vscode-extension/.vscodeignore b/ksl-vscode-extension/.vscodeignore new file mode 100644 index 0000000..792d043 --- /dev/null +++ b/ksl-vscode-extension/.vscodeignore @@ -0,0 +1,2 @@ +**/*.ts +**/tsconfig.json \ No newline at end of file diff --git a/ksl-vscode-extension/LICENSE b/ksl-vscode-extension/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/ksl-vscode-extension/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/ksl-vscode-extension/README.md b/ksl-vscode-extension/README.md new file mode 100644 index 0000000..3568817 --- /dev/null +++ b/ksl-vscode-extension/README.md @@ -0,0 +1,10 @@ +# KSL Visual Studio Code Extension + +This extension provides syntax highlighting and various language support for the Kessel schema language. + +Available for install on the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=project-kessel.ksl-syntax) + +## Quick Start + +Open any KSL file to automatically activate the extension. The KSL status bar should appear in the bottom right corner of the window when opened to a KSL file. + diff --git a/ksl-vscode-extension/assets/ksl-icon.png b/ksl-vscode-extension/assets/ksl-icon.png new file mode 100644 index 0000000..b33367b Binary files /dev/null and b/ksl-vscode-extension/assets/ksl-icon.png differ diff --git a/ksl-vscode-extension/ksl-syntax-0.0.1.vsix b/ksl-vscode-extension/ksl-syntax-0.0.1.vsix new file mode 100644 index 0000000..7f8a394 Binary files /dev/null and b/ksl-vscode-extension/ksl-syntax-0.0.1.vsix differ diff --git a/ksl-vscode-extension/language-configuration.json b/ksl-vscode-extension/language-configuration.json new file mode 100644 index 0000000..c84bd06 --- /dev/null +++ b/ksl-vscode-extension/language-configuration.json @@ -0,0 +1,63 @@ +{ + "comments": { + "lineComment": "//" + }, + "brackets": [ + [ + "(", + ")" + ], + [ + "[", + "]" + ], + [ + "{", + "}" + ] + ], + "autoClosingPairs": [ + [ + "(", + ")" + ], + [ + "[", + "]" + ], + [ + "{", + "}" + ], + [ + "`", + "`" + ], + [ + "'", + "'" + ] + ], + "surroundingPairs": [ + [ + "(", + ")" + ], + [ + "[", + "]" + ], + [ + "{", + "}" + ], + [ + "`", + "`" + ], + [ + "'", + "'" + ] + ] +} diff --git a/ksl-vscode-extension/out/extension.js b/ksl-vscode-extension/out/extension.js new file mode 100644 index 0000000..2c39308 --- /dev/null +++ b/ksl-vscode-extension/out/extension.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.activate = activate; +exports.deactivate = deactivate; +const vscode = require("vscode"); +const node_1 = require("vscode-languageclient/node"); +let client; +function activate(context) { + // This line of code will only be executed once when your extension is activated + // TODO: Start server exe and communicate with it + let serverExe = context.extensionPath + '/out/ksl-lsp'; + let ServerOptions = { + command: serverExe + }; + let clientOptions = { + // Register the server for KSL source files + documentSelector: [ + { + scheme: "file", language: "ksl" + } + ], + synchronize: { + fileEvents: vscode.workspace.createFileSystemWatcher("**/*.ksl"), // Watch files with your language's extension + }, + }; + vscode.window.showInformationMessage("Starting language server"); + client = new node_1.LanguageClient("KSL", ServerOptions, clientOptions); + client.info("Client created!"); + let t = client.start(); + t.then(_ => client.info("Connected!"), err => client.error(err)); +} +function deactivate() { + if (!client) { + vscode.window.showWarningMessage("No active language server to stop."); + return undefined; + } + vscode.window.showInformationMessage("Stopping language server."); + return client.stop(); +} +//# sourceMappingURL=extension.js.map \ No newline at end of file diff --git a/ksl-vscode-extension/out/extension.js.map b/ksl-vscode-extension/out/extension.js.map new file mode 100644 index 0000000..2c97767 --- /dev/null +++ b/ksl-vscode-extension/out/extension.js.map @@ -0,0 +1 @@ +{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAUA,4BA2BC;AAED,gCAOG;AA9CH,iCAAgC;AAEhC,qDAIsC;AAEtC,IAAI,MAAsB,CAAC;AAE3B,SAAgB,QAAQ,CAAC,OAAgC;IAErD,gFAAgF;IAChF,iDAAiD;IACjD,IAAI,SAAS,GAAG,OAAO,CAAC,aAAa,GAAG,cAAc,CAAC;IACvD,IAAI,aAAa,GAAkB;QAC/B,OAAO,EAAE,SAAS;KACrB,CAAA;IAED,IAAI,aAAa,GAA0B;QACvC,2CAA2C;QAC3C,gBAAgB,EAAE;YACd;gBACI,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK;aAClC;SACJ;QACD,WAAW,EAAE;YACT,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,CAAC,UAAU,CAAC,EAAE,6CAA6C;SAClH;KAEJ,CAAA;IAED,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,0BAA0B,CAAC,CAAA;IAChE,MAAM,GAAG,IAAI,qBAAc,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IACjE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC9B,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;AACpE,CAAC;AAED,SAAgB,UAAU;IACtB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,oCAAoC,CAAC,CAAA;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,2BAA2B,CAAC,CAAA;IACjE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC"} \ No newline at end of file diff --git a/ksl-vscode-extension/out/ksl-lsp b/ksl-vscode-extension/out/ksl-lsp new file mode 100755 index 0000000..b017bda Binary files /dev/null and b/ksl-vscode-extension/out/ksl-lsp differ diff --git a/ksl-vscode-extension/package.json b/ksl-vscode-extension/package.json new file mode 100644 index 0000000..4bdf0a0 --- /dev/null +++ b/ksl-vscode-extension/package.json @@ -0,0 +1,49 @@ +{ + "name": "ksl-syntax", + "displayName": "Language Support for KSL", + "description": "Custom language syntax for KSL.", + "icon": "assets/ksl-icon.png", + "version": "0.0.1", + "publisher": "project-kessel", + "main": "./out/extension.js", + "activationEvents": [ + "workspaceContains:**/*.ksl" + ], + "engines": { + "vscode": "^1.75.0" + }, + "dependencies": { + "glob": "^11.0.0", + "vscode-languageclient": "^9.0.1" + }, + "devDependencies": { + "@types/vscode": "^1.75.0", + "@vscode/test-electron": "^2.3.9" + }, + "repository": { + "type": "git", + "url": "https://github.com/project-kessel/ksl-schema-language" + }, + "contributes": { + "languages": [ + { + "id": "ksl", + "aliases": [ + "KSL", + "ksl" + ], + "extensions": [ + ".ksl" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "ksl", + "scopeName": "source.ksl", + "path": "./syntaxes/ksl.tmLanguage.json" + } + ] + } +} \ No newline at end of file diff --git a/ksl-vscode-extension/src/extension.ts b/ksl-vscode-extension/src/extension.ts new file mode 100644 index 0000000..46d6ed0 --- /dev/null +++ b/ksl-vscode-extension/src/extension.ts @@ -0,0 +1,47 @@ +import * as vscode from 'vscode' + +import { + LanguageClient, + LanguageClientOptions, + ServerOptions, + } from 'vscode-languageclient/node'; + +let client: LanguageClient; + +export function activate(context: vscode.ExtensionContext) { + + // This line of code will only be executed once when your extension is activated + // TODO: Start server exe and communicate with it + let serverExe = context.extensionPath + '/out/ksl-lsp'; + let ServerOptions: ServerOptions = { + command: serverExe + } + + let clientOptions: LanguageClientOptions = { + // Register the server for KSL source files + documentSelector: [ + { + scheme: "file", language: "ksl" + } + ], + synchronize: { + fileEvents: vscode.workspace.createFileSystemWatcher("**/*.ksl"), // Watch files with your language's extension + }, + + } + + vscode.window.showInformationMessage("Starting language server") + client = new LanguageClient("KSL", ServerOptions, clientOptions); + client.info("Client created!") + let t = client.start(); + t.then(_ => client.info("Connected!"), err => client.error(err)) +} + +export function deactivate(): Thenable | undefined { + if (!client) { + vscode.window.showWarningMessage("No active language server to stop.") + return undefined; + } + vscode.window.showInformationMessage("Stopping language server.") + return client.stop(); + } \ No newline at end of file diff --git a/ksl-vscode-extension/syntaxes/ksl.tmLanguage.json b/ksl-vscode-extension/syntaxes/ksl.tmLanguage.json new file mode 100644 index 0000000..893ba09 --- /dev/null +++ b/ksl-vscode-extension/syntaxes/ksl.tmLanguage.json @@ -0,0 +1,292 @@ +{ + "scopeName": "source.ksl", + "name": "KSL", + "patterns": [ + { + "include": "#entity" + }, + { + "include": "#storage" + }, + { + "include": "#keywords" + }, + { + "include": "#constants" + }, + { + "include": "#punctuation" + }, + { + "include": "#comments" + } + ], + "repository": { + "storage": { + "patterns": [ + { + "name": "storage.modifier.ksl", + "match": "\\b(public|internal|private|allow_duplicates)\\b" + }, + { + "name": "storage.type.ksl", + "match": "\\b(AtMostOne|ExactlyOne|AtLeastOne|Any)\\b" + } + ] + }, + "keywords": { + "patterns": [ + { + "name": "keyword.other.ksl", + "match": "\\b(version|namespace|relation|as|and|or|unless)\\b" + }, + { + "name": "keyword.extension.ksl", + "match": "\\bextension\\b" + }, + { + "name": "keyword.type.ksl", + "match": "\\btype\\b" + }, + { + "name": "keyword.control.import.ksl", + "match": "\\b(import)\\b" + } + ] + }, + "constants": { + "patterns": [ + { + "name": "constant.numeric.ksl", + "match": "\\b[0-9]+(\\.[0-9]+)*\\b" + }, + { + "name": "constant.language.ksl", + "match": "\\b(bool)\\b" + } + ] + }, + "entity": { + "patterns": [ + { + "name": "entity.function.ksl", + "match": "\\b(public|private|internal)\\b\\s+(\\bextension\\b)\\s+(\\w+)\\(([^)]*)\\)", + "captures": { + "1": { + "name": "storage.modifier.ksl" + }, + "2": { + "name": "keyword.extension.ksl" + }, + "3": { + "name": "entity.name.function.ksl" + }, + "4": { + "patterns": [ + { + "name": "variable.parameter.ksl", + "match": "\\w+" + }, + { + "name": "punctuation.other.comma.ksl", + "match": "\\," + } + ] + } + } + }, + { + "name": "entity.import.ksl", + "match": "(\\bimport\\b)\\s+(\\w+)", + "captures": { + "1": { + "name": "keyword.control.import.ksl" + }, + "2": { + "name": "entity.name.import.ksl" + } + } + }, + { + "name": "entity.namespace.ksl", + "match": "(\\bnamespace\\b)\\s+(\\w+)", + "captures": { + "1": { + "name": "keyword.other.ksl" + }, + "2": { + "name": "entity.name.type.namespace.ksl" + } + } + }, + { + "match": "(@)(\\w+)\\.(\\w+)\\(", + "captures": { + "1": { + "name": "punctuation.other.call.ksl" + }, + "2": { + "name": "variable.other.ksl" + }, + "3": { + "name": "entity.name.function.support.ksl" + } + } + }, + { + "match": "\\b(public|private|internal)?\\b\\s*(\\btype\\b)\\s*(\\w+)", + "captures": { + "1": { + "name": "storage.modifier.ksl" + }, + "2": { + "name": "keyword.type.ksl" + }, + "3": { + "name": "entity.name.type.ksl" + } + } + } + ] + }, + "punctuation": { + "patterns": [ + { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.begin.bracket.curly.ksl" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.definition.end.bracket.curly.ksl" + } + }, + "patterns": [ + { + "include": "$self" + } + ] + }, + { + "begin": "\\(", + "beginCaptures": { + "0": { + "name": "punctuation.definition.begin.bracket.round.ksl" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.end.bracket.round.ksl" + } + }, + "patterns": [ + { + "include": "$self" + } + ] + }, + { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "punctuation.definition.begin.bracket.square.ksl" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "punctuation.definition.end.bracket.square.ksl" + } + }, + "patterns": [ + { + "include": "$self" + } + ] + }, + { + "begin": "`", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.ksl" + } + }, + "comment": "Templated strings", + "end": "`", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.ksl" + } + }, + "name": "string.quoted.template.ksl", + "patterns": [ + { + "include": "$self" + } + ] + }, + { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.ksl" + } + }, + "comment": "Regular strings", + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.ksl" + } + }, + "name": "string.quoted.regular.ksl", + "patterns": [ + { + "include": "$self" + } + ] + }, + { + "name": "punctuation.definition.variable.ksl", + "match": "\\$" + }, + { + "name": "punctuation.other.period.ksl", + "match": "\\." + }, + { + "name": "punctuation.other.comma.ksl", + "match": "\\," + }, + { + "name": "punctuation.other.colon.ksl", + "match": ":" + }, + { + "name": "punctuation.other.call.ksl", + "match": "@" + }, + { + "name": "punctuation.other.terminator.ksl", + "match": ";" + } + ] + }, + "comments": { + "patterns": [ + { + "name": "comment.line.double-slash.ksl", + "begin": "//", + "end": "(?=\\n)" + } + ] + } + }, + "fileTypes": [ + "ksl" + ] +} diff --git a/ksl-vscode-extension/tsconfig.json b/ksl-vscode-extension/tsconfig.json new file mode 100644 index 0000000..87e2970 --- /dev/null +++ b/ksl-vscode-extension/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "lib": ["es2020"], + "outDir": "out", + "rootDir": "src", + "sourceMap": true + }, + "include": ["src"] +} \ No newline at end of file diff --git a/pkg/ksl/compiler.go b/pkg/ksl/compiler.go index 37b2fe9..4222d0d 100644 --- a/pkg/ksl/compiler.go +++ b/pkg/ksl/compiler.go @@ -3,6 +3,7 @@ package ksl import ( "io" "slices" + "strings" "github.com/antlr4-go/antlr/v4" "github.com/project-kessel/ksl-schema-language/pkg/intermediate" @@ -33,6 +34,99 @@ func Compile(r io.Reader) (*intermediate.Namespace, error) { return converter.fileToNamespace(file) } +func GetNextTokens(r io.Reader) ([]TokenCandidate, string, error) { + data, err := io.ReadAll(r) + if err != nil { + return nil, "", err + } + + source := antlr.NewInputStream(string(data)) + lexer := parser.NewkslLexer(source) + tokens := antlr.NewCommonTokenStream(lexer, antlr.LexerDefaultTokenChannel) + interpreter := parser.NewkslParser(tokens) + interpreter.BuildParseTrees = true + l := &autoCompleteErrorListener{} + interpreter.RemoveErrorListeners() + interpreter.AddErrorListener(l) + + interpreter.File() + + var expectedTokenIntervals *antlr.IntervalSet + var activeRule string + if l.hasOtherErrors { + return nil, "", nil + } + + if l.hasExpectedTokensAtEOF { + expectedTokenIntervals = l.expectedTokens + activeRule = l.ruleAtEOF + } else { + //Do nothing for now- interacting with the parser at EOF causes a panic + //expectedTokenIntervals = interpreter.GetExpectedTokensWithinCurrentRule() + //activeRule = interpreter.GetRuleNames()[interpreter.GetParserRuleContext().GetRuleIndex()] + return nil, "", nil + } + + expectedTokens := []TokenCandidate{} + names := interpreter.SymbolicNames + values := interpreter.LiteralNames + for _, interval := range expectedTokenIntervals.GetIntervals() { + for tokenType := interval.Start; tokenType < interval.Stop; tokenType++ { + var text string + name := names[tokenType] + + if tokenType >= 0 && tokenType < len(values) { + text = values[tokenType] + } + + candidate := TokenCandidate{Name: name} + + if text != "" { + text = strings.Trim(text, "'") + candidate.Literal = &text + } + + expectedTokens = append(expectedTokens, candidate) + } + } + return expectedTokens, activeRule, nil //Gets symbolic names that are valid next, including optional ones. Doesn't break down composites like access and cardinality. + //Literals are available for keywords, but composites don't have one + +} + +type TokenCandidate struct { + Name string + Literal *string +} + +type autoCompleteErrorListener struct { + *antlr.DefaultErrorListener + hasExpectedTokensAtEOF bool + hasOtherErrors bool + expectedTokens *antlr.IntervalSet + ruleAtEOF string +} + +func (l *autoCompleteErrorListener) SyntaxError( + recognizer antlr.Recognizer, + offendingSymbol interface{}, + line, column int, + msg string, + e antlr.RecognitionException, +) { + token := offendingSymbol.(antlr.Token) + parser := recognizer.(antlr.Parser) + + if token.GetTokenType() == antlr.TokenEOF { + l.expectedTokens = parser.GetExpectedTokens() + ctx := parser.GetParserRuleContext() + l.ruleAtEOF = parser.GetRuleNames()[ctx.GetRuleIndex()] + l.hasExpectedTokensAtEOF = true + } else { + l.hasOtherErrors = true + } +} + type converter struct { imports []string }