diff --git a/handlers/sshd_config/fields/match-parser/Match.g4 b/handlers/sshd_config/fields/match-parser/Match.g4 index d7b77a4..10aa6eb 100644 --- a/handlers/sshd_config/fields/match-parser/Match.g4 +++ b/handlers/sshd_config/fields/match-parser/Match.g4 @@ -17,7 +17,7 @@ criteria ; values - : value (COMMA value?)* + : value? (COMMA value?)* ; value diff --git a/handlers/sshd_config/fields/match-parser/parser/Match.interp b/handlers/sshd_config/fields/match-parser/parser/Match.interp index 1291067..d188f93 100644 --- a/handlers/sshd_config/fields/match-parser/parser/Match.interp +++ b/handlers/sshd_config/fields/match-parser/parser/Match.interp @@ -34,4 +34,4 @@ value atn: -[4, 1, 10, 50, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 3, 4, 41, 8, 4, 5, 4, 43, 8, 4, 10, 4, 12, 4, 46, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 50, 0, 13, 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 37, 1, 0, 0, 0, 10, 47, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 44, 3, 10, 5, 0, 38, 40, 5, 8, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 43, 1, 0, 0, 0, 42, 38, 1, 0, 0, 0, 43, 46, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 9, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 47, 48, 5, 9, 0, 0, 48, 11, 1, 0, 0, 0, 7, 13, 17, 21, 28, 31, 40, 44] \ No newline at end of file +[4, 1, 10, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, 1, 4, 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 53, 0, 13, 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 38, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, 5, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, 5, 8, 0, 0, 41, 43, 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 50, 5, 9, 0, 0, 50, 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46] \ No newline at end of file diff --git a/handlers/sshd_config/fields/match-parser/parser/match_parser.go b/handlers/sshd_config/fields/match-parser/parser/match_parser.go index 79f54ba..ae15253 100644 --- a/handlers/sshd_config/fields/match-parser/parser/match_parser.go +++ b/handlers/sshd_config/fields/match-parser/parser/match_parser.go @@ -44,26 +44,27 @@ func matchParserInit() { } staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 10, 50, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, + 4, 1, 10, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, - 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 3, 4, - 41, 8, 4, 5, 4, 43, 8, 4, 10, 4, 12, 4, 46, 9, 4, 1, 5, 1, 5, 1, 5, 0, - 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 50, 0, 13, 1, 0, 0, 0, 2, 26, - 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 37, 1, 0, 0, 0, 10, - 47, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, - 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, - 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, - 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, - 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, - 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, - 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, - 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, 34, 5, 1, 0, 0, 0, - 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 44, 3, 10, 5, 0, 38, 40, 5, - 8, 0, 0, 39, 41, 3, 10, 5, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, - 43, 1, 0, 0, 0, 42, 38, 1, 0, 0, 0, 43, 46, 1, 0, 0, 0, 44, 42, 1, 0, 0, - 0, 44, 45, 1, 0, 0, 0, 45, 9, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 47, 48, 5, - 9, 0, 0, 48, 11, 1, 0, 0, 0, 7, 13, 17, 21, 28, 31, 40, 44, + 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, + 1, 4, 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, + 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 53, 0, 13, + 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, + 38, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, + 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, + 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, + 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, + 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, + 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, + 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, + 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, + 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, + 5, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, + 5, 8, 0, 0, 41, 43, 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, + 43, 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, + 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, + 50, 5, 9, 0, 0, 50, 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -446,8 +447,6 @@ func (s *MatchEntryContext) ExitRule(listener antlr.ParseTreeListener) { func (p *MatchParser) MatchEntry() (localctx IMatchEntryContext) { localctx = NewMatchEntryContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 2, MatchParserRULE_matchEntry) - var _la int - p.EnterOuterAlt(localctx, 1) { p.SetState(26) @@ -467,17 +466,15 @@ func (p *MatchParser) MatchEntry() (localctx IMatchEntryContext) { } p.SetState(31) p.GetErrorHandler().Sync(p) - if p.HasError() { - goto errorExit - } - _la = p.GetTokenStream().LA(1) - if _la == MatchParserSTRING { + if p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 4, p.GetParserRuleContext()) == 1 { { p.SetState(30) p.Values() } + } else if p.HasError() { // JIM + goto errorExit } errorExit: @@ -844,11 +841,21 @@ func (p *MatchParser) Values() (localctx IValuesContext) { var _la int p.EnterOuterAlt(localctx, 1) - { - p.SetState(37) - p.Value() + p.SetState(38) + p.GetErrorHandler().Sync(p) + if p.HasError() { + goto errorExit } - p.SetState(44) + _la = p.GetTokenStream().LA(1) + + if _la == MatchParserSTRING { + { + p.SetState(37) + p.Value() + } + + } + p.SetState(46) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -857,14 +864,14 @@ func (p *MatchParser) Values() (localctx IValuesContext) { for _la == MatchParserCOMMA { { - p.SetState(38) + p.SetState(40) p.Match(MatchParserCOMMA) if p.HasError() { // Recognition error - abort rule goto errorExit } } - p.SetState(40) + p.SetState(42) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -873,13 +880,13 @@ func (p *MatchParser) Values() (localctx IValuesContext) { if _la == MatchParserSTRING { { - p.SetState(39) + p.SetState(41) p.Value() } } - p.SetState(46) + p.SetState(48) p.GetErrorHandler().Sync(p) if p.HasError() { goto errorExit @@ -975,7 +982,7 @@ func (p *MatchParser) Value() (localctx IValueContext) { p.EnterRule(localctx, 10, MatchParserRULE_value) p.EnterOuterAlt(localctx, 1) { - p.SetState(47) + p.SetState(49) p.Match(MatchParserSTRING) if p.HasError() { // Recognition error - abort rule diff --git a/handlers/sshd_config/handlers/formatting_nodes.go b/handlers/sshd_config/handlers/formatting_nodes.go index 4045b36..02c148e 100644 --- a/handlers/sshd_config/handlers/formatting_nodes.go +++ b/handlers/sshd_config/handlers/formatting_nodes.go @@ -11,14 +11,14 @@ import ( protocol "github.com/tliron/glsp/protocol_3_16" ) +var optionTemplate = formatting.FormatTemplate( + "%s /!'%s/!'", +) + func formatSSHDOption( option *ast.SSHDOption, options protocol.FormattingOptions, ) []protocol.TextEdit { - template := formatting.FormatTemplate( - "%s/t%s", - ) - var key string if option.Key != nil { @@ -38,7 +38,7 @@ func formatSSHDOption( return []protocol.TextEdit{ { Range: option.ToLSPRange(), - NewText: template.Format(options, key, value), + NewText: optionTemplate.Format(options, key, value), }, } } @@ -49,12 +49,9 @@ func formatSSHDMatchBlock( ) []protocol.TextEdit { edits := make([]protocol.TextEdit, 0) - template := formatting.FormatTemplate( - "%s/t%s", - ) edits = append(edits, protocol.TextEdit{ Range: matchBlock.ToLSPRange(), - NewText: template.Format(options, matchBlock.MatchEntry.Key.Key, formatMatchToString(matchBlock.MatchValue)), + NewText: optionTemplate.Format(options, matchBlock.MatchEntry.Key.Key, formatMatchToString(matchBlock.MatchValue)), }) it := matchBlock.Options.Iterator()