mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package matchparser
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
parser2 "config-lsp/common/parsers/openssh-match-parser/parser"
|
|
"github.com/antlr4-go/antlr/v4"
|
|
)
|
|
|
|
func NewMatch() *Match {
|
|
match := new(Match)
|
|
match.Clear()
|
|
|
|
return match
|
|
}
|
|
|
|
func (m *Match) Clear() {
|
|
m.Entries = make([]*MatchEntry, 0)
|
|
}
|
|
|
|
func (m *Match) Parse(
|
|
input string,
|
|
line uint32,
|
|
startCharacter uint32,
|
|
) []common.LSPError {
|
|
context := createMatchListenerContext(line, startCharacter)
|
|
|
|
stream := antlr.NewInputStream(input)
|
|
|
|
lexerErrorListener := createErrorListener(context.line)
|
|
lexer := parser2.NewMatchLexer(stream)
|
|
lexer.RemoveErrorListeners()
|
|
lexer.AddErrorListener(&lexerErrorListener)
|
|
|
|
tokenStream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
|
|
|
|
parserErrorListener := createErrorListener(context.line)
|
|
antlrParser := parser2.NewMatchParser(tokenStream)
|
|
antlrParser.RemoveErrorListeners()
|
|
antlrParser.AddErrorListener(&parserErrorListener)
|
|
|
|
listener := createListener(m, context)
|
|
antlr.ParseTreeWalkerDefault.Walk(
|
|
&listener,
|
|
antlrParser.Root(),
|
|
)
|
|
|
|
errors := lexerErrorListener.Errors
|
|
errors = append(errors, parserErrorListener.Errors...)
|
|
errors = append(errors, listener.Errors...)
|
|
|
|
return errors
|
|
|
|
}
|