this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/scanner: allow leading double-quote in #-quoted string

Fixes #1649.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I2343130f714d841d376689117689c8540d0894bd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/537220
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+22 -6
+16 -6
cue/scanner/scanner.go
··· 567 567 return s.ch, true 568 568 } 569 569 570 - func (s *Scanner) checkHashCount(offs int, quote quoteInfo) { 571 - for i := 0; i < quote.numHash; i++ { 570 + func (s *Scanner) scanHashes(maxHash int) int { 571 + for i := 0; i < maxHash; i++ { 572 572 if s.ch != '#' { 573 - s.errf(offs, "string literal not terminated") 574 - return 573 + return i 575 574 } 576 575 s.next() 577 576 } 577 + return maxHash 578 578 } 579 579 580 580 func stripCR(b []byte) []byte { ··· 830 830 quote.numChar = 1 831 831 tok, lit = s.scanString(offs, quote) 832 832 case 1: 833 - s.checkHashCount(offs, quote) 834 - tok, lit = token.STRING, string(s.src[offs:s.offset]) 833 + // When the string is surrounded by hashes, 834 + // a single leading quote is OK (and part of the string) 835 + // e.g. #""hello""# 836 + // unless it's succeeded by the correct number of terminating 837 + // hash characters 838 + // e.g. ##""## 839 + if n := s.scanHashes(quote.numHash); n == quote.numHash { 840 + // It's the empty string. 841 + tok, lit = token.STRING, string(s.src[offs:s.offset]) 842 + } else { 843 + tok, lit = s.scanString(offs, quote) 844 + } 835 845 case 2: 836 846 quote.numChar = 3 837 847 switch s.ch {
+6
cue/scanner/scanner_test.go
··· 125 125 {token.STRING, "'foobar'", literal}, 126 126 {token.STRING, `'foo\/bar'`, literal}, 127 127 {token.STRING, `#" ""#`, literal}, 128 + {token.STRING, `#"" "#`, literal}, 129 + {token.STRING, `#""hello""#`, literal}, 130 + {token.STRING, `##""# "##`, literal}, 131 + {token.STRING, `####""###"####`, literal}, 132 + {token.STRING, "##\"\"\"\n\"\"\"#\n\"\"\"##", literal}, 133 + {token.STRING, `##"####"##`, literal}, 128 134 {token.STRING, `#"foobar"#`, literal}, 129 135 {token.STRING, `#"\r"#`, literal}, 130 136 {token.STRING, `#"\("#`, literal},