Esempio n. 1
0
File: states.go Progetto: hfern/luao
func stWhitespace(l lex.Lexer) lex.StateFn {
	for next := l.PeekRune(0); inMapR(next, whitespaceChars); next = l.PeekRune(0) {
		l.NextRune()
		if next == '\n' {
			l.NewLine()
		}
	}
	emit(l, Whitespace)
	return stStart
}
Esempio n. 2
0
File: states.go Progetto: hfern/luao
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
}
Esempio n. 3
0
File: states.go Progetto: hfern/luao
func stReadString(l lex.Lexer) lex.StateFn {
	delim := l.NextRune()
	if !(delim == '\'' || delim == '"') {
		emitError("Expected `\"` or `'` to start quote-string.")
	}
	for {
		char := l.NextRune()
		switch char {
		case delim:
			// end of string
			fmt.Println("End of the string!")
			emit(l, String)
			return stStart
		case '\\':
			l.NextRune()
		case lex.RuneEOF:
			l.EmitEOF()
		case '\n':
			l.NewLine()
		}
	}
	return stStart
}