mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
fix(server): Overall improvements
This commit is contained in:
parent
3860c73403
commit
ba1738c700
@ -67,15 +67,21 @@ func TrimWhitespace(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
value := raw
|
value := strings.TrimSpace(raw)
|
||||||
currentIndex := 0
|
currentIndex := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
nextStart, found := findNextDoubleQuote(value, currentIndex)
|
nextStart, found := findNextDoubleQuote(value, currentIndex)
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
part := value[:nextStart]
|
part := trimPattern.ReplaceAllString(
|
||||||
value = strings.TrimSpace(part) + value[nextStart:]
|
value[:nextStart],
|
||||||
|
" ",
|
||||||
|
)
|
||||||
|
|
||||||
|
value = modifyString(value, 0, nextStart, part)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
nextEnd, found := findNextDoubleQuote(value, nextStart+1)
|
nextEnd, found := findNextDoubleQuote(value, nextStart+1)
|
||||||
@ -91,7 +97,7 @@ func TrimWhitespace(
|
|||||||
if currentIndex < len(value) {
|
if currentIndex < len(value) {
|
||||||
part := value[currentIndex:]
|
part := value[currentIndex:]
|
||||||
|
|
||||||
value = value[:currentIndex] + strings.TrimSpace(part)
|
value = modifyString(value, currentIndex, len(value), part)
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -49,7 +49,8 @@ func (l VirtualLine) GetSubset(start uint32, end uint32) VirtualLine {
|
|||||||
if end <= partEnd {
|
if end <= partEnd {
|
||||||
rangeEnd = end - partStart
|
rangeEnd = end - partStart
|
||||||
} else {
|
} else {
|
||||||
rangeEnd = partEnd
|
// End of the part
|
||||||
|
rangeEnd = partEnd - partStart
|
||||||
}
|
}
|
||||||
|
|
||||||
parts = append(parts, VirtualLinePart{
|
parts = append(parts, VirtualLinePart{
|
||||||
@ -100,27 +101,27 @@ func (l VirtualLine) ConvertRangeToTextRange(start uint32, end uint32) []Locatio
|
|||||||
return ranges
|
return ranges
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l VirtualLine) AsTrimmed() VirtualLine {
|
// func (l VirtualLine) AsTrimmed() VirtualLine {
|
||||||
if len(l.Parts) == 0 {
|
// if len(l.Parts) == 0 {
|
||||||
// There's nothing that could be trimmed, so we can also just
|
// // There's nothing that could be trimmed, so we can also just
|
||||||
// return the original line, as it's identical
|
// // return the original line, as it's identical
|
||||||
return l
|
// return l
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
parts := make([]VirtualLinePart, len(l.Parts))
|
// parts := make([]VirtualLinePart, len(l.Parts))
|
||||||
|
//
|
||||||
for index, part := range l.Parts {
|
// for index, part := range l.Parts {
|
||||||
parts[index] = part.AsTrimmed()
|
// parts[index] = part.AsTrimmed()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return VirtualLine{
|
// return VirtualLine{
|
||||||
LocationRange: LocationRange{
|
// LocationRange: LocationRange{
|
||||||
Start: parts[0].Start,
|
// Start: parts[0].Start,
|
||||||
End: parts[len(parts)-1].End,
|
// End: parts[len(parts)-1].End,
|
||||||
},
|
// },
|
||||||
Parts: parts,
|
// Parts: parts,
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
type VirtualLinePart struct {
|
type VirtualLinePart struct {
|
||||||
// This is the true location of the text
|
// This is the true location of the text
|
||||||
@ -129,34 +130,39 @@ type VirtualLinePart struct {
|
|||||||
Text string
|
Text string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p VirtualLinePart) AsTrimmed() VirtualLinePart {
|
// func (p VirtualLinePart) AsTrimmed() VirtualLinePart {
|
||||||
firstNonWhitespace := utils.FindFirstNonMatch(p.Text, UnicodeWhitespace, 0)
|
// firstNonWhitespace := utils.FindFirstNonMatch(p.Text, UnicodeWhitespace, 0)
|
||||||
|
//
|
||||||
if firstNonWhitespace == -1 {
|
// if firstNonWhitespace == -1 {
|
||||||
// Empty line
|
// // Empty line
|
||||||
return p
|
// return p
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
lastNonWhitespace := utils.FindLastNonMatch(p.Text, UnicodeWhitespace, len(p.Text)-1)
|
// var text string
|
||||||
|
// lastNonWhitespace := utils.FindLastNonMatch(p.Text, UnicodeWhitespace, len(p.Text)-1)
|
||||||
if lastNonWhitespace == -1 {
|
//
|
||||||
lastNonWhitespace = len(p.Text) - 1
|
// // Allow one space at the end
|
||||||
}
|
// if lastNonWhitespace == -1 {
|
||||||
|
// lastNonWhitespace = len(p.Text) - 1
|
||||||
return VirtualLinePart{
|
// text = p.Text[firstNonWhitespace:]
|
||||||
LocationRange: LocationRange{
|
// } else {
|
||||||
Start: Location{
|
// text = p.Text[firstNonWhitespace : lastNonWhitespace+1]
|
||||||
Line: p.Start.Line,
|
// }
|
||||||
Character: p.Start.Character + uint32(firstNonWhitespace),
|
//
|
||||||
},
|
// return VirtualLinePart{
|
||||||
End: Location{
|
// LocationRange: LocationRange{
|
||||||
Line: p.Start.Line,
|
// Start: Location{
|
||||||
Character: p.Start.Character + uint32(lastNonWhitespace) + 1,
|
// Line: p.Start.Line,
|
||||||
},
|
// Character: p.Start.Character + uint32(firstNonWhitespace),
|
||||||
},
|
// },
|
||||||
Text: p.Text[firstNonWhitespace : lastNonWhitespace+1],
|
// End: Location{
|
||||||
}
|
// Line: p.Start.Line,
|
||||||
}
|
// Character: p.Start.Character + uint32(lastNonWhitespace) + 1,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// Text: text,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func SplitIntoVirtualLines(input string) []VirtualLine {
|
func SplitIntoVirtualLines(input string) []VirtualLine {
|
||||||
stringLines := utils.SplitIntoVirtualLines(input)
|
stringLines := utils.SplitIntoVirtualLines(input)
|
||||||
|
@ -133,50 +133,50 @@ how are you
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSplitIntoVirtualLinesIndentedExample(
|
// func TestSplitIntoVirtualLinesIndentedExample(
|
||||||
t *testing.T,
|
// t *testing.T,
|
||||||
) {
|
// ) {
|
||||||
// 4 spaces
|
// // 4 spaces
|
||||||
input := utils.Dedent(`
|
// input := utils.Dedent(`
|
||||||
Hello
|
// Hello
|
||||||
`)
|
// `)
|
||||||
expected := []VirtualLine{
|
// expected := []VirtualLine{
|
||||||
{
|
// {
|
||||||
LocationRange: LocationRange{
|
// LocationRange: LocationRange{
|
||||||
Start: Location{
|
// Start: Location{
|
||||||
Line: 0,
|
// Line: 0,
|
||||||
Character: 4,
|
// Character: 4,
|
||||||
},
|
// },
|
||||||
End: Location{
|
// End: Location{
|
||||||
Line: 0,
|
// Line: 0,
|
||||||
Character: 9,
|
// Character: 9,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
Parts: []VirtualLinePart{
|
// Parts: []VirtualLinePart{
|
||||||
{
|
// {
|
||||||
LocationRange: LocationRange{
|
// LocationRange: LocationRange{
|
||||||
Start: Location{
|
// Start: Location{
|
||||||
Line: 0,
|
// Line: 0,
|
||||||
Character: 4,
|
// Character: 4,
|
||||||
},
|
// },
|
||||||
End: Location{
|
// End: Location{
|
||||||
Line: 0,
|
// Line: 0,
|
||||||
Character: 9,
|
// Character: 9,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
Text: "Hello",
|
// Text: "Hello",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
actual := SplitIntoVirtualLines(input)
|
// actual := SplitIntoVirtualLines(input)
|
||||||
|
//
|
||||||
for index, line := range actual {
|
// for index, line := range actual {
|
||||||
actual[index] = line.AsTrimmed()
|
// actual[index] = line.AsTrimmed()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if !cmp.Equal(expected, actual) {
|
// if !cmp.Equal(expected, actual) {
|
||||||
t.Fatalf("Expected %v, got %v", expected, actual)
|
// t.Fatalf("Expected %v, got %v", expected, actual)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
@ -25,7 +25,7 @@ value
|
|||||||
;
|
;
|
||||||
|
|
||||||
string
|
string
|
||||||
: (QUOTED_STRING | (WHITESPACE? (STRING WHITESPACE)* STRING))
|
: (WHITESPACE? ((STRING | QUOTED_STRING) WHITESPACE)* (STRING | QUOTED_STRING))
|
||||||
;
|
;
|
||||||
|
|
||||||
commentSymbol
|
commentSymbol
|
||||||
|
@ -90,12 +90,12 @@ func (s *gitconfigParserListener) EnterValue(ctx *parser.ValueContext) {
|
|||||||
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
location := common.CharacterRangeFromCtx(ctx.BaseParserRuleContext)
|
||||||
location.ChangeBothLines(s.gitconfigContext.line)
|
location.ChangeBothLines(s.gitconfigContext.line)
|
||||||
|
|
||||||
virtualLine := s.gitconfigContext.virtualLine.GetSubset(location.Start.Character, location.End.Character).AsTrimmed()
|
virtualLine := s.gitconfigContext.virtualLine.GetSubset(location.Start.Character, location.End.Character)
|
||||||
value := commonparser.ParseRawString(
|
value := commonparser.ParseRawString(
|
||||||
virtualLine.GetText(),
|
virtualLine.GetText(),
|
||||||
commonparser.ParseFeatures{
|
commonparser.ParseFeatures{
|
||||||
ParseDoubleQuotes: true,
|
ParseDoubleQuotes: true,
|
||||||
TrimWhitespace: false,
|
TrimWhitespace: true,
|
||||||
ParseEscapedCharacters: false,
|
ParseEscapedCharacters: false,
|
||||||
Replacements: &map[string]string{},
|
Replacements: &map[string]string{},
|
||||||
},
|
},
|
||||||
|
@ -28,4 +28,4 @@ commentSymbol
|
|||||||
|
|
||||||
|
|
||||||
atn:
|
atn:
|
||||||
[4, 1, 6, 78, 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, 2, 7, 7, 7, 1, 0, 3, 0, 18, 8, 0, 1, 0, 1, 0, 3, 0, 22, 8, 0, 1, 0, 3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 0, 0, 36, 38, 1, 0, 0, 0, 37, 39, 5, 4, 0, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 42, 3, 10, 5, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 3, 1, 0, 0, 0, 43, 45, 3, 14, 7, 0, 44, 46, 5, 4, 0, 0, 45, 44, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 51, 1, 0, 0, 0, 47, 49, 3, 12, 6, 0, 48, 50, 5, 4, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 52, 1, 0, 0, 0, 51, 47, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 5, 1, 0, 0, 0, 55, 56, 3, 12, 6, 0, 56, 7, 1, 0, 0, 0, 57, 58, 5, 1, 0, 0, 58, 9, 1, 0, 0, 0, 59, 60, 3, 12, 6, 0, 60, 11, 1, 0, 0, 0, 61, 74, 5, 6, 0, 0, 62, 64, 5, 4, 0, 0, 63, 62, 1, 0, 0, 0, 63, 64, 1, 0, 0, 0, 64, 69, 1, 0, 0, 0, 65, 66, 5, 5, 0, 0, 66, 68, 5, 4, 0, 0, 67, 65, 1, 0, 0, 0, 68, 71, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 69, 70, 1, 0, 0, 0, 70, 72, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 74, 5, 5, 0, 0, 73, 61, 1, 0, 0, 0, 73, 63, 1, 0, 0, 0, 74, 13, 1, 0, 0, 0, 75, 76, 7, 0, 0, 0, 76, 15, 1, 0, 0, 0, 14, 17, 21, 24, 29, 32, 35, 38, 41, 45, 49, 53, 63, 69, 73]
|
[4, 1, 6, 76, 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, 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, 0, 0, 33, 35, 1, 0, 0, 0, 34, 36, 3, 8, 4, 0, 35, 34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 38, 1, 0, 0, 0, 37, 39, 5, 4, 0, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1, 0, 0, 0, 40, 42, 3, 10, 5, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 3, 1, 0, 0, 0, 43, 45, 3, 14, 7, 0, 44, 46, 5, 4, 0, 0, 45, 44, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 51, 1, 0, 0, 0, 47, 49, 3, 12, 6, 0, 48, 50, 5, 4, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 52, 1, 0, 0, 0, 51, 47, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 5, 1, 0, 0, 0, 55, 56, 3, 12, 6, 0, 56, 7, 1, 0, 0, 0, 57, 58, 5, 1, 0, 0, 58, 9, 1, 0, 0, 0, 59, 60, 3, 12, 6, 0, 60, 11, 1, 0, 0, 0, 61, 63, 5, 4, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 68, 1, 0, 0, 0, 64, 65, 7, 0, 0, 0, 65, 67, 5, 4, 0, 0, 66, 64, 1, 0, 0, 0, 67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 71, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 72, 7, 0, 0, 0, 72, 13, 1, 0, 0, 0, 73, 74, 7, 1, 0, 0, 74, 15, 1, 0, 0, 0, 13, 17, 21, 24, 29, 32, 35, 38, 41, 45, 49, 53, 62, 68]
|
@ -44,39 +44,38 @@ func configParserInit() {
|
|||||||
}
|
}
|
||||||
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
|
staticData.PredictionContextCache = antlr.NewPredictionContextCache()
|
||||||
staticData.serializedATN = []int32{
|
staticData.serializedATN = []int32{
|
||||||
4, 1, 6, 78, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4,
|
4, 1, 6, 76, 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, 2, 7, 7, 7, 1, 0, 3, 0, 18, 8, 0, 1, 0, 1, 0, 3,
|
2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 1, 0, 3, 0, 18, 8, 0, 1, 0, 1, 0, 3,
|
||||||
0, 22, 8, 0, 1, 0, 3, 0, 25, 8, 0, 1, 0, 1, 0, 1, 1, 3, 1, 30, 8, 1, 1,
|
0, 22, 8, 0, 1, 0, 3, 0, 25, 8, 0, 1, 0, 1, 0, 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, 1, 3,
|
1, 3, 1, 33, 8, 1, 1, 1, 3, 1, 36, 8, 1, 1, 1, 3, 1, 39, 8, 1, 1, 1, 3,
|
||||||
1, 42, 8, 1, 1, 2, 1, 2, 3, 2, 46, 8, 2, 1, 2, 1, 2, 3, 2, 50, 8, 2, 4,
|
1, 42, 8, 1, 1, 2, 1, 2, 3, 2, 46, 8, 2, 1, 2, 1, 2, 3, 2, 50, 8, 2, 4,
|
||||||
2, 52, 8, 2, 11, 2, 12, 2, 53, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6,
|
2, 52, 8, 2, 11, 2, 12, 2, 53, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6,
|
||||||
1, 6, 3, 6, 64, 8, 6, 1, 6, 1, 6, 5, 6, 68, 8, 6, 10, 6, 12, 6, 71, 9,
|
3, 6, 63, 8, 6, 1, 6, 1, 6, 5, 6, 67, 8, 6, 10, 6, 12, 6, 70, 9, 6, 1,
|
||||||
6, 1, 6, 3, 6, 74, 8, 6, 1, 7, 1, 7, 1, 7, 0, 0, 8, 0, 2, 4, 6, 8, 10,
|
6, 1, 6, 1, 7, 1, 7, 1, 7, 0, 0, 8, 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 1,
|
||||||
12, 14, 0, 1, 1, 0, 2, 3, 83, 0, 17, 1, 0, 0, 0, 2, 29, 1, 0, 0, 0, 4,
|
0, 5, 6, 1, 0, 2, 3, 80, 0, 17, 1, 0, 0, 0, 2, 29, 1, 0, 0, 0, 4, 43, 1,
|
||||||
43, 1, 0, 0, 0, 6, 55, 1, 0, 0, 0, 8, 57, 1, 0, 0, 0, 10, 59, 1, 0, 0,
|
0, 0, 0, 6, 55, 1, 0, 0, 0, 8, 57, 1, 0, 0, 0, 10, 59, 1, 0, 0, 0, 12,
|
||||||
0, 12, 73, 1, 0, 0, 0, 14, 75, 1, 0, 0, 0, 16, 18, 5, 4, 0, 0, 17, 16,
|
62, 1, 0, 0, 0, 14, 73, 1, 0, 0, 0, 16, 18, 5, 4, 0, 0, 17, 16, 1, 0, 0,
|
||||||
1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 21, 3, 2, 1, 0,
|
0, 17, 18, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 21, 3, 2, 1, 0, 20, 22,
|
||||||
20, 22, 5, 4, 0, 0, 21, 20, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1,
|
5, 4, 0, 0, 21, 20, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0,
|
||||||
0, 0, 0, 23, 25, 3, 4, 2, 0, 24, 23, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25,
|
23, 25, 3, 4, 2, 0, 24, 23, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 1,
|
||||||
26, 1, 0, 0, 0, 26, 27, 5, 0, 0, 1, 27, 1, 1, 0, 0, 0, 28, 30, 3, 6, 3,
|
0, 0, 0, 26, 27, 5, 0, 0, 1, 27, 1, 1, 0, 0, 0, 28, 30, 3, 6, 3, 0, 29,
|
||||||
0, 29, 28, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 32, 1, 0, 0, 0, 31, 33,
|
28, 1, 0, 0, 0, 29, 30, 1, 0, 0, 0, 30, 32, 1, 0, 0, 0, 31, 33, 5, 4, 0,
|
||||||
5, 4, 0, 0, 32, 31, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 35, 1, 0, 0, 0,
|
0, 32, 31, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 35, 1, 0, 0, 0, 34, 36,
|
||||||
34, 36, 3, 8, 4, 0, 35, 34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 38, 1,
|
3, 8, 4, 0, 35, 34, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 38, 1, 0, 0, 0,
|
||||||
0, 0, 0, 37, 39, 5, 4, 0, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39,
|
37, 39, 5, 4, 0, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 41, 1,
|
||||||
41, 1, 0, 0, 0, 40, 42, 3, 10, 5, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0,
|
0, 0, 0, 40, 42, 3, 10, 5, 0, 41, 40, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42,
|
||||||
0, 0, 42, 3, 1, 0, 0, 0, 43, 45, 3, 14, 7, 0, 44, 46, 5, 4, 0, 0, 45, 44,
|
3, 1, 0, 0, 0, 43, 45, 3, 14, 7, 0, 44, 46, 5, 4, 0, 0, 45, 44, 1, 0, 0,
|
||||||
1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 51, 1, 0, 0, 0, 47, 49, 3, 12, 6, 0,
|
0, 45, 46, 1, 0, 0, 0, 46, 51, 1, 0, 0, 0, 47, 49, 3, 12, 6, 0, 48, 50,
|
||||||
48, 50, 5, 4, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 52, 1,
|
5, 4, 0, 0, 49, 48, 1, 0, 0, 0, 49, 50, 1, 0, 0, 0, 50, 52, 1, 0, 0, 0,
|
||||||
0, 0, 0, 51, 47, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53,
|
51, 47, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1,
|
||||||
54, 1, 0, 0, 0, 54, 5, 1, 0, 0, 0, 55, 56, 3, 12, 6, 0, 56, 7, 1, 0, 0,
|
0, 0, 0, 54, 5, 1, 0, 0, 0, 55, 56, 3, 12, 6, 0, 56, 7, 1, 0, 0, 0, 57,
|
||||||
0, 57, 58, 5, 1, 0, 0, 58, 9, 1, 0, 0, 0, 59, 60, 3, 12, 6, 0, 60, 11,
|
58, 5, 1, 0, 0, 58, 9, 1, 0, 0, 0, 59, 60, 3, 12, 6, 0, 60, 11, 1, 0, 0,
|
||||||
1, 0, 0, 0, 61, 74, 5, 6, 0, 0, 62, 64, 5, 4, 0, 0, 63, 62, 1, 0, 0, 0,
|
0, 61, 63, 5, 4, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 68,
|
||||||
63, 64, 1, 0, 0, 0, 64, 69, 1, 0, 0, 0, 65, 66, 5, 5, 0, 0, 66, 68, 5,
|
1, 0, 0, 0, 64, 65, 7, 0, 0, 0, 65, 67, 5, 4, 0, 0, 66, 64, 1, 0, 0, 0,
|
||||||
4, 0, 0, 67, 65, 1, 0, 0, 0, 68, 71, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 69,
|
67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 71, 1,
|
||||||
70, 1, 0, 0, 0, 70, 72, 1, 0, 0, 0, 71, 69, 1, 0, 0, 0, 72, 74, 5, 5, 0,
|
0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 72, 7, 0, 0, 0, 72, 13, 1, 0, 0, 0, 73,
|
||||||
0, 73, 61, 1, 0, 0, 0, 73, 63, 1, 0, 0, 0, 74, 13, 1, 0, 0, 0, 75, 76,
|
74, 7, 1, 0, 0, 74, 15, 1, 0, 0, 0, 13, 17, 21, 24, 29, 32, 35, 38, 41,
|
||||||
7, 0, 0, 0, 76, 15, 1, 0, 0, 0, 14, 17, 21, 24, 29, 32, 35, 38, 41, 45,
|
45, 49, 53, 62, 68,
|
||||||
49, 53, 63, 69, 73,
|
|
||||||
}
|
}
|
||||||
deserializer := antlr.NewATNDeserializer(nil)
|
deserializer := antlr.NewATNDeserializer(nil)
|
||||||
staticData.atn = deserializer.Deserialize(staticData.serializedATN)
|
staticData.atn = deserializer.Deserialize(staticData.serializedATN)
|
||||||
@ -1068,9 +1067,10 @@ type IStringContext interface {
|
|||||||
GetParser() antlr.Parser
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
// Getter signatures
|
// Getter signatures
|
||||||
QUOTED_STRING() antlr.TerminalNode
|
|
||||||
AllSTRING() []antlr.TerminalNode
|
AllSTRING() []antlr.TerminalNode
|
||||||
STRING(i int) antlr.TerminalNode
|
STRING(i int) antlr.TerminalNode
|
||||||
|
AllQUOTED_STRING() []antlr.TerminalNode
|
||||||
|
QUOTED_STRING(i int) antlr.TerminalNode
|
||||||
AllWHITESPACE() []antlr.TerminalNode
|
AllWHITESPACE() []antlr.TerminalNode
|
||||||
WHITESPACE(i int) antlr.TerminalNode
|
WHITESPACE(i int) antlr.TerminalNode
|
||||||
|
|
||||||
@ -1110,10 +1110,6 @@ func NewStringContext(parser antlr.Parser, parent antlr.ParserRuleContext, invok
|
|||||||
|
|
||||||
func (s *StringContext) GetParser() antlr.Parser { return s.parser }
|
func (s *StringContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
func (s *StringContext) QUOTED_STRING() antlr.TerminalNode {
|
|
||||||
return s.GetToken(ConfigParserQUOTED_STRING, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StringContext) AllSTRING() []antlr.TerminalNode {
|
func (s *StringContext) AllSTRING() []antlr.TerminalNode {
|
||||||
return s.GetTokens(ConfigParserSTRING)
|
return s.GetTokens(ConfigParserSTRING)
|
||||||
}
|
}
|
||||||
@ -1122,6 +1118,14 @@ func (s *StringContext) STRING(i int) antlr.TerminalNode {
|
|||||||
return s.GetToken(ConfigParserSTRING, i)
|
return s.GetToken(ConfigParserSTRING, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StringContext) AllQUOTED_STRING() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ConfigParserQUOTED_STRING)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StringContext) QUOTED_STRING(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ConfigParserQUOTED_STRING, i)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StringContext) AllWHITESPACE() []antlr.TerminalNode {
|
func (s *StringContext) AllWHITESPACE() []antlr.TerminalNode {
|
||||||
return s.GetTokens(ConfigParserWHITESPACE)
|
return s.GetTokens(ConfigParserWHITESPACE)
|
||||||
}
|
}
|
||||||
@ -1158,34 +1162,48 @@ func (p *ConfigParser) String_() (localctx IStringContext) {
|
|||||||
var _alt int
|
var _alt int
|
||||||
|
|
||||||
p.EnterOuterAlt(localctx, 1)
|
p.EnterOuterAlt(localctx, 1)
|
||||||
p.SetState(73)
|
p.SetState(62)
|
||||||
p.GetErrorHandler().Sync(p)
|
p.GetErrorHandler().Sync(p)
|
||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
goto errorExit
|
goto errorExit
|
||||||
}
|
}
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
switch p.GetTokenStream().LA(1) {
|
if _la == ConfigParserWHITESPACE {
|
||||||
case ConfigParserQUOTED_STRING:
|
|
||||||
{
|
{
|
||||||
p.SetState(61)
|
p.SetState(61)
|
||||||
p.Match(ConfigParserQUOTED_STRING)
|
p.Match(ConfigParserWHITESPACE)
|
||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
// Recognition error - abort rule
|
// Recognition error - abort rule
|
||||||
goto errorExit
|
goto errorExit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case ConfigParserWHITESPACE, ConfigParserSTRING:
|
}
|
||||||
p.SetState(63)
|
p.SetState(68)
|
||||||
p.GetErrorHandler().Sync(p)
|
p.GetErrorHandler().Sync(p)
|
||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
goto errorExit
|
goto errorExit
|
||||||
}
|
}
|
||||||
_la = p.GetTokenStream().LA(1)
|
_alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext())
|
||||||
|
if p.HasError() {
|
||||||
if _la == ConfigParserWHITESPACE {
|
goto errorExit
|
||||||
|
}
|
||||||
|
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
||||||
|
if _alt == 1 {
|
||||||
{
|
{
|
||||||
p.SetState(62)
|
p.SetState(64)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if !(_la == ConfigParserSTRING || _la == ConfigParserQUOTED_STRING) {
|
||||||
|
p.GetErrorHandler().RecoverInline(p)
|
||||||
|
} else {
|
||||||
|
p.GetErrorHandler().ReportMatch(p)
|
||||||
|
p.Consume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(65)
|
||||||
p.Match(ConfigParserWHITESPACE)
|
p.Match(ConfigParserWHITESPACE)
|
||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
// Recognition error - abort rule
|
// Recognition error - abort rule
|
||||||
@ -1194,7 +1212,7 @@ func (p *ConfigParser) String_() (localctx IStringContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
p.SetState(69)
|
p.SetState(70)
|
||||||
p.GetErrorHandler().Sync(p)
|
p.GetErrorHandler().Sync(p)
|
||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
goto errorExit
|
goto errorExit
|
||||||
@ -1203,48 +1221,17 @@ func (p *ConfigParser) String_() (localctx IStringContext) {
|
|||||||
if p.HasError() {
|
if p.HasError() {
|
||||||
goto errorExit
|
goto errorExit
|
||||||
}
|
}
|
||||||
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
}
|
||||||
if _alt == 1 {
|
{
|
||||||
{
|
p.SetState(71)
|
||||||
p.SetState(65)
|
_la = p.GetTokenStream().LA(1)
|
||||||
p.Match(ConfigParserSTRING)
|
|
||||||
if p.HasError() {
|
|
||||||
// Recognition error - abort rule
|
|
||||||
goto errorExit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
p.SetState(66)
|
|
||||||
p.Match(ConfigParserWHITESPACE)
|
|
||||||
if p.HasError() {
|
|
||||||
// Recognition error - abort rule
|
|
||||||
goto errorExit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if !(_la == ConfigParserSTRING || _la == ConfigParserQUOTED_STRING) {
|
||||||
p.SetState(71)
|
p.GetErrorHandler().RecoverInline(p)
|
||||||
p.GetErrorHandler().Sync(p)
|
} else {
|
||||||
if p.HasError() {
|
p.GetErrorHandler().ReportMatch(p)
|
||||||
goto errorExit
|
p.Consume()
|
||||||
}
|
|
||||||
_alt = p.GetInterpreter().AdaptivePredict(p.BaseParser, p.GetTokenStream(), 12, p.GetParserRuleContext())
|
|
||||||
if p.HasError() {
|
|
||||||
goto errorExit
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
|
||||||
p.SetState(72)
|
|
||||||
p.Match(ConfigParserSTRING)
|
|
||||||
if p.HasError() {
|
|
||||||
// Recognition error - abort rule
|
|
||||||
goto errorExit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
p.SetError(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
|
||||||
goto errorExit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
errorExit:
|
errorExit:
|
||||||
@ -1342,7 +1329,7 @@ func (p *ConfigParser) CommentSymbol() (localctx ICommentSymbolContext) {
|
|||||||
|
|
||||||
p.EnterOuterAlt(localctx, 1)
|
p.EnterOuterAlt(localctx, 1)
|
||||||
{
|
{
|
||||||
p.SetState(75)
|
p.SetState(73)
|
||||||
_la = p.GetTokenStream().LA(1)
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
if !(_la == ConfigParserHASH || _la == ConfigParserSEMICOLON) {
|
if !(_la == ConfigParserHASH || _la == ConfigParserSEMICOLON) {
|
||||||
|
@ -136,3 +136,39 @@ bare = false
|
|||||||
t.Fatalf("Expected 1 error, got %d", len(errors))
|
t.Fatalf("Expected 1 error, got %d", len(errors))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLeadingLine(t *testing.T) {
|
||||||
|
input := utils.Dedent(`
|
||||||
|
[core]
|
||||||
|
command = git \
|
||||||
|
commit \
|
||||||
|
-m "Hello World"
|
||||||
|
`)
|
||||||
|
|
||||||
|
config := NewGitConfig()
|
||||||
|
errors := config.Parse(input)
|
||||||
|
|
||||||
|
if len(errors) > 0 {
|
||||||
|
t.Fatalf("Expected no errors, got %v", errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(config.Sections) != 1 {
|
||||||
|
t.Fatalf("Expected 1 section, got %d", len(config.Sections))
|
||||||
|
}
|
||||||
|
|
||||||
|
section := config.Sections[0]
|
||||||
|
|
||||||
|
if !(section.Title.Title == "core") {
|
||||||
|
t.Errorf("Expected core, got %s", section.Title.Title)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawFirstOption, _ := section.Entries.Get(uint32(1))
|
||||||
|
firstOption := rawFirstOption.(*GitEntry)
|
||||||
|
if !(firstOption.Key.Value.Value == "command" && firstOption.Value.Value == "git commit -m Hello World") {
|
||||||
|
t.Errorf("Expected command, got %s", firstOption.Key.Value.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(firstOption.Value.Raw.Parts[0].Text == "git " && firstOption.Value.Raw.Parts[1].Text == "\t\tcommit " && firstOption.Value.Raw.Parts[2].Text == "\t\t-m \"Hello World\"") {
|
||||||
|
t.Errorf("Expected command, got %s", firstOption.Value.Raw.Parts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user