feat(sshd_config): Add separator field

This commit is contained in:
Myzel394 2024-09-11 22:54:16 +02:00
parent 6383fbba17
commit 01bda3b660
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
8 changed files with 220 additions and 75 deletions

View File

@ -5,7 +5,11 @@ lineStatement
; ;
entry entry
: WHITESPACE? key? WHITESPACE? value? WHITESPACE? leadingComment? : WHITESPACE? key? separator? value? WHITESPACE? leadingComment?
;
separator
: WHITESPACE
; ;
key key

View File

@ -68,6 +68,15 @@ func (s *sshParserListener) EnterKey(ctx *parser.KeyContext) {
} }
} }
func (s *sshParserListener) EnterSeparator(ctx *parser.SeparatorContext) {
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
location.ChangeBothLines(s.sshContext.line)
s.sshContext.currentOption.Separator = &SSHSeparator{
LocationRange: location,
}
}
func (s *sshParserListener) EnterValue(ctx *parser.ValueContext) { func (s *sshParserListener) EnterValue(ctx *parser.ValueContext) {
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext) location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
location.ChangeBothLines(s.sshContext.line) location.ChangeBothLines(s.sshContext.line)

View File

@ -15,10 +15,11 @@ NEWLINE
rule names: rule names:
lineStatement lineStatement
entry entry
separator
key key
value value
leadingComment leadingComment
atn: atn:
[4, 1, 4, 61, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 1, 0, 1, 0, 3, 0, 13, 8, 0, 1, 0, 1, 0, 3, 0, 17, 8, 0, 3, 0, 19, 8, 0, 1, 0, 1, 0, 1, 1, 3, 1, 24, 8, 1, 1, 1, 3, 1, 27, 8, 1, 1, 1, 3, 1, 30, 8, 1, 1, 1, 3, 1, 33, 8, 1, 1, 1, 3, 1, 36, 8, 1, 1, 1, 3, 1, 39, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 45, 8, 3, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 51, 8, 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 1, 0, 0, 0, 16, 21, 3, 10, 5, 0, 17, 19, 5, 2, 0, 0, 18, 17, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 21, 1, 0, 0, 0, 20, 12, 1, 0, 0, 0, 20, 14, 1, 0, 0, 0, 20, 18, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 23, 5, 0, 0, 1, 23, 1, 1, 0, 0, 0, 24, 26, 5, 2, 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 28, 1, 0, 0, 0, 27, 29, 3, 6, 3, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 4, 2, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 34, 1, 0, 0, 0, 33, 35, 3, 8, 4, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 37, 1, 0, 0, 0, 36, 38, 5, 2, 0, 0, 37, 36, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 3, 1, 0, 0, 0, 42, 43, 5, 2, 0, 0, 43, 5, 1, 0, 0, 0, 44, 45, 5, 3, 0, 0, 45, 7, 1, 0, 0, 0, 46, 47, 5, 3, 0, 0, 47, 49, 5, 2, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 51, 5, 3, 0, 0, 51, 9, 1, 0, 0, 0, 52, 54, 5, 1, 0, 0, 53, 55, 5, 2, 0, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 60, 1, 0, 0, 0, 56, 58, 5, 3, 0, 0, 57, 59, 5, 2, 0, 0, 58, 57, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 56, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 11, 1, 0, 0, 0, 13, 14, 18, 20, 25, 28, 31, 34, 37, 40, 48, 54, 58, 62]

View File

@ -33,6 +33,12 @@ func (s *BaseConfigListener) EnterEntry(ctx *EntryContext) {}
// ExitEntry is called when production entry is exited. // ExitEntry is called when production entry is exited.
func (s *BaseConfigListener) ExitEntry(ctx *EntryContext) {} func (s *BaseConfigListener) ExitEntry(ctx *EntryContext) {}
// 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) {}
// EnterKey is called when production key is entered. // EnterKey is called when production key is entered.
func (s *BaseConfigListener) EnterKey(ctx *KeyContext) {} func (s *BaseConfigListener) EnterKey(ctx *KeyContext) {}

View File

@ -14,6 +14,9 @@ type ConfigListener interface {
// EnterEntry is called when entering the entry production. // EnterEntry is called when entering the entry production.
EnterEntry(c *EntryContext) EnterEntry(c *EntryContext)
// EnterSeparator is called when entering the separator production.
EnterSeparator(c *SeparatorContext)
// EnterKey is called when entering the key production. // EnterKey is called when entering the key production.
EnterKey(c *KeyContext) EnterKey(c *KeyContext)
@ -29,6 +32,9 @@ type ConfigListener interface {
// ExitEntry is called when exiting the entry production. // ExitEntry is called when exiting the entry production.
ExitEntry(c *EntryContext) ExitEntry(c *EntryContext)
// ExitSeparator is called when exiting the separator production.
ExitSeparator(c *SeparatorContext)
// ExitKey is called when exiting the key production. // ExitKey is called when exiting the key production.
ExitKey(c *KeyContext) ExitKey(c *KeyContext)

View File

@ -39,37 +39,38 @@ func configParserInit() {
"", "HASH", "WHITESPACE", "STRING", "NEWLINE", "", "HASH", "WHITESPACE", "STRING", "NEWLINE",
} }
staticData.RuleNames = []string{ staticData.RuleNames = []string{
"lineStatement", "entry", "key", "value", "leadingComment", "lineStatement", "entry", "separator", "key", "value", "leadingComment",
} }
staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.PredictionContextCache = antlr.NewPredictionContextCache()
staticData.serializedATN = []int32{ staticData.serializedATN = []int32{
4, 1, 4, 61, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 4, 1, 4, 65, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4,
1, 0, 1, 0, 3, 0, 13, 8, 0, 1, 0, 1, 0, 3, 0, 17, 8, 0, 3, 0, 19, 8, 0, 2, 5, 7, 5, 1, 0, 1, 0, 3, 0, 15, 8, 0, 1, 0, 1, 0, 3, 0, 19, 8, 0, 3,
1, 0, 1, 0, 1, 1, 3, 1, 24, 8, 1, 1, 1, 3, 1, 27, 8, 1, 1, 1, 3, 1, 30, 0, 21, 8, 0, 1, 0, 1, 0, 1, 1, 3, 1, 26, 8, 1, 1, 1, 3, 1, 29, 8, 1, 1,
8, 1, 1, 1, 3, 1, 33, 8, 1, 1, 1, 3, 1, 36, 8, 1, 1, 1, 3, 1, 39, 8, 1, 1, 3, 1, 32, 8, 1, 1, 1, 3, 1, 35, 8, 1, 1, 1, 3, 1, 38, 8, 1, 1, 1, 3,
1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 45, 8, 3, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 51, 1, 41, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 3, 4, 49, 8, 4, 1, 4,
8, 4, 1, 4, 1, 4, 3, 4, 55, 8, 4, 4, 4, 57, 8, 4, 11, 4, 12, 4, 58, 1, 1, 4, 1, 5, 1, 5, 3, 5, 55, 8, 5, 1, 5, 1, 5, 3, 5, 59, 8, 5, 4, 5, 61,
4, 0, 0, 5, 0, 2, 4, 6, 8, 0, 0, 69, 0, 18, 1, 0, 0, 0, 2, 23, 1, 0, 0, 8, 5, 11, 5, 12, 5, 62, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 0, 72, 0,
0, 4, 40, 1, 0, 0, 0, 6, 44, 1, 0, 0, 0, 8, 48, 1, 0, 0, 0, 10, 19, 3, 20, 1, 0, 0, 0, 2, 25, 1, 0, 0, 0, 4, 42, 1, 0, 0, 0, 6, 44, 1, 0, 0, 0,
2, 1, 0, 11, 13, 5, 2, 0, 0, 12, 11, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 8, 48, 1, 0, 0, 0, 10, 52, 1, 0, 0, 0, 12, 21, 3, 2, 1, 0, 13, 15, 5, 2,
14, 1, 0, 0, 0, 14, 19, 3, 8, 4, 0, 15, 17, 5, 2, 0, 0, 16, 15, 1, 0, 0, 0, 0, 14, 13, 1, 0, 0, 0, 14, 15, 1, 0, 0, 0, 15, 16, 1, 0, 0, 0, 16, 21,
0, 16, 17, 1, 0, 0, 0, 17, 19, 1, 0, 0, 0, 18, 10, 1, 0, 0, 0, 18, 12, 3, 10, 5, 0, 17, 19, 5, 2, 0, 0, 18, 17, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0,
1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 19, 20, 1, 0, 0, 0, 20, 21, 5, 0, 0, 1, 19, 21, 1, 0, 0, 0, 20, 12, 1, 0, 0, 0, 20, 14, 1, 0, 0, 0, 20, 18, 1,
21, 1, 1, 0, 0, 0, 22, 24, 5, 2, 0, 0, 23, 22, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 23, 5, 0, 0, 1, 23, 1, 1, 0, 0, 0, 24,
0, 0, 24, 26, 1, 0, 0, 0, 25, 27, 3, 4, 2, 0, 26, 25, 1, 0, 0, 0, 26, 27, 26, 5, 2, 0, 0, 25, 24, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 28, 1, 0, 0,
1, 0, 0, 0, 27, 29, 1, 0, 0, 0, 28, 30, 5, 2, 0, 0, 29, 28, 1, 0, 0, 0, 0, 27, 29, 3, 6, 3, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31,
29, 30, 1, 0, 0, 0, 30, 32, 1, 0, 0, 0, 31, 33, 3, 6, 3, 0, 32, 31, 1, 1, 0, 0, 0, 30, 32, 3, 4, 2, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0,
0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 35, 1, 0, 0, 0, 34, 36, 5, 2, 0, 0, 35, 32, 34, 1, 0, 0, 0, 33, 35, 3, 8, 4, 0, 34, 33, 1, 0, 0, 0, 34, 35, 1,
34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 38, 1, 0, 0, 0, 37, 39, 3, 8, 4, 0, 0, 0, 35, 37, 1, 0, 0, 0, 36, 38, 5, 2, 0, 0, 37, 36, 1, 0, 0, 0, 37,
0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 3, 1, 0, 0, 0, 40, 41, 5, 38, 1, 0, 0, 0, 38, 40, 1, 0, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0,
3, 0, 0, 41, 5, 1, 0, 0, 0, 42, 43, 5, 3, 0, 0, 43, 45, 5, 2, 0, 0, 44, 0, 0, 40, 41, 1, 0, 0, 0, 41, 3, 1, 0, 0, 0, 42, 43, 5, 2, 0, 0, 43, 5,
42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 47, 5, 3, 0, 1, 0, 0, 0, 44, 45, 5, 3, 0, 0, 45, 7, 1, 0, 0, 0, 46, 47, 5, 3, 0, 0,
0, 47, 7, 1, 0, 0, 0, 48, 50, 5, 1, 0, 0, 49, 51, 5, 2, 0, 0, 50, 49, 1, 47, 49, 5, 2, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 50, 1,
0, 0, 0, 50, 51, 1, 0, 0, 0, 51, 56, 1, 0, 0, 0, 52, 54, 5, 3, 0, 0, 53, 0, 0, 0, 50, 51, 5, 3, 0, 0, 51, 9, 1, 0, 0, 0, 52, 54, 5, 1, 0, 0, 53,
55, 5, 2, 0, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 57, 1, 0, 0, 55, 5, 2, 0, 0, 54, 53, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 60, 1, 0, 0,
0, 56, 52, 1, 0, 0, 0, 57, 58, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 0, 56, 58, 5, 3, 0, 0, 57, 59, 5, 2, 0, 0, 58, 57, 1, 0, 0, 0, 58, 59,
1, 0, 0, 0, 59, 9, 1, 0, 0, 0, 13, 12, 16, 18, 23, 26, 29, 32, 35, 38, 1, 0, 0, 0, 59, 61, 1, 0, 0, 0, 60, 56, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0,
44, 50, 54, 58, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 11, 1, 0, 0, 0, 13, 14, 18,
20, 25, 28, 31, 34, 37, 40, 48, 54, 58, 62,
} }
deserializer := antlr.NewATNDeserializer(nil) deserializer := antlr.NewATNDeserializer(nil)
staticData.atn = deserializer.Deserialize(staticData.serializedATN) staticData.atn = deserializer.Deserialize(staticData.serializedATN)
@ -118,9 +119,10 @@ const (
const ( const (
ConfigParserRULE_lineStatement = 0 ConfigParserRULE_lineStatement = 0
ConfigParserRULE_entry = 1 ConfigParserRULE_entry = 1
ConfigParserRULE_key = 2 ConfigParserRULE_separator = 2
ConfigParserRULE_value = 3 ConfigParserRULE_key = 3
ConfigParserRULE_leadingComment = 4 ConfigParserRULE_value = 4
ConfigParserRULE_leadingComment = 5
) )
// ILineStatementContext is an interface to support dynamic dispatch. // ILineStatementContext is an interface to support dynamic dispatch.
@ -238,7 +240,7 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
var _la int var _la int
p.EnterOuterAlt(localctx, 1) p.EnterOuterAlt(localctx, 1)
p.SetState(18) p.SetState(20)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -247,12 +249,12 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 2, p.GetParserRuleContext()) { switch p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 2, p.GetParserRuleContext()) {
case 1: case 1:
{ {
p.SetState(10) p.SetState(12)
p.Entry() p.Entry()
} }
case 2: case 2:
p.SetState(12) p.SetState(14)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -261,7 +263,7 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
if _la == ConfigParserWHITESPACE { if _la == ConfigParserWHITESPACE {
{ {
p.SetState(11) p.SetState(13)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -271,12 +273,12 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
} }
{ {
p.SetState(14) p.SetState(16)
p.LeadingComment() p.LeadingComment()
} }
case 3: case 3:
p.SetState(16) p.SetState(18)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -285,7 +287,7 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
if _la == ConfigParserWHITESPACE { if _la == ConfigParserWHITESPACE {
{ {
p.SetState(15) p.SetState(17)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -299,7 +301,7 @@ func (p *ConfigParser) LineStatement() (localctx ILineStatementContext) {
goto errorExit goto errorExit
} }
{ {
p.SetState(20) p.SetState(22)
p.Match(ConfigParserEOF) p.Match(ConfigParserEOF)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -331,6 +333,7 @@ type IEntryContext interface {
AllWHITESPACE() []antlr.TerminalNode AllWHITESPACE() []antlr.TerminalNode
WHITESPACE(i int) antlr.TerminalNode WHITESPACE(i int) antlr.TerminalNode
Key() IKeyContext Key() IKeyContext
Separator() ISeparatorContext
Value() IValueContext Value() IValueContext
LeadingComment() ILeadingCommentContext LeadingComment() ILeadingCommentContext
@ -394,6 +397,22 @@ func (s *EntryContext) Key() IKeyContext {
return t.(IKeyContext) return t.(IKeyContext)
} }
func (s *EntryContext) Separator() ISeparatorContext {
var t antlr.RuleContext
for _, ctx := range s.GetChildren() {
if _, ok := ctx.(ISeparatorContext); ok {
t = ctx.(antlr.RuleContext)
break
}
}
if t == nil {
return nil
}
return t.(ISeparatorContext)
}
func (s *EntryContext) Value() IValueContext { func (s *EntryContext) Value() IValueContext {
var t antlr.RuleContext var t antlr.RuleContext
for _, ctx := range s.GetChildren() { for _, ctx := range s.GetChildren() {
@ -452,12 +471,12 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
var _la int var _la int
p.EnterOuterAlt(localctx, 1) p.EnterOuterAlt(localctx, 1)
p.SetState(23) p.SetState(25)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 3, p.GetParserRuleContext()) == 1 { if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 3, p.GetParserRuleContext()) == 1 {
{ {
p.SetState(22) p.SetState(24)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -468,35 +487,31 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
} else if p.HasError() { // JIM } else if p.HasError() { // JIM
goto errorExit goto errorExit
} }
p.SetState(26) p.SetState(28)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) == 1 { if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) == 1 {
{ {
p.SetState(25) p.SetState(27)
p.Key() p.Key()
} }
} else if p.HasError() { // JIM } else if p.HasError() { // JIM
goto errorExit goto errorExit
} }
p.SetState(29) p.SetState(31)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 5, p.GetParserRuleContext()) == 1 { if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 5, p.GetParserRuleContext()) == 1 {
{ {
p.SetState(28) p.SetState(30)
p.Match(ConfigParserWHITESPACE) p.Separator()
if p.HasError() {
// Recognition error - abort rule
goto errorExit
}
} }
} else if p.HasError() { // JIM } else if p.HasError() { // JIM
goto errorExit goto errorExit
} }
p.SetState(32) p.SetState(34)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -505,12 +520,12 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
if _la == ConfigParserSTRING { if _la == ConfigParserSTRING {
{ {
p.SetState(31) p.SetState(33)
p.Value() p.Value()
} }
} }
p.SetState(35) p.SetState(37)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -519,7 +534,7 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
if _la == ConfigParserWHITESPACE { if _la == ConfigParserWHITESPACE {
{ {
p.SetState(34) p.SetState(36)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -528,7 +543,7 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
} }
} }
p.SetState(38) p.SetState(40)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -537,7 +552,7 @@ func (p *ConfigParser) Entry() (localctx IEntryContext) {
if _la == ConfigParserHASH { if _la == ConfigParserHASH {
{ {
p.SetState(37) p.SetState(39)
p.LeadingComment() p.LeadingComment()
} }
@ -556,6 +571,102 @@ errorExit:
goto errorExit // Trick to prevent compiler error if the label is not used goto errorExit // Trick to prevent compiler error if the label is not used
} }
// ISeparatorContext is an interface to support dynamic dispatch.
type ISeparatorContext interface {
antlr.ParserRuleContext
// GetParser returns the parser.
GetParser() antlr.Parser
// Getter signatures
WHITESPACE() antlr.TerminalNode
// IsSeparatorContext differentiates from other interfaces.
IsSeparatorContext()
}
type SeparatorContext struct {
antlr.BaseParserRuleContext
parser antlr.Parser
}
func NewEmptySeparatorContext() *SeparatorContext {
var p = new(SeparatorContext)
antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1)
p.RuleIndex = ConfigParserRULE_separator
return p
}
func InitEmptySeparatorContext(p *SeparatorContext) {
antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, nil, -1)
p.RuleIndex = ConfigParserRULE_separator
}
func (*SeparatorContext) IsSeparatorContext() {}
func NewSeparatorContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SeparatorContext {
var p = new(SeparatorContext)
antlr.InitBaseParserRuleContext(&p.BaseParserRuleContext, parent, invokingState)
p.parser = parser
p.RuleIndex = ConfigParserRULE_separator
return p
}
func (s *SeparatorContext) GetParser() antlr.Parser { return s.parser }
func (s *SeparatorContext) WHITESPACE() antlr.TerminalNode {
return s.GetToken(ConfigParserWHITESPACE, 0)
}
func (s *SeparatorContext) GetRuleContext() antlr.RuleContext {
return s
}
func (s *SeparatorContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
return antlr.TreesStringTree(s, ruleNames, recog)
}
func (s *SeparatorContext) EnterRule(listener antlr.ParseTreeListener) {
if listenerT, ok := listener.(ConfigListener); ok {
listenerT.EnterSeparator(s)
}
}
func (s *SeparatorContext) ExitRule(listener antlr.ParseTreeListener) {
if listenerT, ok := listener.(ConfigListener); ok {
listenerT.ExitSeparator(s)
}
}
func (p *ConfigParser) Separator() (localctx ISeparatorContext) {
localctx = NewSeparatorContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 4, ConfigParserRULE_separator)
p.EnterOuterAlt(localctx, 1)
{
p.SetState(42)
p.Match(ConfigParserWHITESPACE)
if p.HasError() {
// Recognition error - abort rule
goto errorExit
}
}
errorExit:
if p.HasError() {
v := p.GetError()
localctx.SetException(v)
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
p.SetError(nil)
}
p.ExitRule()
return localctx
goto errorExit // Trick to prevent compiler error if the label is not used
}
// IKeyContext is an interface to support dynamic dispatch. // IKeyContext is an interface to support dynamic dispatch.
type IKeyContext interface { type IKeyContext interface {
antlr.ParserRuleContext antlr.ParserRuleContext
@ -628,10 +739,10 @@ func (s *KeyContext) ExitRule(listener antlr.ParseTreeListener) {
func (p *ConfigParser) Key() (localctx IKeyContext) { func (p *ConfigParser) Key() (localctx IKeyContext) {
localctx = NewKeyContext(p, p.GetParserRuleContext(), p.GetState()) localctx = NewKeyContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 4, ConfigParserRULE_key) p.EnterRule(localctx, 6, ConfigParserRULE_key)
p.EnterOuterAlt(localctx, 1) p.EnterOuterAlt(localctx, 1)
{ {
p.SetState(40) p.SetState(44)
p.Match(ConfigParserSTRING) p.Match(ConfigParserSTRING)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -734,14 +845,14 @@ func (s *ValueContext) ExitRule(listener antlr.ParseTreeListener) {
func (p *ConfigParser) Value() (localctx IValueContext) { func (p *ConfigParser) Value() (localctx IValueContext) {
localctx = NewValueContext(p, p.GetParserRuleContext(), p.GetState()) localctx = NewValueContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 6, ConfigParserRULE_value) p.EnterRule(localctx, 8, ConfigParserRULE_value)
p.EnterOuterAlt(localctx, 1) p.EnterOuterAlt(localctx, 1)
p.SetState(44) p.SetState(48)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) == 1 { if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 9, p.GetParserRuleContext()) == 1 {
{ {
p.SetState(42) p.SetState(46)
p.Match(ConfigParserSTRING) p.Match(ConfigParserSTRING)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -749,7 +860,7 @@ func (p *ConfigParser) Value() (localctx IValueContext) {
} }
} }
{ {
p.SetState(43) p.SetState(47)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -761,7 +872,7 @@ func (p *ConfigParser) Value() (localctx IValueContext) {
goto errorExit goto errorExit
} }
{ {
p.SetState(46) p.SetState(50)
p.Match(ConfigParserSTRING) p.Match(ConfigParserSTRING)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -874,19 +985,19 @@ func (s *LeadingCommentContext) ExitRule(listener antlr.ParseTreeListener) {
func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) { func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
localctx = NewLeadingCommentContext(p, p.GetParserRuleContext(), p.GetState()) localctx = NewLeadingCommentContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 8, ConfigParserRULE_leadingComment) p.EnterRule(localctx, 10, ConfigParserRULE_leadingComment)
var _la int var _la int
p.EnterOuterAlt(localctx, 1) p.EnterOuterAlt(localctx, 1)
{ {
p.SetState(48) p.SetState(52)
p.Match(ConfigParserHASH) p.Match(ConfigParserHASH)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
goto errorExit goto errorExit
} }
} }
p.SetState(50) p.SetState(54)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -895,7 +1006,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
if _la == ConfigParserWHITESPACE { if _la == ConfigParserWHITESPACE {
{ {
p.SetState(49) p.SetState(53)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -904,7 +1015,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
} }
} }
p.SetState(56) p.SetState(60)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -913,14 +1024,14 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
for ok := true; ok; ok = _la == ConfigParserSTRING { for ok := true; ok; ok = _la == ConfigParserSTRING {
{ {
p.SetState(52) p.SetState(56)
p.Match(ConfigParserSTRING) p.Match(ConfigParserSTRING)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
goto errorExit goto errorExit
} }
} }
p.SetState(54) p.SetState(58)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit
@ -929,7 +1040,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
if _la == ConfigParserWHITESPACE { if _la == ConfigParserWHITESPACE {
{ {
p.SetState(53) p.SetState(57)
p.Match(ConfigParserWHITESPACE) p.Match(ConfigParserWHITESPACE)
if p.HasError() { if p.HasError() {
// Recognition error - abort rule // Recognition error - abort rule
@ -939,7 +1050,7 @@ func (p *ConfigParser) LeadingComment() (localctx ILeadingCommentContext) {
} }
p.SetState(58) p.SetState(62)
p.GetErrorHandler().Sync(p) p.GetErrorHandler().Sync(p)
if p.HasError() { if p.HasError() {
goto errorExit goto errorExit

View File

@ -27,11 +27,16 @@ type SSHEntry interface {
GetType() SSHEntryType GetType() SSHEntryType
} }
type SSHSeparator struct {
common.LocationRange
}
type SSHOption struct { type SSHOption struct {
common.LocationRange common.LocationRange
Value string Value string
Key *SSHKey Key *SSHKey
Separator *SSHSeparator
OptionValue *SSHValue OptionValue *SSHValue
} }

View File

@ -3,11 +3,14 @@ package lsp
import ( import (
sshdconfig "config-lsp/handlers/sshd_config" sshdconfig "config-lsp/handlers/sshd_config"
"config-lsp/handlers/sshd_config/handlers" "config-lsp/handlers/sshd_config/handlers"
"regexp"
"github.com/tliron/glsp" "github.com/tliron/glsp"
protocol "github.com/tliron/glsp/protocol_3_16" protocol "github.com/tliron/glsp/protocol_3_16"
) )
var containsSeparatorPattern = regexp.MustCompile(`\s+$`)
func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) { func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
line := params.Position.Line line := params.Position.Line
cursor := params.Position.Character cursor := params.Position.Character
@ -21,7 +24,7 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
entry, matchBlock := d.Config.FindOption(line) entry, matchBlock := d.Config.FindOption(line)
if entry == nil { if entry == nil || entry.Separator == nil {
// Empty line // Empty line
return handlers.GetRootCompletions( return handlers.GetRootCompletions(
d, d,