From fa647e898a4d1e48a41a5e17d7daf235da540fb1 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Mon, 19 Aug 2024 10:15:02 -0300 Subject: [PATCH] Make formatter a bit more convenient --- src/formatters/json.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/formatters/json.cr b/src/formatters/json.cr index 9e03d21..857723b 100644 --- a/src/formatters/json.cr +++ b/src/formatters/json.cr @@ -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