Example #1
0
func scan(c *scanner.Scanner) token {
	c.EatWhitespaceAndComments()
	if c.Peek() == '/' {
		c.ReadChar()
		return token{"Divide", ""}
	} else if c.EndOfFile() {
		log.Println("Found EOF")
		return token{"EOF", ""}
	} else if c.Peek() == '-' {
		c.ReadChar()
		chr := c.ReadChar()
		if chr != '>' {
			c.Fail("Found -, and expected a \"to\" statement(->) but found ", chr)
		}
		return token{"To", ""}
	} else if utils.IsAlphabetic(c.Peek()) {
		word := c.ReadWord()
		if word == "States" {
			return token{"States", ""}
		} else if word == "Edges" {
			return token{"Edges", ""}
		}
		return token{"Word", word}

	} else if utils.IsNumeric(c.Peek()) {
		integer := strconv.Itoa(c.ReadNumber())
		return token{"Integer", integer}
	} else {
		c.Fail("Unexpected keyword ", c.Peek())
	}
	return token{}
}