import gleam/io import gleam/list import gleam/string pub fn parse(input: String) -> Nil { let input = input |> string.to_graphemes() |> handle_comments([], False) |> handle_whitespace() input |> list.each(io.print) } // [TODO]: handle into slashdash comments for nodes fn handle_comments( input: List(String), accumulator: List(String), in_comment: Bool, ) -> List(String) { case input { // [TODO]: Check if in a string. ["/", "/", ..input] -> input |> list.drop_while(fn(g) { g != "\n" }) |> handle_comments(accumulator, in_comment) ["/", "*", ..input] -> input |> handle_comments(accumulator, True) ["*", "/", ..input] if in_comment -> input |> handle_comments(accumulator, False) [_, ..input] if in_comment -> input |> handle_comments(accumulator, in_comment) [g, ..input] -> input |> handle_comments([g, ..accumulator], in_comment) [] -> accumulator } } // [TODO]: Look into how KDL uses whitespace, and more potential things needed to be handled. fn handle_whitespace(input: List(String)) -> List(String) { case input { [" ", ..input] -> handle_whitespace(input) ["\t", ..input] -> handle_whitespace(input) ["\n", ..input] -> handle_whitespace(input) ["\r\n", ..input] -> handle_whitespace(input) _ -> input } }