mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
feat(gitconfig): Add first version of gitconfig ast
This commit is contained in:
parent
948e3503de
commit
1dd6be38d8
@ -14,11 +14,7 @@ type ValueNotInEnumError struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e ValueNotInEnumError) Error() string {
|
func (e ValueNotInEnumError) Error() string {
|
||||||
if len(e.AvailableValues) <= 6 {
|
return fmt.Sprintf("This value is not an enum value. Select one from: %s", strings.Join(e.AvailableValues, ","))
|
||||||
return fmt.Sprintf("This value is not valid. Select one from: %s", strings.Join(e.AvailableValues, ","))
|
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("This value is not valid")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnumString struct {
|
type EnumString struct {
|
||||||
|
51
server/handlers/gitconfig/Config.g4
Normal file
51
server/handlers/gitconfig/Config.g4
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
grammar Config;
|
||||||
|
|
||||||
|
lineStatement
|
||||||
|
: entry EOF
|
||||||
|
;
|
||||||
|
|
||||||
|
entry
|
||||||
|
: WHITESPACE? key? separator? value? leadingComment?
|
||||||
|
;
|
||||||
|
|
||||||
|
leadingComment
|
||||||
|
: HASH WHITESPACE? (string WHITESPACE?)+
|
||||||
|
;
|
||||||
|
|
||||||
|
key
|
||||||
|
: string
|
||||||
|
;
|
||||||
|
|
||||||
|
separator
|
||||||
|
: EQUAL
|
||||||
|
;
|
||||||
|
|
||||||
|
value
|
||||||
|
: string
|
||||||
|
;
|
||||||
|
|
||||||
|
string
|
||||||
|
: (QUOTED_STRING | STRING)
|
||||||
|
;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
|
||||||
|
EQUAL
|
||||||
|
: '='
|
||||||
|
;
|
||||||
|
|
||||||
|
HASH
|
||||||
|
: '#'
|
||||||
|
;
|
||||||
|
|
||||||
|
WHITESPACE
|
||||||
|
: [ \t]+
|
||||||
|
;
|
||||||
|
|
||||||
|
STRING
|
||||||
|
: ~('#' | '\r' | '\n' | '"' | ' ' | '\t')+
|
||||||
|
;
|
||||||
|
|
||||||
|
QUOTED_STRING
|
||||||
|
: '"' WHITESPACE? (STRING WHITESPACE)* STRING? ('"')?
|
||||||
|
;
|
45
server/handlers/gitconfig/ast/error-listener.go
Normal file
45
server/handlers/gitconfig/ast/error-listener.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
|
||||||
|
"github.com/antlr4-go/antlr/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type errorListenerContext struct {
|
||||||
|
line uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
type errorListener struct {
|
||||||
|
*antlr.DefaultErrorListener
|
||||||
|
Errors []common.LSPError
|
||||||
|
context errorListenerContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *errorListener) SyntaxError(
|
||||||
|
recognizer antlr.Recognizer,
|
||||||
|
offendingSymbol interface{},
|
||||||
|
_ int,
|
||||||
|
character int,
|
||||||
|
message string,
|
||||||
|
error antlr.RecognitionException,
|
||||||
|
) {
|
||||||
|
line := d.context.line
|
||||||
|
d.Errors = append(d.Errors, common.LSPError{
|
||||||
|
Range: common.CreateSingleCharRange(uint32(line), uint32(character)),
|
||||||
|
Err: common.SyntaxError{
|
||||||
|
Message: message,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func createErrorListener(
|
||||||
|
line uint32,
|
||||||
|
) errorListener {
|
||||||
|
return errorListener{
|
||||||
|
Errors: make([]common.LSPError, 0),
|
||||||
|
context: errorListenerContext{
|
||||||
|
line: line,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
47
server/handlers/gitconfig/ast/gitconfig.go
Normal file
47
server/handlers/gitconfig/ast/gitconfig.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
"config-lsp/common/parser"
|
||||||
|
|
||||||
|
"github.com/emirpasic/gods/maps/treemap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GitKey struct {
|
||||||
|
common.LocationRange
|
||||||
|
Value parser.ParsedString
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitSeparator struct {
|
||||||
|
common.LocationRange
|
||||||
|
Value parser.ParsedString
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitValue struct {
|
||||||
|
common.LocationRange
|
||||||
|
Value parser.ParsedString
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitEntry struct {
|
||||||
|
common.LocationRange
|
||||||
|
Key *GitKey
|
||||||
|
Separator *GitSeparator
|
||||||
|
Value *GitValue
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitSectionHeader struct {
|
||||||
|
common.LocationRange
|
||||||
|
Title *parser.ParsedString
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitSection struct {
|
||||||
|
common.LocationRange
|
||||||
|
Entries *treemap.Map
|
||||||
|
Title *GitSectionHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
type GitConfig struct {
|
||||||
|
Sections []*GitSection
|
||||||
|
CommentLines map[uint32]struct{}
|
||||||
|
}
|
||||||
|
|
6
server/handlers/gitconfig/ast/gitconfig_fields.go
Normal file
6
server/handlers/gitconfig/ast/gitconfig_fields.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
func (c *GitConfig) Clear() {
|
||||||
|
c.Sections = []*GitSection{}
|
||||||
|
}
|
||||||
|
|
95
server/handlers/gitconfig/ast/listener.go
Normal file
95
server/handlers/gitconfig/ast/listener.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
commonparser "config-lsp/common/parser"
|
||||||
|
"config-lsp/handlers/gitconfig/ast/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
type gitconfigListenerContext struct {
|
||||||
|
line uint32
|
||||||
|
currentSection *GitSection
|
||||||
|
currentEntry *GitEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func createListenerContext() *gitconfigListenerContext {
|
||||||
|
context := new(gitconfigListenerContext)
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
|
type gitconfigParserListener struct {
|
||||||
|
*parser.BaseConfigListener
|
||||||
|
Config *GitConfig
|
||||||
|
Errors []common.LSPError
|
||||||
|
gitconfigContext *gitconfigListenerContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func createListener(
|
||||||
|
config *GitConfig,
|
||||||
|
context *gitconfigListenerContext,
|
||||||
|
) gitconfigParserListener {
|
||||||
|
return gitconfigParserListener{
|
||||||
|
Config: config,
|
||||||
|
Errors: make([]common.LSPError, 0),
|
||||||
|
gitconfigContext: context,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *gitconfigParserListener) EnterEntry(ctx *parser.EntryContext) {
|
||||||
|
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
||||||
|
location.ChangeBothLines(s.gitconfigContext.line)
|
||||||
|
|
||||||
|
s.gitconfigContext.currentEntry = &GitEntry{
|
||||||
|
LocationRange: location,
|
||||||
|
}
|
||||||
|
|
||||||
|
s.gitconfigContext.currentSection.Entries.Put(
|
||||||
|
location.Start.Line,
|
||||||
|
s.gitconfigContext.currentEntry,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *gitconfigParserListener) ExitEntry(ctx *parser.EntryContext) {
|
||||||
|
s.gitconfigContext.currentEntry = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *gitconfigParserListener) EnterKey(ctx *parser.KeyContext) {
|
||||||
|
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
||||||
|
location.ChangeBothLines(s.gitconfigContext.line)
|
||||||
|
|
||||||
|
text := ctx.GetText()
|
||||||
|
value := commonparser.ParseRawString(text, commonparser.FullFeatures)
|
||||||
|
|
||||||
|
s.gitconfigContext.currentEntry.Key = &GitKey{
|
||||||
|
LocationRange: location,
|
||||||
|
Value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *gitconfigParserListener) EnterSeparator(ctx *parser.SeparatorContext) {
|
||||||
|
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
||||||
|
location.ChangeBothLines(s.gitconfigContext.line)
|
||||||
|
|
||||||
|
text := ctx.GetText()
|
||||||
|
value := commonparser.ParseRawString(text, commonparser.FullFeatures)
|
||||||
|
|
||||||
|
s.gitconfigContext.currentEntry.Separator = &GitSeparator{
|
||||||
|
LocationRange: location,
|
||||||
|
Value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *gitconfigParserListener) EnterValue(ctx *parser.ValueContext) {
|
||||||
|
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
||||||
|
location.ChangeBothLines(s.gitconfigContext.line)
|
||||||
|
|
||||||
|
text := ctx.GetText()
|
||||||
|
value := commonparser.ParseRawString(text, commonparser.FullFeatures)
|
||||||
|
|
||||||
|
s.gitconfigContext.currentEntry.Value = &GitValue{
|
||||||
|
LocationRange: location,
|
||||||
|
Value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
148
server/handlers/gitconfig/ast/parser.go
Normal file
148
server/handlers/gitconfig/ast/parser.go
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
package ast
|
||||||
|
|
||||||
|
import (
|
||||||
|
"config-lsp/common"
|
||||||
|
"config-lsp/utils"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/antlr4-go/antlr/v4"
|
||||||
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGitConfig() *GitConfig {
|
||||||
|
config := &GitConfig{}
|
||||||
|
config.Clear()
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
var commentPattern = regexp.MustCompile(`^\s*#`)
|
||||||
|
var emptyLinePattern = regexp.MustCompile(`^\s*$`)
|
||||||
|
var headerPattern = regexp.MustCompile(`^\s*\[`)
|
||||||
|
|
||||||
|
func (c *GitConfig) Parse(input string) []common.LSPError {
|
||||||
|
errors := make([]common.LSPError, 0)
|
||||||
|
lines := utils.SplitIntoLines(input)
|
||||||
|
context := createListenerContext()
|
||||||
|
|
||||||
|
for rawLineNumber, line := range lines {
|
||||||
|
lineNumber := uint32(rawLineNumber)
|
||||||
|
|
||||||
|
if emptyLinePattern.MatchString(line) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if commentPattern.MatchString(line) {
|
||||||
|
c.CommentLines[lineNumber] = struct{}{}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if headerPattern.MatchString(line) {
|
||||||
|
c.parseHeader(context, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
errors = append(
|
||||||
|
errors,
|
||||||
|
c.parseStatement(context, line)...,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GitConfig) parseHeader(
|
||||||
|
context *gitconfigListenerContext,
|
||||||
|
input string,
|
||||||
|
) []protocol.Diagnostic {
|
||||||
|
leftBracketIndex := strings.Index(input, "[")
|
||||||
|
rightBracketIndex := strings.Index(input, "]")
|
||||||
|
|
||||||
|
if rightBracketIndex == -1 {
|
||||||
|
return []protocol.Diagnostic{
|
||||||
|
{
|
||||||
|
Range: protocol.Range{
|
||||||
|
Start: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: 0,
|
||||||
|
},
|
||||||
|
End: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: uint32(len(input)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Message: `This section title is missing a closing bracket "]"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if leftBracketIndex != 0 {
|
||||||
|
return []protocol.Diagnostic{
|
||||||
|
{
|
||||||
|
Range: protocol.Range{
|
||||||
|
Start: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: 0,
|
||||||
|
},
|
||||||
|
End: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: uint32(leftBracketIndex),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Message: `A section title should not have any characters before the opening bracket "["`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rightBracketIndex != len(input)-1 {
|
||||||
|
return []protocol.Diagnostic{
|
||||||
|
{
|
||||||
|
Range: protocol.Range{
|
||||||
|
Start: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: uint32(rightBracketIndex),
|
||||||
|
},
|
||||||
|
End: protocol.Position{
|
||||||
|
Line: context.line,
|
||||||
|
Character: uint32(len(input)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Message: `A section title should not have any characters after the closing bracket "]"`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *GitConfig) parseStatement(
|
||||||
|
context *gitconfigListenerContext,
|
||||||
|
input string,
|
||||||
|
) []common.LSPError {
|
||||||
|
stream := antlr.NewInputStream(input)
|
||||||
|
|
||||||
|
lexerErrorListener := createErrorListener(context.line)
|
||||||
|
lexer := parser.NewConfigLexer(stream)
|
||||||
|
lexer.RemoveErrorListeners()
|
||||||
|
lexer.AddErrorListener(&lexerErrorListener)
|
||||||
|
|
||||||
|
tokenStream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
|
||||||
|
|
||||||
|
parserErrorListener := createErrorListener(context.line)
|
||||||
|
antlrParser := parser.NewConfigParser(tokenStream)
|
||||||
|
antlrParser.RemoveErrorListeners()
|
||||||
|
antlrParser.AddErrorListener(&parserErrorListener)
|
||||||
|
|
||||||
|
listener := createListener(c, context)
|
||||||
|
antlr.ParseTreeWalkerDefault.Walk(
|
||||||
|
&listener,
|
||||||
|
antlrParser.LineStatement(),
|
||||||
|
)
|
||||||
|
|
||||||
|
errors := lexerErrorListener.Errors
|
||||||
|
errors = append(errors, parserErrorListener.Errors...)
|
||||||
|
errors = append(errors, listener.Errors...)
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
28
server/handlers/gitconfig/ast/parser/Config.interp
Normal file
28
server/handlers/gitconfig/ast/parser/Config.interp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
token literal names:
|
||||||
|
null
|
||||||
|
'='
|
||||||
|
'#'
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
|
||||||
|
token symbolic names:
|
||||||
|
null
|
||||||
|
EQUAL
|
||||||
|
HASH
|
||||||
|
WHITESPACE
|
||||||
|
STRING
|
||||||
|
QUOTED_STRING
|
||||||
|
|
||||||
|
rule names:
|
||||||
|
lineStatement
|
||||||
|
entry
|
||||||
|
leadingComment
|
||||||
|
key
|
||||||
|
separator
|
||||||
|
value
|
||||||
|
string
|
||||||
|
|
||||||
|
|
||||||
|
atn:
|
||||||
|
[4, 1, 5, 53, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 1, 0, 1, 0, 1, 0, 1, 1, 3, 1, 19, 8, 1, 1, 1, 3, 1, 22, 8, 1, 1, 1, 3, 1, 25, 8, 1, 1, 1, 3, 1, 28, 8, 1, 1, 1, 3, 1, 31, 8, 1, 1, 2, 1, 2, 3, 2, 35, 8, 2, 1, 2, 1, 2, 3, 2, 39, 8, 2, 4, 2, 41, 8, 2, 11, 2, 12, 2, 42, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 0, 0, 7, 0, 2, 4, 6, 8, 10, 12, 0, 1, 1, 0, 4, 5, 53, 0, 14, 1, 0, 0, 0, 2, 18, 1, 0, 0, 0, 4, 32, 1, 0, 0, 0, 6, 44, 1, 0, 0, 0, 8, 46, 1, 0, 0, 0, 10, 48, 1, 0, 0, 0, 12, 50, 1, 0, 0, 0, 14, 15, 3, 2, 1, 0, 15, 16, 5, 0, 0, 1, 16, 1, 1, 0, 0, 0, 17, 19, 5, 3, 0, 0, 18, 17, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 21, 1, 0, 0, 0, 20, 22, 3, 6, 3, 0, 21, 20, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 25, 3, 8, 4, 0, 24, 23, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 27, 1, 0, 0, 0, 26, 28, 3, 10, 5, 0, 27, 26, 1, 0, 0, 0, 27, 28, 1, 0, 0, 0, 28, 30, 1, 0, 0, 0, 29, 31, 3, 4, 2, 0, 30, 29, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 3, 1, 0, 0, 0, 32, 34, 5, 2, 0, 0, 33, 35, 5, 3, 0, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 40, 1, 0, 0, 0, 36, 38, 3, 12, 6, 0, 37, 39, 5, 3, 0, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 36, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 40, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 5, 1, 0, 0, 0, 44, 45, 3, 12, 6, 0, 45, 7, 1, 0, 0, 0, 46, 47, 5, 1, 0, 0, 47, 9, 1, 0, 0, 0, 48, 49, 3, 12, 6, 0, 49, 11, 1, 0, 0, 0, 50, 51, 7, 0, 0, 0, 51, 13, 1, 0, 0, 0, 8, 18, 21, 24, 27, 30, 34, 38, 42]
|
7
server/handlers/gitconfig/ast/parser/Config.tokens
Normal file
7
server/handlers/gitconfig/ast/parser/Config.tokens
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
EQUAL=1
|
||||||
|
HASH=2
|
||||||
|
WHITESPACE=3
|
||||||
|
STRING=4
|
||||||
|
QUOTED_STRING=5
|
||||||
|
'='=1
|
||||||
|
'#'=2
|
32
server/handlers/gitconfig/ast/parser/ConfigLexer.interp
Normal file
32
server/handlers/gitconfig/ast/parser/ConfigLexer.interp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
token literal names:
|
||||||
|
null
|
||||||
|
'='
|
||||||
|
'#'
|
||||||
|
null
|
||||||
|
null
|
||||||
|
null
|
||||||
|
|
||||||
|
token symbolic names:
|
||||||
|
null
|
||||||
|
EQUAL
|
||||||
|
HASH
|
||||||
|
WHITESPACE
|
||||||
|
STRING
|
||||||
|
QUOTED_STRING
|
||||||
|
|
||||||
|
rule names:
|
||||||
|
EQUAL
|
||||||
|
HASH
|
||||||
|
WHITESPACE
|
||||||
|
STRING
|
||||||
|
QUOTED_STRING
|
||||||
|
|
||||||
|
channel names:
|
||||||
|
DEFAULT_TOKEN_CHANNEL
|
||||||
|
HIDDEN
|
||||||
|
|
||||||
|
mode names:
|
||||||
|
DEFAULT_MODE
|
||||||
|
|
||||||
|
atn:
|
||||||
|
[4, 0, 5, 43, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 4, 2, 17, 8, 2, 11, 2, 12, 2, 18, 1, 3, 4, 3, 22, 8, 3, 11, 3, 12, 3, 23, 1, 4, 1, 4, 3, 4, 28, 8, 4, 1, 4, 1, 4, 1, 4, 5, 4, 33, 8, 4, 10, 4, 12, 4, 36, 9, 4, 1, 4, 3, 4, 39, 8, 4, 1, 4, 3, 4, 42, 8, 4, 0, 0, 5, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 1, 0, 2, 2, 0, 9, 9, 32, 32, 4, 0, 9, 10, 13, 13, 32, 32, 34, 35, 48, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 1, 11, 1, 0, 0, 0, 3, 13, 1, 0, 0, 0, 5, 16, 1, 0, 0, 0, 7, 21, 1, 0, 0, 0, 9, 25, 1, 0, 0, 0, 11, 12, 5, 61, 0, 0, 12, 2, 1, 0, 0, 0, 13, 14, 5, 35, 0, 0, 14, 4, 1, 0, 0, 0, 15, 17, 7, 0, 0, 0, 16, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 6, 1, 0, 0, 0, 20, 22, 8, 1, 0, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 8, 1, 0, 0, 0, 25, 27, 5, 34, 0, 0, 26, 28, 3, 5, 2, 0, 27, 26, 1, 0, 0, 0, 27, 28, 1, 0, 0, 0, 28, 34, 1, 0, 0, 0, 29, 30, 3, 7, 3, 0, 30, 31, 3, 5, 2, 0, 31, 33, 1, 0, 0, 0, 32, 29, 1, 0, 0, 0, 33, 36, 1, 0, 0, 0, 34, 32, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 38, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, 37, 39, 3, 7, 3, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 42, 5, 34, 0, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 10, 1, 0, 0, 0, 7, 0, 18, 23, 27, 34, 38, 41, 0]
|
7
server/handlers/gitconfig/ast/parser/ConfigLexer.tokens
Normal file
7
server/handlers/gitconfig/ast/parser/ConfigLexer.tokens
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
EQUAL=1
|
||||||
|
HASH=2
|
||||||
|
WHITESPACE=3
|
||||||
|
STRING=4
|
||||||
|
QUOTED_STRING=5
|
||||||
|
'='=1
|
||||||
|
'#'=2
|
64
server/handlers/gitconfig/ast/parser/config_base_listener.go
Normal file
64
server/handlers/gitconfig/ast/parser/config_base_listener.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Code generated from Config.g4 by ANTLR 4.13.0. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser // Config
|
||||||
|
|
||||||
|
import "github.com/antlr4-go/antlr/v4"
|
||||||
|
|
||||||
|
// BaseConfigListener is a complete listener for a parse tree produced by ConfigParser.
|
||||||
|
type BaseConfigListener struct{}
|
||||||
|
|
||||||
|
var _ ConfigListener = &BaseConfigListener{}
|
||||||
|
|
||||||
|
// VisitTerminal is called when a terminal node is visited.
|
||||||
|
func (s *BaseConfigListener) VisitTerminal(node antlr.TerminalNode) {}
|
||||||
|
|
||||||
|
// VisitErrorNode is called when an error node is visited.
|
||||||
|
func (s *BaseConfigListener) VisitErrorNode(node antlr.ErrorNode) {}
|
||||||
|
|
||||||
|
// EnterEveryRule is called when any rule is entered.
|
||||||
|
func (s *BaseConfigListener) EnterEveryRule(ctx antlr.ParserRuleContext) {}
|
||||||
|
|
||||||
|
// ExitEveryRule is called when any rule is exited.
|
||||||
|
func (s *BaseConfigListener) ExitEveryRule(ctx antlr.ParserRuleContext) {}
|
||||||
|
|
||||||
|
// EnterLineStatement is called when production lineStatement is entered.
|
||||||
|
func (s *BaseConfigListener) EnterLineStatement(ctx *LineStatementContext) {}
|
||||||
|
|
||||||
|
// ExitLineStatement is called when production lineStatement is exited.
|
||||||
|
func (s *BaseConfigListener) ExitLineStatement(ctx *LineStatementContext) {}
|
||||||
|
|
||||||
|
// EnterEntry is called when production entry is entered.
|
||||||
|
func (s *BaseConfigListener) EnterEntry(ctx *EntryContext) {}
|
||||||
|
|
||||||
|
// ExitEntry is called when production entry is exited.
|
||||||
|
func (s *BaseConfigListener) ExitEntry(ctx *EntryContext) {}
|
||||||
|
|
||||||
|
// EnterLeadingComment is called when production leadingComment is entered.
|
||||||
|
func (s *BaseConfigListener) EnterLeadingComment(ctx *LeadingCommentContext) {}
|
||||||
|
|
||||||
|
// ExitLeadingComment is called when production leadingComment is exited.
|
||||||
|
func (s *BaseConfigListener) ExitLeadingComment(ctx *LeadingCommentContext) {}
|
||||||
|
|
||||||
|
// EnterKey is called when production key is entered.
|
||||||
|
func (s *BaseConfigListener) EnterKey(ctx *KeyContext) {}
|
||||||
|
|
||||||
|
// ExitKey is called when production key is exited.
|
||||||
|
func (s *BaseConfigListener) ExitKey(ctx *KeyContext) {}
|
||||||
|
|
||||||
|
// EnterSeparator is called when production separator is entered.
|
||||||
|
func (s *BaseConfigListener) EnterSeparator(ctx *SeparatorContext) {}
|
||||||
|
|
||||||
|
// ExitSeparator is called when production separator is exited.
|
||||||
|
func (s *BaseConfigListener) ExitSeparator(ctx *SeparatorContext) {}
|
||||||
|
|
||||||
|
// EnterValue is called when production value is entered.
|
||||||
|
func (s *BaseConfigListener) EnterValue(ctx *ValueContext) {}
|
||||||
|
|
||||||
|
// ExitValue is called when production value is exited.
|
||||||
|
func (s *BaseConfigListener) ExitValue(ctx *ValueContext) {}
|
||||||
|
|
||||||
|
// EnterString is called when production string is entered.
|
||||||
|
func (s *BaseConfigListener) EnterString(ctx *StringContext) {}
|
||||||
|
|
||||||
|
// ExitString is called when production string is exited.
|
||||||
|
func (s *BaseConfigListener) ExitString(ctx *StringContext) {}
|
121
server/handlers/gitconfig/ast/parser/config_lexer.go
Normal file
121
server/handlers/gitconfig/ast/parser/config_lexer.go
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
// Code generated from Config.g4 by ANTLR 4.13.0. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/antlr4-go/antlr/v4"
|
||||||
|
"sync"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Suppress unused import error
|
||||||
|
var _ = fmt.Printf
|
||||||
|
var _ = sync.Once{}
|
||||||
|
var _ = unicode.IsLetter
|
||||||
|
|
||||||
|
type ConfigLexer struct {
|
||||||
|
*antlr.BaseLexer
|
||||||
|
channelNames []string
|
||||||
|
modeNames []string
|
||||||
|
// TODO: EOF string
|
||||||
|
}
|
||||||
|
|
||||||
|
var ConfigLexerLexerStaticData struct {
|
||||||
|
once sync.Once
|
||||||
|
serializedATN []int32
|
||||||
|
ChannelNames []string
|
||||||
|
ModeNames []string
|
||||||
|
LiteralNames []string
|
||||||
|
SymbolicNames []string
|
||||||
|
RuleNames []string
|
||||||
|
PredictionContextCache *antlr.PredictionContextCache
|
||||||
|
atn *antlr.ATN
|
||||||
|
decisionToDFA []*antlr.DFA
|
||||||
|
}
|
||||||
|
|
||||||
|
func configlexerLexerInit() {
|
||||||
|
staticData := &ConfigLexerLexerStaticData
|
||||||
|
staticData.ChannelNames = []string{
|
||||||
|
"DEFAULT_TOKEN_CHANNEL", "HIDDEN",
|
||||||
|
}
|
||||||
|
staticData.ModeNames = []string{
|
||||||
|
"DEFAULT_MODE",
|
||||||
|
}
|
||||||
|
staticData.LiteralNames = []string{
|
||||||
|
"", "'='", "'#'",
|
||||||
|
}
|
||||||
|
staticData.SymbolicNames = []string{
|
||||||
|
"", "EQUAL", "HASH", "WHITESPACE", "STRING", "QUOTED_STRING",
|
||||||
|
}
|
||||||
|
staticData.RuleNames = []string{
|
||||||
|
"EQUAL", "HASH", "WHITESPACE", "STRING", "QUOTED_STRING",
|
||||||
|
}
|
||||||
|
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
|
||||||
|
staticData.serializedATN = []int32{
|
||||||
|
4, 0, 5, 43, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2,
|
||||||
|
4, 7, 4, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 4, 2, 17, 8, 2, 11, 2, 12, 2, 18,
|
||||||
|
1, 3, 4, 3, 22, 8, 3, 11, 3, 12, 3, 23, 1, 4, 1, 4, 3, 4, 28, 8, 4, 1,
|
||||||
|
4, 1, 4, 1, 4, 5, 4, 33, 8, 4, 10, 4, 12, 4, 36, 9, 4, 1, 4, 3, 4, 39,
|
||||||
|
8, 4, 1, 4, 3, 4, 42, 8, 4, 0, 0, 5, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 1, 0,
|
||||||
|
2, 2, 0, 9, 9, 32, 32, 4, 0, 9, 10, 13, 13, 32, 32, 34, 35, 48, 0, 1, 1,
|
||||||
|
0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1,
|
||||||
|
0, 0, 0, 1, 11, 1, 0, 0, 0, 3, 13, 1, 0, 0, 0, 5, 16, 1, 0, 0, 0, 7, 21,
|
||||||
|
1, 0, 0, 0, 9, 25, 1, 0, 0, 0, 11, 12, 5, 61, 0, 0, 12, 2, 1, 0, 0, 0,
|
||||||
|
13, 14, 5, 35, 0, 0, 14, 4, 1, 0, 0, 0, 15, 17, 7, 0, 0, 0, 16, 15, 1,
|
||||||
|
0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19,
|
||||||
|
6, 1, 0, 0, 0, 20, 22, 8, 1, 0, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0,
|
||||||
|
0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 8, 1, 0, 0, 0, 25, 27, 5,
|
||||||
|
34, 0, 0, 26, 28, 3, 5, 2, 0, 27, 26, 1, 0, 0, 0, 27, 28, 1, 0, 0, 0, 28,
|
||||||
|
34, 1, 0, 0, 0, 29, 30, 3, 7, 3, 0, 30, 31, 3, 5, 2, 0, 31, 33, 1, 0, 0,
|
||||||
|
0, 32, 29, 1, 0, 0, 0, 33, 36, 1, 0, 0, 0, 34, 32, 1, 0, 0, 0, 34, 35,
|
||||||
|
1, 0, 0, 0, 35, 38, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, 37, 39, 3, 7, 3, 0,
|
||||||
|
38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 42, 5,
|
||||||
|
34, 0, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 10, 1, 0, 0, 0, 7,
|
||||||
|
0, 18, 23, 27, 34, 38, 41, 0,
|
||||||
|
}
|
||||||
|
deserializer := antlr.NewATNDeserializer(nil)
|
||||||
|
staticData.atn = deserializer.Deserialize(staticData.serializedATN)
|
||||||
|
atn := staticData.atn
|
||||||
|
staticData.decisionToDFA = make([]*antlr.DFA, len(atn.DecisionToState))
|
||||||
|
decisionToDFA := staticData.decisionToDFA
|
||||||
|
for index, state := range atn.DecisionToState {
|
||||||
|
decisionToDFA[index] = antlr.NewDFA(state, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigLexerInit initializes any static state used to implement ConfigLexer. By default the
|
||||||
|
// static state used to implement the lexer is lazily initialized during the first call to
|
||||||
|
// NewConfigLexer(). You can call this function if you wish to initialize the static state ahead
|
||||||
|
// of time.
|
||||||
|
func ConfigLexerInit() {
|
||||||
|
staticData := &ConfigLexerLexerStaticData
|
||||||
|
staticData.once.Do(configlexerLexerInit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewConfigLexer produces a new lexer instance for the optional input antlr.CharStream.
|
||||||
|
func NewConfigLexer(input antlr.CharStream) *ConfigLexer {
|
||||||
|
ConfigLexerInit()
|
||||||
|
l := new(ConfigLexer)
|
||||||
|
l.BaseLexer = antlr.NewBaseLexer(input)
|
||||||
|
staticData := &ConfigLexerLexerStaticData
|
||||||
|
l.Interpreter = antlr.NewLexerATNSimulator(l, staticData.atn, staticData.decisionToDFA, staticData.PredictionContextCache)
|
||||||
|
l.channelNames = staticData.ChannelNames
|
||||||
|
l.modeNames = staticData.ModeNames
|
||||||
|
l.RuleNames = staticData.RuleNames
|
||||||
|
l.LiteralNames = staticData.LiteralNames
|
||||||
|
l.SymbolicNames = staticData.SymbolicNames
|
||||||
|
l.GrammarFileName = "Config.g4"
|
||||||
|
// TODO: l.EOF = antlr.TokenEOF
|
||||||
|
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigLexer tokens.
|
||||||
|
const (
|
||||||
|
ConfigLexerEQUAL = 1
|
||||||
|
ConfigLexerHASH = 2
|
||||||
|
ConfigLexerWHITESPACE = 3
|
||||||
|
ConfigLexerSTRING = 4
|
||||||
|
ConfigLexerQUOTED_STRING = 5
|
||||||
|
)
|
52
server/handlers/gitconfig/ast/parser/config_listener.go
Normal file
52
server/handlers/gitconfig/ast/parser/config_listener.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Code generated from Config.g4 by ANTLR 4.13.0. DO NOT EDIT.
|
||||||
|
|
||||||
|
package parser // Config
|
||||||
|
|
||||||
|
import "github.com/antlr4-go/antlr/v4"
|
||||||
|
|
||||||
|
// ConfigListener is a complete listener for a parse tree produced by ConfigParser.
|
||||||
|
type ConfigListener interface {
|
||||||
|
antlr.ParseTreeListener
|
||||||
|
|
||||||
|
// EnterLineStatement is called when entering the lineStatement production.
|
||||||
|
EnterLineStatement(c *LineStatementContext)
|
||||||
|
|
||||||
|
// EnterEntry is called when entering the entry production.
|
||||||
|
EnterEntry(c *EntryContext)
|
||||||
|
|
||||||
|
// EnterLeadingComment is called when entering the leadingComment production.
|
||||||
|
EnterLeadingComment(c *LeadingCommentContext)
|
||||||
|
|
||||||
|
// EnterKey is called when entering the key production.
|
||||||
|
EnterKey(c *KeyContext)
|
||||||
|
|
||||||
|
// EnterSeparator is called when entering the separator production.
|
||||||
|
EnterSeparator(c *SeparatorContext)
|
||||||
|
|
||||||
|
// EnterValue is called when entering the value production.
|
||||||
|
EnterValue(c *ValueContext)
|
||||||
|
|
||||||
|
// EnterString is called when entering the string production.
|
||||||
|
EnterString(c *StringContext)
|
||||||
|
|
||||||
|
// ExitLineStatement is called when exiting the lineStatement production.
|
||||||
|
ExitLineStatement(c *LineStatementContext)
|
||||||
|
|
||||||
|
// ExitEntry is called when exiting the entry production.
|
||||||
|
ExitEntry(c *EntryContext)
|
||||||
|
|
||||||
|
// ExitLeadingComment is called when exiting the leadingComment production.
|
||||||
|
ExitLeadingComment(c *LeadingCommentContext)
|
||||||
|
|
||||||
|
// ExitKey is called when exiting the key production.
|
||||||
|
ExitKey(c *KeyContext)
|
||||||
|
|
||||||
|
// ExitSeparator is called when exiting the separator production.
|
||||||
|
ExitSeparator(c *SeparatorContext)
|
||||||
|
|
||||||
|
// ExitValue is called when exiting the value production.
|
||||||
|
ExitValue(c *ValueContext)
|
||||||
|
|
||||||
|
// ExitString is called when exiting the string production.
|
||||||
|
ExitString(c *StringContext)
|
||||||
|
}
|
1086
server/handlers/gitconfig/ast/parser/config_parser.go
Normal file
1086
server/handlers/gitconfig/ast/parser/config_parser.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,10 @@ ROOT=$(git rev-parse --show-toplevel)/server
|
|||||||
cd $ROOT/handlers/aliases && antlr4 -Dlanguage=Go -o ast/parser Aliases.g4
|
cd $ROOT/handlers/aliases && antlr4 -Dlanguage=Go -o ast/parser Aliases.g4
|
||||||
|
|
||||||
# fstab
|
# fstab
|
||||||
cd $ROOT/hanlders/fstab && antlr4 -Dlanguage=Go -o ast/parser Fstab.g4
|
cd $ROOT/handlers/fstab && antlr4 -Dlanguage=Go -o ast/parser Fstab.g4
|
||||||
|
|
||||||
|
# gitconfig
|
||||||
|
cd $ROOT/handlers/gitconfig && antlr4 -Dlanguage=Go -o ast/parser Config.g4
|
||||||
|
|
||||||
# sshd_config
|
# sshd_config
|
||||||
cd $ROOT/handlers/sshd_config && antlr4 -Dlanguage=Go -o ast/parser Config.g4
|
cd $ROOT/handlers/sshd_config && antlr4 -Dlanguage=Go -o ast/parser Config.g4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user