Read a byte and put it in last_char.

In case of an end-of-file or an error, put -1 in last_char.

Property definitions

saxophonit $ XophonLexer :: read_char
	# Read a byte and put it in `last_char`.
	#
	# In case of an end-of-file or an error, put -1 in `last_char`.
	private fun read_char do
		if locator.line_number < 0 then
			locator.line_number = 1
			locator.column_number = 1
		else if last_char < 0 then
			fire_fatal_error("Internal error: Already at the end of the file.")
			return
		else if last_char == '\n'.code_point then
			locator.line_number += 1
			locator.column_number = 1
		else
			locator.column_number += 1
		end

		var s = input.read_byte
		if s < 0 then
			last_char = -1
			return
		end
		last_char = s.to_i

		# XML 1.0 end-of-line handling
		# Note: Regardless the XML version, any EOL defined by the
		# recommandation MUST be reported as a single LINE FEED.
		if was_cr and last_char == '\n'.code_point then
			# EOL already reported. => Skip this byte.
			s = input.read_byte
			if s < 0 then
				last_char = -1
			else
				last_char = s
			end
		end
		was_cr = last_char == '\r'.code_point
		if was_cr then
			# Regardless the following byte, '\r' always introduce an EOL.
			last_char = '\n'.code_point
		end
	end
lib/saxophonit/lexer.nit:240,2--281,4