Example #1
0
func (c *Scanner) eatwhitespace() {
	for !c.EndOfFile() {
		if utils.IsWhitespace(c.Peek()) {
			c.ReadChar()
		} else {
			break
		}
	}
}
Example #2
0
func (c *Scanner) ReadWord() string {
	if !utils.IsAlphabetic(c.Peek()) {
		c.Fail("Could not read word")
	}
	word := string(c.ReadChar())
	for !c.EndOfFile() {
		if utils.IsAlphabetic(c.Peek()) || utils.IsNumeric(c.Peek()) {
			word += string(c.ReadChar())
		} else if utils.IsWhitespace(c.Peek()) || c.Peek() == '/' {
			break
		} else {
			c.Fail("Reading a word failed, found '", word, "' but then unexpected ", string(c.Peek()))
		}
	}
	return word
}
Example #3
0
func (c *Scanner) ReadNumber() int {
	number := ""
	for !c.EndOfFile() {
		if utils.IsNumeric(c.Peek()) {
			number += string(c.ReadChar())
		} else if utils.IsWhitespace(c.Peek()) || c.Peek() == '/' {
			break
		} else {
			c.Fail("Expected whitespace after the number "+number+", but got ", string(c.Peek()))
		}
	}

	if len(number) == 0 {
		c.Fail("Did not read any number")
	}

	numbasint, err := strconv.Atoi(number)
	if err != nil {
		c.Fail("Could not convert to number. Something really bad happened, and should never happen. Please contact the developers at https://github.com/jbossen/P7-code")
	}

	return numbasint
}