mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Make formatter a bit more convenient
This commit is contained in:
parent
ad92929a10
commit
fa647e898a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user