Skip to content

Commit

Permalink
add support for golang template files
Browse files Browse the repository at this point in the history
  • Loading branch information
Acetolyne committed Nov 23, 2023
1 parent 6688c2b commit 6c26f94
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,25 @@ type CommentValues struct {
endMulti string
}

//Initialize comment characters based on file extension
//This may be more than one type per filetype as html can have javascript comments in them as well and there may be other filetypes that have multiple languages in them
//Add new file extensions here to add support for them to get themn officially added to future builds please submit a feature request at https://github.com/Acetolyne/commentlex
//@ext a list of file extensions that can be scanned, can be a single type or multiple types
//@startSingle the start characters of a single line comment
//@startMulti the start characters of a multi line comment
//@endMulti the end characters of a multi line comment
// Initialize comment characters based on file extension
// This may be more than one type per filetype as html can have javascript comments in them as well and there may be other filetypes that have multiple languages in them
// Add new file extensions here to add support for them to get themn officially added to future builds please submit a feature request at https://github.com/Acetolyne/commentlex
// @ext a list of file extensions that can be scanned, can be a single type or multiple types
// @startSingle the start characters of a single line comment
// @startMulti the start characters of a multi line comment
// @endMulti the end characters of a multi line comment
//
//If a single line comment requires you to end the comment then you may use the startMulti and end Multi fields to specify the characters that end the comment
//If the same filetype also has multiline comments that are different you may specify a new block with the same file extension and both will be processed.
// If a single line comment requires you to end the comment then you may use the startMulti and end Multi fields to specify the characters that end the comment
// If the same filetype also has multiline comments that are different you may specify a new block with the same file extension and both will be processed.
//
//Template for new or add extensions to one that matches below.
// {
// ext: []string{".FILEEXT"},
// startSingle: "//",
// startMulti: "/*",
// endMulti: "*/",
// },
// Template for new or add extensions to one that matches below.
//
// {
// ext: []string{".FILEEXT"},
// startSingle: "//",
// startMulti: "/*",
// endMulti: "*/",
// },
var Extensions = []CommentValues{
{
ext: []string{"", ".go", ".py", ".js", ".rs", ".html", ".gohtml", ".php", ".c", ".cpp", ".h", ".class", ".jar", ".java", ".jsp"},
Expand Down Expand Up @@ -95,6 +96,11 @@ var Extensions = []CommentValues{
ext: []string{".py"},
startSingle: "#",
},
{
ext: []string{".tmpl"},
startMulti: "{{/*",
endMulti: "*/}}",
},
}

// IsValid reports whether the position is valid.
Expand Down Expand Up @@ -126,7 +132,7 @@ func (pos Position) String() string {
// Use GoTokens to configure the Scanner such that it accepts all Go
// literal tokens including Go identifiers. Comments will be skipped.
//
//@todo cleanup the mode bits
// @todo cleanup the mode bits
const (
//ScanIdents = 1 << -Ident
//ScanInts = 1 << -Int
Expand Down Expand Up @@ -321,7 +327,7 @@ func (s *Scanner) Init(file string) *Scanner {
return s
}

//Return valid filetypes
// Return valid filetypes
func (s *Scanner) GetExtensions() []string {
var validtypes []string
for e := range Extensions {
Expand Down Expand Up @@ -458,7 +464,7 @@ func (s *Scanner) error(msg string) {
fmt.Fprintf(os.Stderr, "%s: %s\n", pos, msg)
}

//scanComment scans current line or lines and returns if it is a comment or not
// scanComment scans current line or lines and returns if it is a comment or not
func (s *Scanner) scanComment(ch rune) rune {
isSingle := false
isMulti := false
Expand Down

0 comments on commit 6c26f94

Please sign in to comment.