Skip to content

Commit dceb95a

Browse files
committed
gen: fix regexp Or syntax
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 3051773 commit dceb95a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

data/content.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/code-generator/generator/heuristics.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import (
1010
yaml "gopkg.in/yaml.v2"
1111
)
1212

13+
const (
14+
multilinePrefix = "(?m)"
15+
orPipe = "|"
16+
)
17+
1318
// GenHeuristics generates language identification heuristics in Go.
1419
// It is of generator.File type.
1520
func GenHeuristics(fileToParse, _, outPath, tmplPath, tmplName, commit string) error {
@@ -67,14 +72,14 @@ func loadRule(namedPatterns map[string]StringArray, rule *Rule) *LanguagePattern
6772
}
6873
result = &LanguagePattern{"And", rule.Languages, "", subPatterns}
6974
} else if len(rule.Pattern) != 0 { // OrPattern
70-
conjunction := strings.Join(rule.Pattern, " | ")
75+
conjunction := strings.Join(rule.Pattern, orPipe)
7176
pattern := convertToValidRegexp(conjunction)
7277
result = &LanguagePattern{"Or", rule.Languages, pattern, nil}
7378
} else if rule.NegativePattern != "" { // NotPattern
7479
pattern := convertToValidRegexp(rule.NegativePattern)
7580
result = &LanguagePattern{"Not", rule.Languages, pattern, nil}
7681
} else if rule.NamedPattern != "" { // Named OrPattern
77-
conjunction := strings.Join(namedPatterns[rule.NamedPattern], " | ")
82+
conjunction := strings.Join(namedPatterns[rule.NamedPattern], orPipe)
7883
pattern := convertToValidRegexp(conjunction)
7984
result = &LanguagePattern{"Or", rule.Languages, pattern, nil}
8085
} else { // AlwaysPattern
@@ -164,8 +169,6 @@ func isUnsupportedRegexpSyntax(reg string) bool {
164169
(strings.HasPrefix(reg, multilinePrefix+`/`) && strings.HasSuffix(reg, `/`))
165170
}
166171

167-
const multilinePrefix = "(?m)"
168-
169172
// convertToValidRegexp converts Ruby regexp syntaxt to RE2 equivalent.
170173
// Does not work with Ruby regexp literals.
171174
func convertToValidRegexp(rubyRegexp string) string {

0 commit comments

Comments
 (0)