From: Alexis Laferrière Date: Mon, 11 Jan 2016 19:49:11 +0000 (-0500) Subject: lib/parser_base: intro `StringProcessor::eof` and fix index error X-Git-Tag: v0.8~15^2~3 X-Git-Url: http://nitlanguage.org lib/parser_base: intro `StringProcessor::eof` and fix index error Signed-off-by: Alexis Laferrière --- diff --git a/lib/parser_base.nit b/lib/parser_base.nit index 234b733..f97fbf0 100644 --- a/lib/parser_base.nit +++ b/lib/parser_base.nit @@ -101,12 +101,15 @@ class StringProcessor # Ignores any printable character until a whitespace is encountered protected fun ignore_until_whitespace: Int do - while not src[pos].is_whitespace do pos += 1 + while src.length > pos and not src[pos].is_whitespace do pos += 1 return pos end # Returns the current location as a `Location` object protected fun hot_location: Location do return new Location(line, line_offset) + + # Is `pos` at the end of the source? + protected fun eof: Bool do return pos >= src.length end # Information about the location of an entity in a source document