Skip to content

Commit

Permalink
Add to scan a quoted heredoc identifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
harukasan committed Sep 25, 2016
1 parent 0c15dad commit 8f6c885
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,23 @@ func scanHeredocBegin(s *Scanner) (token.Token, []byte) {
default:
return token.Continue, nil
}

var quote byte
if s.char == '\'' {
quote = s.char
s.next()
termBegin = s.offset
}
for token.IsIdent(s.char) {
s.next()
}
term := s.src[termBegin:s.offset]
if quote != 0 {
if s.char != quote {
s.failf("invalid heredoc identifier")
}
s.next()
}
s.pushCtx(stateHeredocFirstLine(term, indent))
return token.HeredocBegin, s.src[s.begin:s.offset]
}
Expand Down
6 changes: 6 additions & 0 deletions scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ var rules = map[string][]struct {
{8, token.HeredocPart, nil},
{14, token.NewLine, nil},
},
"<<-'TEXT'\n TEXT\n": {
{0, token.HeredocBegin, []byte("<<-'TEXT'")},
{9, token.NewLine, nil},
{10, token.HeredocPart, nil},
{16, token.NewLine, nil},
},
"1 <<1\n1\n": {
{0, token.DecimalInteger, []byte("1")},
{2, token.HeredocBegin, []byte("<<1")},
Expand Down

0 comments on commit 8f6c885

Please sign in to comment.