diff options
Diffstat (limited to 'stdlib/source/library/lux/control/parser/xml.lux')
-rw-r--r-- | stdlib/source/library/lux/control/parser/xml.lux | 145 |
1 files changed, 0 insertions, 145 deletions
diff --git a/stdlib/source/library/lux/control/parser/xml.lux b/stdlib/source/library/lux/control/parser/xml.lux deleted file mode 100644 index 16802de51..000000000 --- a/stdlib/source/library/lux/control/parser/xml.lux +++ /dev/null @@ -1,145 +0,0 @@ -(.using - [library - [lux (.except) - [abstract - [monad (.only do)]] - [control - ["[0]" try (.only Try) (.open: "[1]#[0]" functor)] - ["[0]" exception (.only exception:)]] - [data - ["[0]" text - ["%" \\format (.only format)]] - [collection - ["[0]" list] - ["[0]" dictionary]] - [format - ["/" xml (.only Attribute Attrs Tag XML)]]] - [meta - ["[0]" symbol (.open: "[1]#[0]" equivalence codec)]]]] - ["[0]" //]) - -(type: .public (Parser a) - (//.Parser [Attrs (List XML)] a)) - -(exception: .public empty_input) -(exception: .public unexpected_input) - -(exception: .public (wrong_tag [expected Tag - actual Tag]) - (exception.report - "Expected" (%.text (/.tag expected)) - "Actual" (%.text (/.tag actual)))) - -(exception: .public (unknown_attribute [expected Attribute - available (List Attribute)]) - (exception.report - "Expected" (%.text (/.attribute expected)) - "Available" (exception.listing (|>> /.attribute %.text) available))) - -(exception: .public (unconsumed_inputs [inputs (List XML)]) - (exception.report - "Inputs" (exception.listing (at /.codec encoded) inputs))) - -(def (result' parser attrs documents) - (All (_ a) (-> (Parser a) Attrs (List XML) (Try a))) - (case (//.result parser [attrs documents]) - {try.#Success [[attrs' remaining] output]} - (if (list.empty? remaining) - {try.#Success output} - (exception.except ..unconsumed_inputs remaining)) - - {try.#Failure error} - {try.#Failure error})) - -(def .public (result parser documents) - (All (_ a) (-> (Parser a) (List XML) (Try a))) - (..result' parser /.attributes documents)) - -(def .public text - (Parser Text) - (function (_ [attrs documents]) - (case documents - {.#End} - (exception.except ..empty_input []) - - {.#Item head tail} - (case head - {/.#Text value} - {try.#Success [[attrs tail] value]} - - {/.#Node _} - (exception.except ..unexpected_input []))))) - -(def .public tag - (Parser Tag) - (function (_ [attrs documents]) - (case documents - {.#End} - (exception.except ..empty_input []) - - {.#Item head _} - (case head - {/.#Text _} - (exception.except ..unexpected_input []) - - {/.#Node tag _ _} - {try.#Success [[attrs documents] tag]})))) - -(def .public (attribute name) - (-> Attribute (Parser Text)) - (function (_ [attrs documents]) - (case (dictionary.value name attrs) - {.#None} - (exception.except ..unknown_attribute [name (dictionary.keys attrs)]) - - {.#Some value} - {try.#Success [[attrs documents] value]}))) - -(def .public (node expected parser) - (All (_ a) (-> Tag (Parser a) (Parser a))) - (function (_ [attrs documents]) - (case documents - {.#End} - (exception.except ..empty_input []) - - {.#Item head tail} - (case head - {/.#Text _} - (exception.except ..unexpected_input []) - - {/.#Node actual attrs' children} - (if (symbol#= expected actual) - (|> children - (..result' parser attrs') - (try#each (|>> [[attrs tail]]))) - (exception.except ..wrong_tag [expected actual])))))) - -(def .public any - (Parser XML) - (function (_ [attrs documents]) - (case documents - {.#End} - (exception.except ..empty_input []) - - {.#Item head tail} - {try.#Success [[attrs tail] head]}))) - -(exception: .public nowhere) - -(def .public (somewhere parser) - (All (_ a) (-> (Parser a) (Parser a))) - (function (again [attrs input]) - (case (//.result parser [attrs input]) - {try.#Success [[attrs remaining] output]} - {try.#Success [[attrs remaining] output]} - - {try.#Failure error} - (case input - {.#End} - (exception.except ..nowhere []) - - {.#Item head tail} - (do try.monad - [[[attrs tail'] output] (again [attrs tail])] - (in [[attrs {.#Item head tail'}] - output])))))) |