From ccf9e0e19c5574c2d9465bb188895351ce9b1487 Mon Sep 17 00:00:00 2001 From: alpha Date: Mon, 18 Jul 2022 02:44:43 +0000 Subject: [PATCH] nicer formatting FossilOrigin-Name: b01735adaf1a9640b7a1ade14effce83de8c90305df1c0f6077b71a6022d90d4 --- ruby/lox.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ruby/lox.rb b/ruby/lox.rb index abe5f6a..5a33abe 100755 --- a/ruby/lox.rb +++ b/ruby/lox.rb @@ -112,12 +112,14 @@ module Lox until state.eos? case - when state.scan(/\/\/(?~\n)/) # ignore line comment + when state.scan(/\/\/(?~\n)/) + # ignore line comment when state.scan(/\/\*/) scan_block_comment(state) when matched = state.scan(TOKENS_RE) state.add_token(TOKENS.fetch(matched)) - when state.scan(/[ \r\t]/) # ignore whitespace + when state.scan(/[ \r\t]/) + # ignore whitespace when state.scan(/\n/) state.line += 1 when state.scan(/"/) @@ -127,8 +129,9 @@ module Lox when identifier = state.scan(/[a-zA-Z_]\w*/) type = KEYWORDS.fetch(identifier, :IDENTIFIER) state.add_token(type) - else state.scan(/./) # keep scanning + else state.errors << Error.new(line: state.line, message: "Unexpected character.") + state.scan(/./) # keep scanning end end