Beispiel #1
0
func readLongString(l lex.Lexer) bool {
	numEquals := longStringEquals('[', l)
	if numEquals < 0 {
		emitError("Expecting [ to start string.")
		return false
	}
	// eat first [
	l.NextRune()

	for i := 0; i < numEquals; i++ {
		if l.NextRune() != '=' {
			emitError("Expected string `=` padding.")
			return false
		}
	}

	// gobble string contents
	for {
		char := l.NextRune()
		if char == lex.RuneEOF {
			emitError("Unexpected EOF. Expecting long-string close.")
			return false
		}

		if char == '\n' {
			l.NewLine()
		}

		// potential close
		if char == ']' {
			// ungobble first ]
			l.BackupRune()
			closingCt := longStringEquals(']', l)
			if closingCt != numEquals {
				// re-gobble the ]
				l.NextRune()
			} else {
				// it was our close!
				// eat the closing bits
				l.NextRune()
				for i := 0; i < numEquals; i++ {
					if l.NextRune() != '=' {
						emitError("Expected close-string `=` padding.")
					}
				}
				l.NextRune()
				return true
			}
		}

	}

	return false
}