Skip to content

Commit

Permalink
Use function to replace global vars.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazywei committed May 31, 2015
1 parent 63fc6b7 commit 46e8957
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tokenzier.go
Expand Up @@ -7,25 +7,28 @@ import (
"github.com/lazywei/mockingbird/scanner"
)

var (
// Start state on token, ignore anything till the next newline

// Start state on token, ignore anything till the next newline
func singleLineCmtPtrn() string {
// Why would we need the trailing space here?
singleLineCmtPtrn = `\s*\/\/ |\s*\-\- |\s*# |\s*% |\s*" `
return `\s*\/\/ |\s*\-\- |\s*# |\s*% |\s*" `
}

func multiLineCmtPtrn() string {
// Start state on opening token, ignore anything until the closing
// token is reached.
multiLineCmtPtrn = `\/\*|<!--|{-|\(\*|"""|'''`
return `\/\*|<!--|{-|\(\*|"""|'''`
}

multiLineCmtPairs = map[string]string{
func multiLineCmtPairs() map[string]string {
return map[string]string{
`/*`: `\*\/`, // C
`<!--`: `-->`, // XML
`{-`: `-}`, // Haskell
`(*`: `\*\)`, // Coq
`"""`: `"""`, // Python
`'''`: `'''`, // Python
}
)
}

func ExtractTokens(data string) []string {

Expand All @@ -39,13 +42,13 @@ func ExtractTokens(data string) []string {
if ok {
tokens = append(tokens, "SHEBANG#!"+name)
}
} else if s.IsBol() && scanOrNot(s, singleLineCmtPtrn) {
} else if s.IsBol() && scanOrNot(s, singleLineCmtPtrn()) {

s.SkipUntil(`\n|\z`)

} else if startToken, ok := s.Scan(multiLineCmtPtrn); ok {
} else if startToken, ok := s.Scan(multiLineCmtPtrn()); ok {

closeToken := multiLineCmtPairs[startToken]
closeToken := multiLineCmtPairs()[startToken]
s.SkipUntil(closeToken)

} else if scanOrNot(s, `"`) {
Expand Down

0 comments on commit 46e8957

Please sign in to comment.