This module provides tools for converting text into a list of blocks, where
type alias Block =
{ indent : Int
, content : String
}Lists of blocks are used by the functions in Tree.Build to construct trees form text. Here are some examples:
> fromStringAsLines "one\n two\n three"
[ { content = "one", indent = 0 }
, { content = "two", indent = 2 }
, { content = "three", indent = 4 }
]
> fromStringAsParagraphs "one\nho ho ho!\n two\n ha ha ha!"
[ { content = "one\nho ho ho!", indent = 0 }
, { content = "two\nha ha ha!", indent = 2 }
]Determine the "quantum of indentation." In a well-formed list of blocks, when the indentation level increases, it increases by one quantum. When it decreases, it decreases by one or more quanta.
> "1\n 2\n 3\n 4" |> fromString |> quantumOfBlocks
1
> "1\n 2\n 3\n 4" |> fromString |> quantumOfBlocks
2
> "1\n 2\n 3" |> fromString |> quantumOfBlocksDetermine if a list of blocks is well-formed, meaning that when the indentation level increases, it increases by one quantum and no more. The return value is a pair consisting of the quantum of indentation and True or False, depending on whethe the list is well-formed.
> "1\n 2\n 3\n 4\n 5" |> fromString |> wellFormed
(1, True)
> "1\n 2\n 3\n 4\n 5" |> fromString |> wellFormed
(1, False)
> "1\n 2\n 3\n 4\n5" |> fromString |> wellFormed
(2, True)