@@ -174,7 +174,7 @@ func (lx *lexer) ignore() {
174
174
lx .start = lx .pos
175
175
}
176
176
177
- // backup steps back one rune. Can be called only twice between calls to next.
177
+ // backup steps back one rune. Can be called 4 times between calls to next.
178
178
func (lx * lexer ) backup () {
179
179
if lx .atEOF {
180
180
lx .atEOF = false
@@ -670,20 +670,28 @@ func lexMultilineString(lx *lexer) stateFn {
670
670
case '\\' :
671
671
return lexMultilineStringEscape
672
672
case stringEnd :
673
+ /// Found " → try to read two more "".
673
674
if lx .accept (stringEnd ) {
674
675
if lx .accept (stringEnd ) {
675
- // Can end in quote: """str""""
676
+ /// Peek ahead: the string can contain " and "", including at the
677
+ /// end: """str"""""
678
+ /// 6 or more at the end, however, is an error.
676
679
if lx .peek () == stringEnd {
680
+ /// Check if we already lexed 5 's; if so we have 6 now, and
681
+ /// that's just too many man!
682
+ if strings .HasSuffix (lx .current (), `"""""` ) {
683
+ return lx .errorf (`unexpected '""""""'` )
684
+ }
677
685
lx .backup ()
678
686
lx .backup ()
679
687
return lexMultilineString
680
688
}
681
689
682
- lx .backup ()
690
+ lx .backup () /// backup: don't include the """ in the item.
683
691
lx .backup ()
684
692
lx .backup ()
685
693
lx .emit (itemMultilineString )
686
- lx .next ()
694
+ lx .next () /// Read over ''' again and discard it.
687
695
lx .next ()
688
696
lx .next ()
689
697
lx .ignore ()
@@ -734,19 +742,28 @@ func lexMultilineRawString(lx *lexer) stateFn {
734
742
}
735
743
return lexMultilineRawString
736
744
case rawStringEnd :
745
+ /// Found ' → try to read two more ''.
737
746
if lx .accept (rawStringEnd ) {
738
747
if lx .accept (rawStringEnd ) {
739
- // Can end in quote: '''str''''
748
+ /// Peek ahead: the string can contain ' and '', including at the
749
+ /// end: '''str'''''
750
+ /// 6 or more at the end, however, is an error.
740
751
if lx .peek () == rawStringEnd {
752
+ /// Check if we already lexed 5 's; if so we have 6 now, and
753
+ /// that's just too many man!
754
+ if strings .HasSuffix (lx .current (), "'''''" ) {
755
+ return lx .errorf (`unexpected "''''''"` )
756
+ }
741
757
lx .backup ()
742
758
lx .backup ()
743
759
return lexMultilineRawString
744
760
}
745
- lx .backup ()
761
+
762
+ lx .backup () /// backup: don't include the ''' in the item.
746
763
lx .backup ()
747
764
lx .backup ()
748
765
lx .emit (itemRawMultilineString )
749
- lx .next ()
766
+ lx .next () /// Read over ''' again and discard it.
750
767
lx .next ()
751
768
lx .next ()
752
769
lx .ignore ()
0 commit comments