Skip to content

Commit

Permalink
Add ability to ignore script lines (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
TekWizely committed Mar 15, 2020
1 parent 0da0b32 commit a73a61a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions internal/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,34 @@ func lexCmdScriptLine(_ *LexContext, l *lexer.Lexer) LexFn {
return lexCmdScriptLine
}
m := l.Marker()
// # at beginning of script line = ignore line
//
if peekRuneEquals(l, runeHash) {
// Consume comment block
//
for peekRuneEquals(l, runeHash) {
l.Next()
// Consume rest of line, including newline
//
for !matchNewlineOrEOF(l) {
l.Next()
}
}
// If the line following the comment block is not part of the script,
// then assume the comment is also not part of the script
// NOTE: We have to include RBrace here on the chance that the user
// is using braces to wrap the script.
//
m2 := l.Marker()
if matchNewlineOrEOF(l) || matchOneOrMore(l, isSpaceOrTab) || matchRune(l, runeRBrace) {
m2.Apply()
l.Clear() // Discard the comment block
return lexCmdScriptLine
}
m.Apply() // End script before comment block
l.EmitType(TokenScriptEnd)
return nil
}
// !whitespace at beginning of non-blank line terminates script
//
if !matchOneOrMore(l, isSpaceOrTab) {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// Version stores the version tag - Should include leading 'v' - Update before tagging new versions.
//
var Version = "v0.7.1+assert"
var Version = "v0.7.1+assert.script-comments"

// BuildDate is optional and can be set using '-ldflags "-X 'main.BuildDate=..."'.
//
Expand Down

0 comments on commit a73a61a

Please sign in to comment.