Skip to content

Commit e7242d5

Browse files
Christoph Hegemannvarungandhi-src
Christoph Hegemann
andauthored
Symbol grammar clarifications (#255)
- Forbids scheme from being empty or starting with 'local' - Unifies "any UTF-8" wording - Specifies that identifiers that can be encoded as simple identifiers have to be encoded as simple identifiers - Makes method_disambiguator optional Co-authored-by: Varun Gandhi <[email protected]>
1 parent 76a272e commit e7242d5

File tree

10 files changed

+1862
-1812
lines changed

10 files changed

+1862
-1812
lines changed

bindings/go/scip/scip.pb.go

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/go/scip/symbol.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scip
33
import (
44
"fmt"
55
"strings"
6-
"unicode"
76

87
"github.com/sourcegraph/sourcegraph/lib/errors"
98
)
@@ -22,10 +21,13 @@ func IsLocalSymbol(symbol string) bool {
2221
return strings.HasPrefix(symbol, "local ")
2322
}
2423

24+
func isSimpleIdentifierCharacter(c rune) bool {
25+
return c == '_' || c == '+' || c == '-' || c == '$' || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')
26+
}
27+
2528
func isSimpleIdentifier(s string) bool {
2629
for _, c := range s {
27-
if ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
28-
c == '$' || c == '+' || c == '-' || c == '_' {
30+
if isSimpleIdentifierCharacter(c) {
2931
continue
3032
}
3133
return false
@@ -218,7 +220,7 @@ func (s *symbolParser) acceptIdentifier(what string) (string, error) {
218220
return s.acceptBacktickEscapedIdentifier(what)
219221
}
220222
start := s.index
221-
for s.index < len(s.Symbol) && isIdentifierCharacter(s.current()) {
223+
for s.index < len(s.Symbol) && isSimpleIdentifierCharacter(s.current()) {
222224
s.index++
223225
}
224226
if start == s.index {
@@ -227,10 +229,6 @@ func (s *symbolParser) acceptIdentifier(what string) (string, error) {
227229
return string(s.Symbol[start:s.index]), nil
228230
}
229231

230-
func isIdentifierCharacter(r rune) bool {
231-
return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-' || r == '+' || r == '$' || r == '_'
232-
}
233-
234232
func (s *symbolParser) acceptSpaceEscapedIdentifier(what string) (string, error) {
235233
return s.acceptEscapedIdentifier(what, ' ')
236234
}

bindings/go/scip/symbol_formatter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func writeEscapedPackage(b *strings.Builder, name string) {
139139
func writeSuffixedDescriptor(b *strings.Builder, identifier string, suffixes ...rune) {
140140
escape := false
141141
for _, ch := range identifier {
142-
if !isIdentifierCharacter(ch) {
142+
if !isSimpleIdentifierCharacter(ch) {
143143
escape = true
144144
break
145145
}

bindings/go/scip/symbol_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestParseSymbolError(t *testing.T) {
8888
"lsif-java maven package 1.0.0",
8989
"lsif-java maven package 1.0.0 java/io/File#Entry.trailingstring",
9090
"lsif-java maven package 1.0.0 java/io/File#Entry.unrecognizedSuffix@",
91+
"lsif-java maven package 1.0.0 java/io/File#Entry.nonSimpλeIdentifier.",
9192
"local 🧠",
9293
"local ",
9394
"local &&&",

0 commit comments

Comments
 (0)