Skip to content

Commit

Permalink
feat: Add PowerShell support. (#1543)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianmlewis@gmail.com>
  • Loading branch information
ianlewis committed Aug 23, 2024
1 parent 786713e commit 3473c73
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 90 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Support was added for
[MATLAB](https://www.mathworks.com/products/matlab.html) and
[MATLAB](https://www.mathworks.com/products/matlab.html)
- Support was added for
[Vim Script](https://vimdoc.sourceforge.net/htmldoc/usr_41.html).
- Support was added for
[Powershell](https://learn.microsoft.com/en-us/powershell/).

## [0.9.0] - 2024-08-08

Expand Down
3 changes: 2 additions & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Supported Languages

44 languages are currently supported.
45 languages are currently supported.

| File type | Extension | Supported comments |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
Expand Down Expand Up @@ -30,6 +30,7 @@
| Objective-C | `.m`, `.h` | `//`, `/* */` |
| PHP | `.php`, `.aw`, `.ctp`, `.fcgi`, `.inc`, `.php3`, `.php4`, `.php5`, `.phps`, `.phpt` | `#`, `//`, `/* */` |
| Perl | `.pl`, `.al`, `.cgi`, `.fcgi`, `.perl`, `.ph`, `.plx`, `.pm`, `.psgi`, `.t` | `#`, `= =cut` |
| PowerShell | `.ps1`, `.psd1`, `.psm1` | `#`, `<# #>` |
| Puppet | `.pp` | `#` |
| Python | `.py`, `.cgi`, `.fcgi`, `.gyp`, `.gypi`, `.lmi`, `.py3`, `.pyde`, `.pyi`, `.pyp`, `.pyt`, `.pyw`, `.rpy`, `.spec`, `.tac`, `.wsgi`, `.xpy` | `#`, `""" """` |
| R | `.r`, `.rd`, `.rsx` | `#` |
Expand Down
18 changes: 7 additions & 11 deletions internal/scanner/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ type MultilineCommentConfig struct {
}

var (
// BackslashEscape indicates characters can be escaped by a backslash.
BackslashEscape = "backslash"
// NoEscape indicates characters cannot be escaped.
// CharEscape indicates the following character is the escape character.
CharEscape = "character"

// NoEscape indicates characters cannot be escaped. This is the default.
NoEscape = "none"

// DoubleEscape indicates that strings can be escaped with double characters.
DoubleEscape = "double"
)
Expand All @@ -56,18 +58,12 @@ type Config struct {

type escapeFunc func(s *CommentScanner, st *stateString) ([]rune, error)

var escapeFuncs = map[string]escapeFunc{
BackslashEscape: backslashEscape,
NoEscape: noEscape,
DoubleEscape: doubleEscape,
}

func noEscape(_ *CommentScanner, _ *stateString) ([]rune, error) {
return nil, nil
}

func backslashEscape(s *CommentScanner, st *stateString) ([]rune, error) {
b := append([]rune{'\\'}, s.config.Strings[st.index].End...)
func charEscape(c rune, s *CommentScanner, st *stateString) ([]rune, error) {
b := append([]rune{c}, s.config.Strings[st.index].End...)
eq, err := s.peekEqual(b)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 3473c73

Please sign in to comment.