Make formatter a bit more convenient

This commit is contained in:
Roberto Alsina 2024-08-19 10:15:02 -03:00
parent ad92929a10
commit fa647e898a

View File

@ -4,9 +4,11 @@ module Tartrazine
class Json < Formatter
property name = "json"
def format(text : String, lexer : Lexer, outp : IO) : Nil
def format(text : String, lexer : Lexer, io : IO?) : String?
outp = io.nil? ? String::Builder.new("") : io
tokenizer = Tokenizer.new(lexer, text)
outp << Tartrazine::Lexer.collapse_tokens(tokenizer.to_a).to_json
return outp.to_s if io.nil?
end
end
end