Skip to content

Commit

Permalink
refactor: generate supported languages (#1544)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <[email protected]>
  • Loading branch information
Ian Lewis authored Aug 24, 2024
1 parent 3473c73 commit a7c4472
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 667 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ go-benchmark: ## Runs Go benchmarks.
if [ "$(OUTPUT_FORMAT)" == "github" ]; then \
extraargs="-v"; \
fi; \
go test $$extraargs -bench=. -count=$(TESTCOUNT) -benchtime=$(BENCHTIME) -run='^#' ./...
go test $$extraargs -mod=vendor -bench=. -count=$(TESTCOUNT) -benchtime=$(BENCHTIME) -run='^#' ./...

## Tools
#####################################################################
Expand Down Expand Up @@ -156,10 +156,10 @@ yamllint: ## Runs the yamllint linter.
## Documentation
#####################################################################

SUPPORTED_LANGUAGES.md: node_modules/.installed internal/scanner/languages.yml ## Supported languages documentation.
SUPPORTED_LANGUAGES.md: node_modules/.installed internal/scanner/languages.go ## Supported languages documentation.
@set -e;\
go mod vendor; \
go run ./internal/cmd/genlangdocs | ./node_modules/.bin/prettier --parser markdown > $@
go run -mod=vendor ./internal/cmd/genlangdocs | ./node_modules/.bin/prettier --parser markdown > $@

## Maintenance
#####################################################################
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/genlangdocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func main() {
for _, l := range langs {
var supported []string
for _, c := range l.config.LineCommentStart {
supported = append(supported, fmt.Sprintf("`%s`", c))
supported = append(supported, fmt.Sprintf("`%s`", string(c)))
}
if l.config.MultilineComment.Start != "" {
s := fmt.Sprintf("`%s %s`", l.config.MultilineComment.Start, l.config.MultilineComment.End)
if string(l.config.MultilineCommentStart) != "" {
s := fmt.Sprintf("`%s %s`", string(l.config.MultilineCommentStart), string(l.config.MultilineCommentEnd))
supported = append(supported, s)
}

Expand Down
52 changes: 52 additions & 0 deletions internal/scanner/escape.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package scanner

// EscapeFunc is function that checks for escaped string characters.
type EscapeFunc func(s *CommentScanner, stringEnd []rune) ([]rune, error)

// NoEscape is a no-op.
func NoEscape(_ *CommentScanner, _ []rune) ([]rune, error) {
return nil, nil
}

// CharEscape checks for the given escape character in the scanner.
func CharEscape(c rune) EscapeFunc {
return func(s *CommentScanner, stringEnd []rune) ([]rune, error) {
b := append([]rune{c}, stringEnd...)
eq, err := s.peekEqual(b)
if err != nil {
return nil, err
}
if eq {
return b, nil
}
return nil, nil
}
}

// DoubleEscape checks for a repeated string ending character in the string.
func DoubleEscape(s *CommentScanner, stringEnd []rune) ([]rune, error) {
b := append([]rune{}, stringEnd...)
b = append(b, stringEnd...)
eq, err := s.peekEqual(b)
if err != nil {
return nil, err
}
if eq {
return b, nil
}
return nil, nil
}
Loading

0 comments on commit a7c4472

Please sign in to comment.