From da79da086a028a55130fbbbc5e08ed0ce736ff96 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 14 Jun 2022 21:28:23 -0400 Subject: New "parser" hierarchy. [Part 2] --- stdlib/source/format/lux/data/binary.lux | 55 ++- .../source/library/lux/control/parser/binary.lux | 308 ---------------- .../library/lux/control/parser/synthesis.lux | 161 --------- stdlib/source/library/lux/data/format/tar.lux | 8 +- stdlib/source/library/lux/extension.lux | 7 +- stdlib/source/library/lux/tool/compiler.lux | 10 +- .../library/lux/tool/compiler/language/lux.lux | 8 +- .../language/lux/phase/extension/directive/jvm.lux | 72 ++-- .../extension/generation/common_lisp/common.lux | 8 +- .../extension/generation/common_lisp/host.lux | 39 +- .../lux/phase/extension/generation/js/common.lux | 8 +- .../lux/phase/extension/generation/js/host.lux | 7 +- .../lux/phase/extension/generation/jvm/common.lux | 10 +- .../lux/phase/extension/generation/jvm/host.lux | 278 +++++++-------- .../lux/phase/extension/generation/lua/common.lux | 8 +- .../lux/phase/extension/generation/lua/host.lux | 7 +- .../lux/phase/extension/generation/php/common.lux | 8 +- .../lux/phase/extension/generation/php/host.lux | 7 +- .../phase/extension/generation/python/common.lux | 8 +- .../lux/phase/extension/generation/python/host.lux | 7 +- .../lux/phase/extension/generation/r/common.lux | 8 +- .../lux/phase/extension/generation/r/host.lux | 7 +- .../lux/phase/extension/generation/ruby/common.lux | 8 +- .../lux/phase/extension/generation/ruby/host.lux | 7 +- .../phase/extension/generation/scheme/common.lux | 8 +- .../lux/phase/extension/generation/scheme/host.lux | 7 +- .../library/lux/tool/compiler/meta/archive.lux | 10 +- .../compiler/meta/archive/module/descriptor.lux | 8 +- .../tool/compiler/meta/archive/module/document.lux | 6 +- .../lux/tool/compiler/meta/archive/registry.lux | 8 +- .../lux/tool/compiler/meta/archive/signature.lux | 6 +- .../library/lux/tool/compiler/meta/import.lux | 8 +- .../library/lux/tool/compiler/meta/io/archive.lux | 8 +- stdlib/source/parser/lux/data/binary.lux | 308 ++++++++++++++++ .../lux/tool/compiler/language/lux/synthesis.lux | 162 +++++++++ stdlib/source/test/lux/control/parser.lux | 4 - stdlib/source/test/lux/control/parser/binary.lux | 392 --------------------- .../source/test/lux/control/parser/synthesis.lux | 205 ----------- stdlib/source/test/lux/data/binary.lux | 376 +++++++++++++++++++- stdlib/source/test/lux/data/format/tar.lux | 6 +- stdlib/source/test/lux/extension.lux | 20 +- stdlib/source/test/lux/tool.lux | 7 +- .../lux/tool/compiler/language/lux/synthesis.lux | 216 ++++++++++++ .../compiler/meta/archive/module/descriptor.lux | 7 +- .../tool/compiler/meta/archive/module/document.lux | 7 +- .../lux/tool/compiler/meta/archive/registry.lux | 7 +- .../lux/tool/compiler/meta/archive/signature.lux | 7 +- .../source/test/lux/tool/compiler/meta/export.lux | 7 +- .../source/test/lux/tool/compiler/meta/import.lux | 7 +- 49 files changed, 1411 insertions(+), 1450 deletions(-) delete mode 100644 stdlib/source/library/lux/control/parser/binary.lux delete mode 100644 stdlib/source/library/lux/control/parser/synthesis.lux create mode 100644 stdlib/source/parser/lux/data/binary.lux create mode 100644 stdlib/source/parser/lux/tool/compiler/language/lux/synthesis.lux delete mode 100644 stdlib/source/test/lux/control/parser/binary.lux delete mode 100644 stdlib/source/test/lux/control/parser/synthesis.lux create mode 100644 stdlib/source/test/lux/tool/compiler/language/lux/synthesis.lux (limited to 'stdlib') diff --git a/stdlib/source/format/lux/data/binary.lux b/stdlib/source/format/lux/data/binary.lux index e29a737ce..a0b96a581 100644 --- a/stdlib/source/format/lux/data/binary.lux +++ b/stdlib/source/format/lux/data/binary.lux @@ -7,10 +7,9 @@ [monad (.only Monad do)] [equivalence (.only Equivalence)]] [control + ["<>" parser (.open: "[1]#[0]" monad)] ["[0]" pipe] - ["[0]" function] - ["<>" parser (.open: "[1]#[0]" monad) - ["" binary (.only Offset Size Parser)]]] + ["[0]" function]] [data ["[0]" product] [text @@ -30,8 +29,8 @@ ["n" nat] ["[0]" i64] ["[0]" frac]]]]] - [\\unsafe - ["[0]" / (.only Binary)]]) + ["[0]" \\unsafe (.only Binary)] + ["" \\parser (.only Offset Size Parser)]) (with_template [ ] [(def: @@ -59,7 +58,7 @@ (def: .public (instance [size mutation]) (-> Specification Binary) - (|> size /.empty [0] mutation product.right)) + (|> size \\unsafe.empty [0] mutation product.right)) (def: .public monoid (Monoid Specification) @@ -87,10 +86,10 @@ [(n#+ offset) ( offset value binary)])]))] - [bits_8 .size_8 /.has_8!] - [bits_16 .size_16 /.has_16!] - [bits_32 .size_32 /.has_32!] - [bits_64 .size_64 /.has_64!] + [bits_8 .size_8 \\unsafe.has_8!] + [bits_16 .size_16 \\unsafe.has_16!] + [bits_32 .size_32 \\unsafe.has_32!] + [bits_64 .size_64 \\unsafe.has_64!] ) (def: .public (or left right) @@ -103,7 +102,7 @@ [(.++ caseS) (function (_ [offset binary]) (|> binary - (/.has_8! offset ) + (\\unsafe.has_8! offset ) [(.++ offset)] caseT))])]) ([0 .#Left left] @@ -146,30 +145,30 @@ [size (function (_ [offset binary]) [(n#+ size offset) - (/.copy! (n.min size (/.size value)) - 0 - value - offset - binary)])])) + (\\unsafe.copy! (n.min size (\\unsafe.size value)) + 0 + value + offset + binary)])])) (with_template [ ] [(def: .public (Writer Binary) (let [mask (..mask )] (function (_ value) - (let [size (|> value /.size (i64.and mask)) + (let [size (|> value \\unsafe.size (i64.and mask)) size' (n#+ size)] [size' (function (_ [offset binary]) [(n#+ size' offset) (|> binary ( offset size) - (/.copy! size 0 value (n#+ offset)))])]))))] + (\\unsafe.copy! size 0 value (n#+ offset)))])]))))] - [binary_8 ..bits_8 .size_8 /.has_8!] - [binary_16 ..bits_16 .size_16 /.has_16!] - [binary_32 ..bits_32 .size_32 /.has_32!] - [binary_64 ..bits_64 .size_64 /.has_64!] + [binary_8 ..bits_8 .size_8 \\unsafe.has_8!] + [binary_16 ..bits_16 .size_16 \\unsafe.has_16!] + [binary_32 ..bits_32 .size_32 \\unsafe.has_32!] + [binary_64 ..bits_64 .size_64 \\unsafe.has_64!] ) (with_template [ ] @@ -209,10 +208,10 @@ [(n#+ offset)] mutation))])))] - [sequence_8 .size_8 /.has_8!] - [sequence_16 .size_16 /.has_16!] - [sequence_32 .size_32 /.has_32!] - [sequence_64 .size_64 /.has_64!] + [sequence_8 .size_8 \\unsafe.has_8!] + [sequence_16 .size_16 \\unsafe.has_16!] + [sequence_32 .size_32 \\unsafe.has_32!] + [sequence_64 .size_64 \\unsafe.has_64!] ) (def: .public maybe @@ -248,7 +247,7 @@ [(.++ caseS) (function (_ [offset binary]) (|> binary - (/.has_8! offset ) + (\\unsafe.has_8! offset ) [(.++ offset)] caseT))])]) ([0 .#Primitive (..and ..text (..list again))] @@ -282,7 +281,7 @@ [(.++ caseS) (function (_ [offset binary]) (|> binary - (/.has_8! offset ) + (\\unsafe.has_8! offset ) [(.++ offset)] caseT))])]) ([0 .#Bit ..bit] diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux deleted file mode 100644 index 98d23b610..000000000 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ /dev/null @@ -1,308 +0,0 @@ -(.using - [library - [lux (.except and or nat int rev list type symbol) - [ffi (.only)] - [type (.only sharing)] - [abstract - [hash (.only Hash)] - [monad (.only do)]] - [control - ["[0]" try (.only Try)] - ["[0]" exception (.only exception:)]] - [data - ["/" binary - ["[1]" \\unsafe (.only Binary)]] - [text - ["%" \\format (.only format)] - [encoding - ["[0]" utf8]]] - [collection - ["[0]" list] - ["[0]" sequence (.only Sequence)] - ["[0]" set (.only Set)] - [array - [\\unsafe (.only)]]]] - [macro - ["^" pattern] - ["[0]" template]] - [math - [number - ["n" nat] - ["[0]" frac]]]]] - ["[0]" // (.open: "[1]#[0]" monad)]) - -(type: .public Offset - Nat) - -(type: .public Parser - (//.Parser [Offset Binary])) - -(exception: .public (binary_was_not_fully_read [binary_length Nat - bytes_read Nat]) - (exception.report - "Binary length" (%.nat binary_length) - "Bytes read" (%.nat bytes_read))) - -(with_template [ ] - [(def: - (template ( ) - [( )]))] - - [n#= "lux i64 ="] - [n#+ "lux i64 +"] - [n#- "lux i64 -"] - ) - -(def: .public (result parser input) - (All (_ a) (-> (Parser a) Binary (Try a))) - (case (parser [0 input]) - {try.#Success [[end _] output]} - (let [length (/.size input)] - (if (n#= end length) - {try.#Success output} - (exception.except ..binary_was_not_fully_read [length end]))) - - failure - (as_expected failure))) - -(def: .public end? - (Parser Bit) - (function (_ (^.let input [offset data])) - {try.#Success [input (n#= offset (/.size data))]})) - -(def: .public offset - (Parser Offset) - (function (_ (^.let input [offset data])) - {try.#Success [input offset]})) - -(def: .public remaining - (Parser Nat) - (function (_ (^.let input [offset data])) - {try.#Success [input (n#- offset (/.size data))]})) - -(type: .public Size - Nat) - -(def: .public size_8 Size 1) -(def: .public size_16 Size (n.* 2 size_8)) -(def: .public size_32 Size (n.* 2 size_16)) -(def: .public size_64 Size (n.* 2 size_32)) - -(exception: .public (range_out_of_bounds [length Nat - start Nat - end Nat]) - (exception.report - "Length" (%.nat length) - "Range start" (%.nat start) - "Range end" (%.nat end))) - -(with_template [ ] - [(def: .public - (Parser I64) - (function (_ [start binary]) - (let [end (n#+ start)] - (if (n.< end (/.size binary)) - (exception.except ..range_out_of_bounds [(/.size binary) start end]) - (|> ( start binary) - [[end binary]] - {try.#Success})))))] - - [bits_8 ..size_8 /.bits_8] - [bits_16 ..size_16 /.bits_16] - [bits_32 ..size_32 /.bits_32] - [bits_64 ..size_64 /.bits_64] - ) - -(with_template [ ] - [(def: .public (Parser ) ..bits_64)] - - [nat Nat] - [int Int] - [rev Rev] - ) - -(def: .public frac - (Parser Frac) - (//#each frac.of_bits ..bits_64)) - -(exception: .public (invalid_tag [range Nat - byte Nat]) - (exception.report - "Tag range" (%.nat range) - "Tag value" (%.nat byte))) - -(def: !variant - (template (!variant +) - [(do [! //.monad] - [flag (is (Parser Nat) - ..bits_8)] - (with_expansions [+' (template.spliced +)] - (case flag - (^.with_template [ ] - [ (`` (at ! each (|>> {(~~ (template.spliced ))}) ))]) - (+') - - _ (//.lifted (exception.except ..invalid_tag [(template.amount [+]) flag])))))])) - -(def: .public (or left right) - (All (_ l r) (-> (Parser l) (Parser r) (Parser (Or l r)))) - (!variant [[0 [.#Left] left] - [1 [.#Right] right]])) - -(def: .public (rec body) - (All (_ a) (-> (-> (Parser a) (Parser a)) (Parser a))) - (function (_ input) - (let [parser (body (rec body))] - (parser input)))) - -(def: .public any - (Parser Any) - (//#in [])) - -(exception: .public (not_a_bit [value Nat]) - (exception.report - "Expected values" "either 0 or 1" - "Actual value" (%.nat value))) - -(def: .public bit - (Parser Bit) - (do //.monad - [value (is (Parser Nat) - ..bits_8)] - (case value - 0 (in #0) - 1 (in #1) - _ (//.lifted (exception.except ..not_a_bit [value]))))) - -(def: .public (segment size) - (-> Nat (Parser Binary)) - (case size - 0 (//#in (/.empty 0)) - _ (function (_ [start binary]) - (let [end (n#+ size start)] - (if (n.< end (/.size binary)) - (exception.except ..range_out_of_bounds [(/.size binary) start end]) - (|> binary - (/.slice start size) - [[end binary]] - {try.#Success})))))) - -(with_template [ ] - [(`` (def: .public - (Parser Binary) - (do //.monad - [size (//#each (|>> .nat) )] - (..segment size))))] - - [08 binary_8 ..bits_8] - [16 binary_16 ..bits_16] - [32 binary_32 ..bits_32] - [64 binary_64 ..bits_64] - ) - -(with_template [ ] - [(`` (def: .public - (Parser Text) - (do //.monad - [utf8 ] - (//.lifted (at utf8.codec decoded utf8)))))] - - [08 utf8_8 ..binary_8] - [16 utf8_16 ..binary_16] - [32 utf8_32 ..binary_32] - [64 utf8_64 ..binary_64] - ) - -(def: .public text ..utf8_64) - -(with_template [ ] - [(def: .public ( valueP) - (All (_ v) (-> (Parser v) (Parser (Sequence v)))) - (do //.monad - [amount (is (Parser Nat) - )] - (loop (again [index 0 - output (sharing [v] - (Parser v) - valueP - - (Sequence v) - sequence.empty)]) - (if (n.< amount index) - (do //.monad - [value valueP] - (again (.++ index) - (sequence.suffix value output))) - (//#in output)))))] - - [08 sequence_8 ..bits_8] - [16 sequence_16 ..bits_16] - [32 sequence_32 ..bits_32] - [64 sequence_64 ..bits_64] - ) - -(def: .public maybe - (All (_ a) (-> (Parser a) (Parser (Maybe a)))) - (..or ..any)) - -(def: .public (list value) - (All (_ a) (-> (Parser a) (Parser (List a)))) - (..rec - (|>> (//.and value) - (..or ..any)))) - -(exception: .public set_elements_are_not_unique) - -(def: .public (set hash value) - (All (_ a) (-> (Hash a) (Parser a) (Parser (Set a)))) - (do //.monad - [raw (..list value) - .let [output (set.of_list hash raw)] - _ (//.assertion (exception.error ..set_elements_are_not_unique []) - (n#= (list.size raw) - (set.size output)))] - (in output))) - -(def: .public symbol - (Parser Symbol) - (//.and ..text ..text)) - -(def: .public type - (Parser Type) - (..rec - (function (_ type) - (let [pair (//.and type type) - indexed ..nat - quantified (//.and (..list type) type)] - (!variant [[0 [.#Primitive] (//.and ..text (..list type))] - [1 [.#Sum] pair] - [2 [.#Product] pair] - [3 [.#Function] pair] - [4 [.#Parameter] indexed] - [5 [.#Var] indexed] - [6 [.#Ex] indexed] - [7 [.#UnivQ] quantified] - [8 [.#ExQ] quantified] - [9 [.#Apply] pair] - [10 [.#Named] (//.and ..symbol type)]]))))) - -(def: .public location - (Parser Location) - (all //.and ..text ..nat ..nat)) - -(def: .public code - (Parser Code) - (..rec - (function (_ again) - (let [sequence (..list again)] - (//.and ..location - (!variant [[0 [.#Bit] ..bit] - [1 [.#Nat] ..nat] - [2 [.#Int] ..int] - [3 [.#Rev] ..rev] - [4 [.#Frac] ..frac] - [5 [.#Text] ..text] - [6 [.#Symbol] ..symbol] - [7 [.#Form] sequence] - [8 [.#Variant] sequence] - [9 [.#Tuple] sequence]])))))) diff --git a/stdlib/source/library/lux/control/parser/synthesis.lux b/stdlib/source/library/lux/control/parser/synthesis.lux deleted file mode 100644 index 9e73bf80c..000000000 --- a/stdlib/source/library/lux/control/parser/synthesis.lux +++ /dev/null @@ -1,161 +0,0 @@ -(.using - [library - [lux (.except function loop i64 local) - [abstract - [monad (.only do)]] - [control - ["[0]" try (.only Try)] - ["[0]" exception (.only exception:)]] - [data - ["[0]" bit] - ["[0]" text (.only) - ["%" \\format (.only format)]] - [collection - ["[0]" list]]] - [math - [number - ["n" nat] - ["[0]" i64] - ["[0]" frac]]] - [meta - ["[0]" symbol]] - [tool - [compiler - [reference (.only) - [variable (.only Register)]] - [arity (.only Arity)] - [language - [lux - [analysis (.only Environment)] - ["/" synthesis (.only Synthesis Abstraction)]]]]]]] - ["[0]" //]) - -(exception: .public (cannot_parse [input (List Synthesis)]) - (exception.report - "Input" (exception.listing /.%synthesis input))) - -(exception: .public (unconsumed_input [input (List Synthesis)]) - (exception.report - "Input" (exception.listing /.%synthesis input))) - -(exception: .public (expected_empty_input [input (List Synthesis)]) - (exception.report - "Input" (exception.listing /.%synthesis input))) - -(exception: .public (wrong_arity [expected Arity - actual Arity]) - (exception.report - "Expected" (%.nat expected) - "Actual" (%.nat actual))) - -(exception: .public empty_input) - -(type: .public Parser - (//.Parser (List Synthesis))) - -(def: .public (result parser input) - (All (_ a) (-> (Parser a) (List Synthesis) (Try a))) - (case (parser input) - {try.#Failure error} - {try.#Failure error} - - {try.#Success [{.#End} value]} - {try.#Success value} - - {try.#Success [unconsumed _]} - (exception.except ..unconsumed_input unconsumed))) - -(def: .public any - (Parser Synthesis) - (.function (_ input) - (case input - {.#End} - (exception.except ..empty_input []) - - {.#Item [head tail]} - {try.#Success [tail head]}))) - -(def: .public end - (Parser Any) - (.function (_ tokens) - (case tokens - {.#End} {try.#Success [tokens []]} - _ (exception.except ..expected_empty_input [tokens])))) - -(def: .public end? - (Parser Bit) - (.function (_ tokens) - {try.#Success [tokens (case tokens - {.#End} true - _ false)]})) - -(with_template [ ] - [(`` (def: .public - (Parser ) - (.function (_ input) - (case input - (pattern (list.partial ( x) input')) - {try.#Success [input' x]} - - _ - (exception.except ..cannot_parse input))))) - - (`` (def: .public ( expected) - (-> (Parser Any)) - (.function (_ input) - (case input - (pattern (list.partial ( actual) input')) - (if (at = expected actual) - {try.#Success [input' []]} - (exception.except ..cannot_parse input)) - - _ - (exception.except ..cannot_parse input)))))] - - [bit this_bit /.bit Bit bit.equivalence] - [i64 this_i64 /.i64 I64 i64.equivalence] - [f64 this_f64 /.f64 Frac frac.equivalence] - [text this_text /.text Text text.equivalence] - [local this_local /.variable/local Nat n.equivalence] - [foreign this_foreign /.variable/foreign Nat n.equivalence] - [constant this_constant /.constant Symbol symbol.equivalence] - ) - -(def: .public (tuple parser) - (All (_ a) (-> (Parser a) (Parser a))) - (.function (_ input) - (case input - (pattern (list.partial (/.tuple head) tail)) - (do try.monad - [output (..result parser head)] - {try.#Success [tail output]}) - - _ - (exception.except ..cannot_parse input)))) - -(def: .public (function expected parser) - (All (_ a) (-> Arity (Parser a) (Parser [(Environment Synthesis) a]))) - (.function (_ input) - (case input - (pattern (list.partial (/.function/abstraction [environment actual body]) tail)) - (if (n.= expected actual) - (do try.monad - [output (..result parser (list body))] - {try.#Success [tail [environment output]]}) - (exception.except ..wrong_arity [expected actual])) - - _ - (exception.except ..cannot_parse input)))) - -(def: .public (loop init_parsers iteration_parser) - (All (_ a b) (-> (Parser a) (Parser b) (Parser [Register a b]))) - (.function (_ input) - (case input - (pattern (list.partial (/.loop/scope [start inits iteration]) tail)) - (do try.monad - [inits (..result init_parsers inits) - iteration (..result iteration_parser (list iteration))] - {try.#Success [tail [start inits iteration]]}) - - _ - (exception.except ..cannot_parse input)))) diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index 29e03f5cd..1c75474cf 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -5,16 +5,16 @@ [abstract [monad (.only do)]] [control + ["<>" parser] ["[0]" pipe] ["[0]" try (.only Try)] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data ["[0]" product] ["[0]" binary (.only Binary) ["[1]!" \\unsafe] - ["[0]" \\format (.only Writer) (.open: "[1]#[0]" monoid)]] + ["[0]" \\format (.only Writer) (.open: "[1]#[0]" monoid)] + ["<[1]>" \\parser (.only Parser)]] ["[0]" text (.only Char) ["%" \\format (.only format)] [encoding diff --git a/stdlib/source/library/lux/extension.lux b/stdlib/source/library/lux/extension.lux index 51ca6a3d3..424cfcba8 100644 --- a/stdlib/source/library/lux/extension.lux +++ b/stdlib/source/library/lux/extension.lux @@ -5,8 +5,7 @@ ["[0]" monad]] [control ["<>" parser (.open: "[1]#[0]" monad) - ["" code (.only Parser)] - ["" synthesis]]] + ["" code (.only Parser)]]] [data ["[0]" product] [collection @@ -20,7 +19,9 @@ [language [lux [analysis - ["" \\parser]]]]]]]]) + ["" \\parser]] + [synthesis + ["" \\parser]]]]]]]]) (type: Declaration (Record diff --git a/stdlib/source/library/lux/tool/compiler.lux b/stdlib/source/library/lux/tool/compiler.lux index 7e1bfc2c3..2912dc635 100644 --- a/stdlib/source/library/lux/tool/compiler.lux +++ b/stdlib/source/library/lux/tool/compiler.lux @@ -2,14 +2,14 @@ [library [lux (.except Module Code) [control + ["<>" parser (.only)] ["[0]" try (.only Try)] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data ["[0]" text] - [binary (.only Binary) - [\\format (.only Writer)]]] + ["[0]" binary (.only Binary) + [\\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]]] [world ["[0]" file (.only Path)]]]] [/ diff --git a/stdlib/source/library/lux/tool/compiler/language/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux.lux index a5c8c9167..084348037 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux.lux @@ -2,11 +2,11 @@ [library [lux (.except) [control - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["<>" parser]] [data - [binary - ["_" \\format (.only Writer)]]] + ["[0]" binary + ["_" \\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]]] [meta ["[0]" version]]]] ["[0]" / diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux index 957b2339d..41076ca66 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux @@ -9,8 +9,7 @@ ["[0]" try (.only Try) (.open: "[1]#[0]" functor)] ["[0]" exception] ["<>" parser (.open: "[1]#[0]" monad) - ["<[0]>" code (.only Parser)] - ["<[0]>" synthesis]]] + ["<[0]>" code (.only Parser)]]] [data ["[0]" product] [binary (.only Binary) @@ -64,12 +63,13 @@ ["[1]" artifact]]]] [language [lux - ["[0]" synthesis (.only Synthesis)] ["[0]" generation] ["[0]" directive (.only Handler Bundle)] ["[0]" analysis (.only Analysis) ["[0]A" type] ["[0]A" scope]] + ["[0]" synthesis (.only Synthesis) + ["<[1]>" \\parser]] [phase [generation [jvm @@ -689,16 +689,16 @@ (try#each (|>> (\\format.result class.writer) [name]) (class.class version.v6_0 - (all modifier#composite - class.public - modifier) - (name.internal name) - {.#Some signature} - (..class_name super) - (list#each ..class_name interfaces) - fields - methods - sequence.empty)))) + (all modifier#composite + class.public + modifier) + (name.internal name) + {.#Some signature} + (..class_name super) + (list#each ..class_name interfaces) + fields + methods + sequence.empty)))) (def: (mock_value valueT) (-> (Type Value) (Bytecode Any)) @@ -906,16 +906,16 @@ bytecode (<| (at ! each (\\format.result class.writer)) phase.lifted (class.class version.v6_0 - (all modifier#composite - class.public - inheritance) - (name.internal name) - {.#Some type_declaration} - (..class_name super) - (list#each ..class_name interfaces) - (list#each ..field_definition fields) - (list#each product.right methods) - sequence.empty)) + (all modifier#composite + class.public + inheritance) + (name.internal name) + {.#Some type_declaration} + (..class_name super) + (list#each ..class_name interfaces) + (list#each ..field_definition fields) + (list#each product.right methods) + sequence.empty)) _ (..save_class! name bytecode all_dependencies)] (in directive.no_requirements)))])) @@ -945,19 +945,19 @@ [bytecode (<| (at ! each (\\format.result class.writer)) phase.lifted (class.class version.v6_0 - (all modifier#composite - class.public - class.abstract - class.interface) - (name.internal name) - {.#Some (signature.inheritance (list#each type.signature parameters) - (type.signature $Object) - (list#each type.signature supers))} - (name.internal "java.lang.Object") - (list#each ..class_name supers) - (list) - (list#each ..method_declaration method_declarations) - sequence.empty)) + (all modifier#composite + class.public + class.abstract + class.interface) + (name.internal name) + {.#Some (signature.inheritance (list#each type.signature parameters) + (type.signature $Object) + (list#each type.signature supers))} + (name.internal "java.lang.Object") + (list#each ..class_name supers) + (list) + (list#each ..method_declaration method_declarations) + sequence.empty)) artifact_id (generation.learn_custom name unit.none) .let [artifact [name bytecode]] _ (generation.execute! artifact) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux index 9452e620b..c0c04d708 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) @@ -33,8 +32,9 @@ ["[1][0]" runtime (.only Operation Phase Handler Bundle Generator)] ["[1][0]" case]]] [// - ["[0]" synthesis (.only %synthesis)] ["[0]" generation] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] [/// ["[1]" phase]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/host.lux index 2b7bb2062..79e422867 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/common_lisp/host.lux @@ -1,37 +1,12 @@ (.using [library - [lux (.except) - [abstract - ["[0]" monad (.only do)]] - [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] - [data - [collection - ["[0]" dictionary] - ["[0]" list]] - [text - ["%" \\format (.only format)]]] - [target - ["_" common_lisp (.only Var Expression)]]]] - ["[0]" // - ["[1][0]" common (.only custom)] - ["//[1]" /// - ["/" bundle] - ["/[1]" // - ["[0]" extension] - [generation - [extension (.only Nullary Unary Binary Trinary - nullary unary binary trinary)] - ["[0]" reference] - ["//" common_lisp - ["[1][0]" runtime (.only Operation Phase Handler Bundle - with_vars)]]] - ["/[1]" // - ["[0]" generation] - ["//[1]" /// - ["[1][0]" phase]]]]]]) + [lux (.except)]] + [//// + ["/" bundle] + [// + [generation + [common_lisp + [runtime (.only Bundle)]]]]]) (def: .public bundle Bundle diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux index 0b40aa0d3..f83d48372 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" try]] [data ["[0]" product] [collection @@ -35,7 +34,8 @@ ["[1][0]" loop] ["[1][0]" function]]] [// - ["[0]" synthesis (.only %synthesis)] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] [/// ["[1]" phase (.open: "[1]#[0]" monad)]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux index da40355f3..0c3a868ae 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -27,6 +26,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux index 7d035fe2f..44e2b7c41 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" try] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - ["<[0]>" synthesis (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data ["[0]" product] [collection @@ -37,7 +36,8 @@ ["[1]extension" /] ["[1][0]" bundle]] [// - ["/[1][0]" synthesis (.only Synthesis %synthesis)] + ["[0]" synthesis (.only Synthesis %synthesis) + ["<[1]>" \\parser (.only Parser)]] [/// ["[1]" phase] [meta @@ -54,7 +54,7 @@ (handler extension_name phase archive input') {try.#Failure error} - (/////.except /////extension.invalid_syntax [extension_name //////synthesis.%synthesis input])))) + (/////.except /////extension.invalid_syntax [extension_name synthesis.%synthesis input])))) (def: $Boolean (type.class "java.lang.Boolean" (list))) (def: $Double (type.class "java.lang.Double" (list))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux index 30ef58a77..e08b2aba8 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" maybe (.open: "[1]#[0]" functor)] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - ["<[0]>" synthesis (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data ["[0]" product] [binary @@ -64,8 +63,9 @@ [analysis ["/" jvm]]] ["/[1]" // - ["[1][0]" synthesis (.only Synthesis Path %synthesis)] ["[1][0]" generation] + ["[0]" synthesis (.only Synthesis Path %synthesis) + ["<[1]>" \\parser (.only Parser)]] [analysis (.only Environment) ["[0]" complex]] [/// @@ -653,7 +653,7 @@ (at //////.monad in (_.getstatic (type.class class (list)) field :unboxed:)))])) (def: unitG - (_.string //////synthesis.unit)) + (_.string synthesis.unit)) (def: put::static Handler @@ -823,22 +823,22 @@ (def: .public (hidden_method_body arity body) (-> Nat Synthesis Synthesis) - (with_expansions [ (panic! (%.format (%.nat arity) " " (//////synthesis.%synthesis body)))] + (with_expansions [ (panic! (%.format (%.nat arity) " " (synthesis.%synthesis body)))] (case [arity body] (^.or [0 _] [1 _]) body - (pattern [2 {//////synthesis.#Control {//////synthesis.#Branch {//////synthesis.#Let _ 2 (//////synthesis.tuple (list _ hidden))}}}]) + (pattern [2 {synthesis.#Control {synthesis.#Branch {synthesis.#Let _ 2 (synthesis.tuple (list _ hidden))}}}]) hidden - [_ {//////synthesis.#Control {//////synthesis.#Branch {//////synthesis.#Case _ path}}}] + [_ {synthesis.#Control {synthesis.#Branch {synthesis.#Case _ path}}}] (loop (again [path (is Path path)]) (case path - {//////synthesis.#Seq _ next} + {synthesis.#Seq _ next} (again next) - (pattern {//////synthesis.#Then (//////synthesis.tuple (list _ hidden))}) + (pattern {synthesis.#Then (synthesis.tuple (list _ hidden))}) hidden _ @@ -852,43 +852,43 @@ (-> Path Path)) (function (again it) (case it - (^.or {//////synthesis.#Pop} - {//////synthesis.#Access _}) + (^.or {synthesis.#Pop} + {synthesis.#Access _}) it - {//////synthesis.#Bind it} - {//////synthesis.#Bind (-- it)} + {synthesis.#Bind it} + {synthesis.#Bind (-- it)} - {//////synthesis.#Bit_Fork when then else} - {//////synthesis.#Bit_Fork when - (again then) - (maybe#each again else)} + {synthesis.#Bit_Fork when then else} + {synthesis.#Bit_Fork when + (again then) + (maybe#each again else)} (^.with_template [] [{ [head tail]} - { [(revised //////synthesis.#then again head) - (list#each (revised //////synthesis.#then again) tail)]}]) - ([//////synthesis.#I64_Fork] - [//////synthesis.#F64_Fork] - [//////synthesis.#Text_Fork]) + { [(revised synthesis.#then again head) + (list#each (revised synthesis.#then again) tail)]}]) + ([synthesis.#I64_Fork] + [synthesis.#F64_Fork] + [synthesis.#Text_Fork]) (^.with_template [] [{ left right} { (again left) (again right)}]) - ([//////synthesis.#Seq] - [//////synthesis.#Alt]) + ([synthesis.#Seq] + [synthesis.#Alt]) - {//////synthesis.#Then it} - {//////synthesis.#Then (without_fake_parameter it)}))) + {synthesis.#Then it} + {synthesis.#Then (without_fake_parameter it)}))) (def: .public (without_fake_parameter it) (-> Synthesis Synthesis) (case it - {//////synthesis.#Simple _} + {synthesis.#Simple _} it - {//////synthesis.#Structure it} - {//////synthesis.#Structure + {synthesis.#Structure it} + {synthesis.#Structure (case it {complex.#Variant it} {complex.#Variant (revised complex.#value without_fake_parameter it)} @@ -896,8 +896,8 @@ {complex.#Tuple it} {complex.#Tuple (list#each without_fake_parameter it)})} - {//////synthesis.#Reference it} - {//////synthesis.#Reference + {synthesis.#Reference it} + {synthesis.#Reference (case it {//////reference.#Variable it} {//////reference.#Variable @@ -911,64 +911,64 @@ {//////reference.#Constant _} it)} - {//////synthesis.#Control it} - {//////synthesis.#Control + {synthesis.#Control it} + {synthesis.#Control (case it - {//////synthesis.#Branch it} - {//////synthesis.#Branch + {synthesis.#Branch it} + {synthesis.#Branch (case it - {//////synthesis.#Exec before after} - {//////synthesis.#Exec (without_fake_parameter before) - (without_fake_parameter after)} + {synthesis.#Exec before after} + {synthesis.#Exec (without_fake_parameter before) + (without_fake_parameter after)} - {//////synthesis.#Let value register body} - {//////synthesis.#Let (without_fake_parameter value) - (-- register) - (without_fake_parameter body)} + {synthesis.#Let value register body} + {synthesis.#Let (without_fake_parameter value) + (-- register) + (without_fake_parameter body)} - {//////synthesis.#If when then else} - {//////synthesis.#If (without_fake_parameter when) - (without_fake_parameter then) - (without_fake_parameter else)} + {synthesis.#If when then else} + {synthesis.#If (without_fake_parameter when) + (without_fake_parameter then) + (without_fake_parameter else)} - {//////synthesis.#Get members record} - {//////synthesis.#Get members - (without_fake_parameter record)} + {synthesis.#Get members record} + {synthesis.#Get members + (without_fake_parameter record)} - {//////synthesis.#Case value path} - {//////synthesis.#Case (without_fake_parameter value) - (without_fake_parameter#path without_fake_parameter path)})} + {synthesis.#Case value path} + {synthesis.#Case (without_fake_parameter value) + (without_fake_parameter#path without_fake_parameter path)})} - {//////synthesis.#Loop it} - {//////synthesis.#Loop + {synthesis.#Loop it} + {synthesis.#Loop (case it - {//////synthesis.#Scope [//////synthesis.#start start - //////synthesis.#inits inits - //////synthesis.#iteration iteration]} - {//////synthesis.#Scope [//////synthesis.#start (-- start) - //////synthesis.#inits (list#each without_fake_parameter inits) - //////synthesis.#iteration iteration]} + {synthesis.#Scope [synthesis.#start start + synthesis.#inits inits + synthesis.#iteration iteration]} + {synthesis.#Scope [synthesis.#start (-- start) + synthesis.#inits (list#each without_fake_parameter inits) + synthesis.#iteration iteration]} - {//////synthesis.#Again _} + {synthesis.#Again _} it)} - {//////synthesis.#Function it} - {//////synthesis.#Function + {synthesis.#Function it} + {synthesis.#Function (case it - {//////synthesis.#Abstraction [//////synthesis.#environment environment - //////synthesis.#arity arity - //////synthesis.#body body]} - {//////synthesis.#Abstraction [//////synthesis.#environment (list#each without_fake_parameter environment) - //////synthesis.#arity arity - //////synthesis.#body body]} + {synthesis.#Abstraction [synthesis.#environment environment + synthesis.#arity arity + synthesis.#body body]} + {synthesis.#Abstraction [synthesis.#environment (list#each without_fake_parameter environment) + synthesis.#arity arity + synthesis.#body body]} - {//////synthesis.#Apply [//////synthesis.#function function - //////synthesis.#arguments arguments]} - {//////synthesis.#Apply [//////synthesis.#function (without_fake_parameter function) - //////synthesis.#arguments (list#each without_fake_parameter arguments)]})})} + {synthesis.#Apply [synthesis.#function function + synthesis.#arguments arguments]} + {synthesis.#Apply [synthesis.#function (without_fake_parameter function) + synthesis.#arguments (list#each without_fake_parameter arguments)]})})} - {//////synthesis.#Extension name parameters} - {//////synthesis.#Extension name (list#each without_fake_parameter parameters)})) + {synthesis.#Extension name parameters} + {synthesis.#Extension name (list#each without_fake_parameter parameters)})) (def: overriden_method_definition (Parser [(Environment Synthesis) (/.Overriden_Method Synthesis)]) @@ -1003,24 +1003,24 @@ (-> Path Path)) (function (again path) (case path - (pattern (//////synthesis.path/then bodyS)) - (//////synthesis.path/then (normalize bodyS)) + (pattern (synthesis.path/then bodyS)) + (synthesis.path/then (normalize bodyS)) (^.with_template [] [(pattern { leftP rightP}) { (again leftP) (again rightP)}]) - ([//////synthesis.#Alt] - [//////synthesis.#Seq]) + ([synthesis.#Alt] + [synthesis.#Seq]) (^.with_template [] [{ _} path]) - ([//////synthesis.#Pop] - [//////synthesis.#Bind] - [//////synthesis.#Access]) + ([synthesis.#Pop] + [synthesis.#Bind] + [synthesis.#Access]) - {//////synthesis.#Bit_Fork when then else} - {//////synthesis.#Bit_Fork when (again then) (maybe#each again else)} + {synthesis.#Bit_Fork when then else} + {synthesis.#Bit_Fork when (again then) (maybe#each again else)} (^.with_template [] [{ [[exampleH nextH] tail]} @@ -1028,9 +1028,9 @@ (list#each (function (_ [example next]) [example (again next)]) tail)]}]) - ([//////synthesis.#I64_Fork] - [//////synthesis.#F64_Fork] - [//////synthesis.#Text_Fork])))) + ([synthesis.#I64_Fork] + [synthesis.#F64_Fork] + [synthesis.#Text_Fork])))) (type: Mapping (Dictionary Synthesis Variable)) @@ -1042,62 +1042,62 @@ (^.with_template [] [(pattern ) body]) - ([{//////synthesis.#Simple _}] - [(//////synthesis.constant _)]) + ([{synthesis.#Simple _}] + [(synthesis.constant _)]) - (pattern (//////synthesis.variant [lefts right? sub])) - (//////synthesis.variant [lefts right? (again sub)]) + (pattern (synthesis.variant [lefts right? sub])) + (synthesis.variant [lefts right? (again sub)]) - (pattern (//////synthesis.tuple members)) - (//////synthesis.tuple (list#each again members)) + (pattern (synthesis.tuple members)) + (synthesis.tuple (list#each again members)) - (pattern (//////synthesis.variable var)) + (pattern (synthesis.variable var)) (|> mapping (dictionary.value body) (maybe.else var) - //////synthesis.variable) + synthesis.variable) - (pattern (//////synthesis.branch/case [inputS pathS])) - (//////synthesis.branch/case [(again inputS) (normalize_path again pathS)]) + (pattern (synthesis.branch/case [inputS pathS])) + (synthesis.branch/case [(again inputS) (normalize_path again pathS)]) - (pattern (//////synthesis.branch/exec [this that])) - (//////synthesis.branch/exec [(again this) (again that)]) + (pattern (synthesis.branch/exec [this that])) + (synthesis.branch/exec [(again this) (again that)]) - (pattern (//////synthesis.branch/let [inputS register outputS])) - (//////synthesis.branch/let [(again inputS) register (again outputS)]) + (pattern (synthesis.branch/let [inputS register outputS])) + (synthesis.branch/let [(again inputS) register (again outputS)]) - (pattern (//////synthesis.branch/if [testS thenS elseS])) - (//////synthesis.branch/if [(again testS) (again thenS) (again elseS)]) + (pattern (synthesis.branch/if [testS thenS elseS])) + (synthesis.branch/if [(again testS) (again thenS) (again elseS)]) - (pattern (//////synthesis.branch/get [path recordS])) - (//////synthesis.branch/get [path (again recordS)]) + (pattern (synthesis.branch/get [path recordS])) + (synthesis.branch/get [path (again recordS)]) - (pattern (//////synthesis.loop/scope [offset initsS+ bodyS])) - (//////synthesis.loop/scope [offset (list#each again initsS+) (again bodyS)]) + (pattern (synthesis.loop/scope [offset initsS+ bodyS])) + (synthesis.loop/scope [offset (list#each again initsS+) (again bodyS)]) - (pattern (//////synthesis.loop/again updatesS+)) - (//////synthesis.loop/again (list#each again updatesS+)) + (pattern (synthesis.loop/again updatesS+)) + (synthesis.loop/again (list#each again updatesS+)) - (pattern (//////synthesis.function/abstraction [environment arity bodyS])) - (//////synthesis.function/abstraction [(list#each (function (_ captured) - (case captured - (pattern (//////synthesis.variable var)) - (|> mapping - (dictionary.value captured) - (maybe.else var) - //////synthesis.variable) + (pattern (synthesis.function/abstraction [environment arity bodyS])) + (synthesis.function/abstraction [(list#each (function (_ captured) + (case captured + (pattern (synthesis.variable var)) + (|> mapping + (dictionary.value captured) + (maybe.else var) + synthesis.variable) - _ - captured)) - environment) - arity - bodyS]) + _ + captured)) + environment) + arity + bodyS]) - (pattern (//////synthesis.function/apply [functionS inputsS+])) - (//////synthesis.function/apply [(again functionS) (list#each again inputsS+)]) + (pattern (synthesis.function/apply [functionS inputsS+])) + (synthesis.function/apply [(again functionS) (list#each again inputsS+)]) - {//////synthesis.#Extension [name inputsS+]} - {//////synthesis.#Extension [name (list#each again inputsS+)]}))) + {synthesis.#Extension [name inputsS+]} + {synthesis.#Extension [name (list#each again inputsS+)]}))) (def: $Object (type.class "java.lang.Object" (list))) @@ -1273,11 +1273,11 @@ local_mapping (|> environment list.enumeration (list#each (function (_ [foreign_id capture]) - [(//////synthesis.variable/foreign foreign_id) + [(synthesis.variable/foreign foreign_id) (|> global_mapping (dictionary.value capture) maybe.trusted)])) - (dictionary.of_list //////synthesis.hash))] + (dictionary.of_list synthesis.hash))] [ownerT name strict_fp? annotations vars self_name arguments returnT exceptionsT @@ -1292,7 +1292,7 @@ ... Combine them. list#conjoint ... Remove duplicates. - (set.of_list //////synthesis.hash) + (set.of_list synthesis.hash) set.list)) (def: (global_mapping total_environment) @@ -1302,7 +1302,7 @@ list.enumeration (list#each (function (_ [id capture]) [capture {//////variable.#Foreign id}])) - (dictionary.of_list //////synthesis.hash))) + (dictionary.of_list synthesis.hash))) (def: (method_definition phase archive artifact_id method) (-> Phase Archive artifact.ID (/.Overriden_Method Synthesis) (Operation (Resource Method))) @@ -1353,14 +1353,14 @@ bytecode (<| (at ! each (\\format.result class.writer)) //////.lifted (class.class version.v6_0 (all modifier#composite class.public class.final) - (name.internal anonymous_class_name) - {.#None} - (name.internal (..reflection super_class)) - (list#each (|>> ..reflection name.internal) super_interfaces) - (foreign.variables total_environment) - (list.partial (..with_anonymous_init class total_environment super_class inputsTI) - methods!) - (sequence.sequence))) + (name.internal anonymous_class_name) + {.#None} + (name.internal (..reflection super_class)) + (list#each (|>> ..reflection name.internal) super_interfaces) + (foreign.variables total_environment) + (list.partial (..with_anonymous_init class total_environment super_class inputsTI) + methods!) + (sequence.sequence))) .let [artifact [anonymous_class_name bytecode]] _ (//////generation.execute! artifact) _ (//////generation.save! artifact_id {.#None} artifact)] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux index d3d7c76d6..c454fc422 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text @@ -38,8 +37,9 @@ ["[1][0]" loop] ["[1][0]" function]]] [// - ["[0]" synthesis (.only %synthesis)] ["[0]" generation] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] [/// ["[1]" phase (.open: "[1]#[0]" monad)]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux index f2a8e2938..4ed8013ca 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -30,6 +29,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux index 898a3e8b0..384736271 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) @@ -33,7 +32,8 @@ ["[1][0]" runtime (.only Operation Phase Handler Bundle Generator)] ["[1][0]" case]]] [// - ["[0]" synthesis (.only %synthesis)] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] ["[0]" generation] [/// ["[1]" phase]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux index 353c6d055..535f01072 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -30,6 +29,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux index 933f52e74..ef6d301bc 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["<[0]>" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) @@ -40,8 +39,9 @@ ["[1][0]" loop]]] [// [analysis (.only)] - ["[0]" synthesis (.only %synthesis)] ["[0]" generation] + ["[0]" synthesis (.only %synthesis) + ["<[1]>" \\parser (.only Parser)]] [/// ["[1]" phase (.open: "[1]#[0]" monad)]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux index e62529746..7ec9d1083 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data ["[0]" text (.only) ["%" \\format]] @@ -29,6 +28,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux index 530f76072..facbc2e58 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) @@ -33,7 +32,8 @@ ["[1][0]" runtime (.only Operation Phase Handler Bundle Generator)] ["[1][0]" case]]] [// - ["[0]" synthesis (.only %synthesis)] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] ["[0]" generation] [/// ["[1]" phase]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/host.lux index d03538b0b..8facd6a1a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/r/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -30,6 +29,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux index 07d25add0..6cdacfa40 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) @@ -38,8 +37,9 @@ ["[1][0]" case] ["[1][0]" loop]]] [// - ["[0]" synthesis (.only %synthesis)] ["[0]" generation] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] [/// ["[1]" phase (.open: "[1]#[0]" monad)]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux index 7dcf5c1cb..89638f972 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -30,6 +29,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux index 0ed822b89..5d4801be1 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/common.lux @@ -4,10 +4,9 @@ [abstract ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" function] - ["[0]" try] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["[0]" try]] [data ["[0]" product] ["[0]" text @@ -33,8 +32,9 @@ ["[1][0]" runtime (.only Operation Phase Handler Bundle Generator)] ["[1][0]" case]]] [// - ["[0]" synthesis (.only %synthesis)] ["[0]" generation] + ["[0]" synthesis (.only %synthesis) + ["" \\parser (.only Parser)]] [/// ["[1]" phase]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/host.lux index f14556827..862df2607 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/scheme/host.lux @@ -4,9 +4,8 @@ [abstract ["[0]" monad (.only do)]] [control - ["[0]" function] - ["<>" parser (.only) - ["" synthesis (.only Parser)]]] + ["<>" parser] + ["[0]" function]] [data [collection ["[0]" dictionary] @@ -30,6 +29,8 @@ with_vars)]]] ["/[1]" // ["[0]" generation] + [synthesis + ["" \\parser (.only Parser)]] ["//[1]" /// ["[1][0]" phase]]]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/archive.lux index fd47dbe30..92c263466 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive.lux @@ -5,16 +5,16 @@ ["[0]" equivalence (.only Equivalence)] ["[0]" monad (.only do)]] [control + ["<>" parser] ["[0]" maybe] ["[0]" try (.only Try)] ["[0]" exception (.only exception:)] - ["[0]" function] - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["[0]" function]] [data ["[0]" product] - [binary (.only Binary) - ["[0]" \\format (.only Writer)]] + ["[0]" binary (.only Binary) + ["[0]" \\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]] ["[0]" text (.only) ["%" \\format (.only format)]] [collection diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/module/descriptor.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/module/descriptor.lux index 75934414f..b661a1587 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/module/descriptor.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/module/descriptor.lux @@ -4,13 +4,13 @@ [abstract [equivalence (.only Equivalence)]] [control - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["<>" parser]] [data ["[0]" product] ["[0]" text] - [binary - ["[0]" \\format (.only Writer)]] + ["[0]" binary + ["[0]" \\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]] [collection ["[0]" set (.only Set)]]] [macro diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/module/document.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/module/document.lux index 684277ae4..ef3073cca 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/module/document.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/module/document.lux @@ -4,14 +4,14 @@ [abstract [monad (.only do)]] [control + ["<>" parser] ["[0]" try (.only Try)] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - [binary (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data [collection ["[0]" dictionary (.only Dictionary)]] ["[0]" binary + [\\parser (.only Parser)] ["[1]" \\format (.only Writer)]]] [type (.only sharing) [primitive (.except)]]]] diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/registry.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/registry.lux index ffe3b439f..0f15e8ca7 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/registry.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/registry.lux @@ -4,15 +4,15 @@ [abstract [monad (.only do)]] [control + ["<>" parser] ["[0]" pipe] ["[0]" maybe (.open: "[1]#[0]" functor)] - ["[0]" exception (.only exception:)] - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["[0]" exception (.only exception:)]] [data ["[0]" product] ["[0]" binary - ["[1]" \\format (.only Writer)]] + ["[1]" \\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]] ["[0]" text (.only) ["%" \\format (.only format)]] [collection diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux index c4d347c21..ac6a22c49 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/signature.lux @@ -4,12 +4,12 @@ [abstract [equivalence (.only Equivalence)]] [control - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["<>" parser]] [data ["[0]" product] ["[0]" binary - ["[1]" \\format (.only Writer)]] + ["[1]" \\format (.only Writer)] + ["<[1]>" \\parser (.only Parser)]] ["[0]" text (.only) ["%" \\format (.only format)]]] [math diff --git a/stdlib/source/library/lux/tool/compiler/meta/import.lux b/stdlib/source/library/lux/tool/compiler/meta/import.lux index 977d0536c..dec6dde3b 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/import.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/import.lux @@ -4,14 +4,14 @@ [abstract ["[0]" monad (.only Monad do)]] [control + ["<>" parser] ["[0]" try (.only Try)] ["[0]" exception (.only exception:)] [concurrency - ["[0]" async (.only Async)]] - ["<>" parser (.only) - ["<[0]>" binary]]] + ["[0]" async (.only Async)]]] [data - [binary (.only Binary)] + ["[0]" binary (.only Binary) + ["<[1]>" \\parser]] ["[0]" text (.only) ["%" \\format]] [collection diff --git a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux index 90afd44d8..a192cf58a 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux @@ -5,14 +5,14 @@ [abstract ["[0]" monad (.only Monad do)]] [control + ["<>" parser] ["[0]" try (.only Try)] [concurrency - ["[0]" async (.only Async) (.open: "[1]#[0]" monad)]] - ["<>" parser (.only) - ["<[0]>" binary (.only Parser)]]] + ["[0]" async (.only Async) (.open: "[1]#[0]" monad)]]] [data - [binary (.only Binary)] ["[0]" product] + ["[0]" binary (.only Binary) + ["<[1]>" \\parser (.only Parser)]] ["[0]" text (.open: "[1]#[0]" equivalence) ["%" \\format (.only format)]] [collection diff --git a/stdlib/source/parser/lux/data/binary.lux b/stdlib/source/parser/lux/data/binary.lux new file mode 100644 index 000000000..1a49d5315 --- /dev/null +++ b/stdlib/source/parser/lux/data/binary.lux @@ -0,0 +1,308 @@ +(.using + [library + [lux (.except and or nat int rev list type symbol) + [ffi (.only)] + [type (.only sharing)] + [abstract + [hash (.only Hash)] + [monad (.only do)]] + [control + ["//" parser (.open: "[1]#[0]" monad)] + ["[0]" try (.only Try)] + ["[0]" exception (.only exception:)]] + [data + ["/" binary + ["[1]" \\unsafe (.only Binary)]] + [text + ["%" \\format (.only format)] + [encoding + ["[0]" utf8]]] + [collection + ["[0]" list] + ["[0]" sequence (.only Sequence)] + ["[0]" set (.only Set)] + [array + [\\unsafe (.only)]]]] + [macro + ["^" pattern] + ["[0]" template]] + [math + [number + ["n" nat] + ["[0]" frac]]]]]) + +(type: .public Offset + Nat) + +(type: .public Parser + (//.Parser [Offset Binary])) + +(exception: .public (binary_was_not_fully_read [binary_length Nat + bytes_read Nat]) + (exception.report + "Binary length" (%.nat binary_length) + "Bytes read" (%.nat bytes_read))) + +(with_template [ ] + [(def: + (template ( ) + [( )]))] + + [n#= "lux i64 ="] + [n#+ "lux i64 +"] + [n#- "lux i64 -"] + ) + +(def: .public (result parser input) + (All (_ a) (-> (Parser a) Binary (Try a))) + (case (parser [0 input]) + {try.#Success [[end _] output]} + (let [length (/.size input)] + (if (n#= end length) + {try.#Success output} + (exception.except ..binary_was_not_fully_read [length end]))) + + failure + (as_expected failure))) + +(def: .public end? + (Parser Bit) + (function (_ (^.let input [offset data])) + {try.#Success [input (n#= offset (/.size data))]})) + +(def: .public offset + (Parser Offset) + (function (_ (^.let input [offset data])) + {try.#Success [input offset]})) + +(def: .public remaining + (Parser Nat) + (function (_ (^.let input [offset data])) + {try.#Success [input (n#- offset (/.size data))]})) + +(type: .public Size + Nat) + +(def: .public size_8 Size 1) +(def: .public size_16 Size (n.* 2 size_8)) +(def: .public size_32 Size (n.* 2 size_16)) +(def: .public size_64 Size (n.* 2 size_32)) + +(exception: .public (range_out_of_bounds [length Nat + start Nat + end Nat]) + (exception.report + "Length" (%.nat length) + "Range start" (%.nat start) + "Range end" (%.nat end))) + +(with_template [ ] + [(def: .public + (Parser I64) + (function (_ [start binary]) + (let [end (n#+ start)] + (if (n.< end (/.size binary)) + (exception.except ..range_out_of_bounds [(/.size binary) start end]) + (|> ( start binary) + [[end binary]] + {try.#Success})))))] + + [bits_8 ..size_8 /.bits_8] + [bits_16 ..size_16 /.bits_16] + [bits_32 ..size_32 /.bits_32] + [bits_64 ..size_64 /.bits_64] + ) + +(with_template [ ] + [(def: .public (Parser ) ..bits_64)] + + [nat Nat] + [int Int] + [rev Rev] + ) + +(def: .public frac + (Parser Frac) + (//#each frac.of_bits ..bits_64)) + +(exception: .public (invalid_tag [range Nat + byte Nat]) + (exception.report + "Tag range" (%.nat range) + "Tag value" (%.nat byte))) + +(def: !variant + (template (!variant +) + [(do [! //.monad] + [flag (is (Parser Nat) + ..bits_8)] + (with_expansions [+' (template.spliced +)] + (case flag + (^.with_template [ ] + [ (`` (at ! each (|>> {(~~ (template.spliced ))}) ))]) + (+') + + _ (//.lifted (exception.except ..invalid_tag [(template.amount [+]) flag])))))])) + +(def: .public (or left right) + (All (_ l r) (-> (Parser l) (Parser r) (Parser (Or l r)))) + (!variant [[0 [.#Left] left] + [1 [.#Right] right]])) + +(def: .public (rec body) + (All (_ a) (-> (-> (Parser a) (Parser a)) (Parser a))) + (function (_ input) + (let [parser (body (rec body))] + (parser input)))) + +(def: .public any + (Parser Any) + (//#in [])) + +(exception: .public (not_a_bit [value Nat]) + (exception.report + "Expected values" "either 0 or 1" + "Actual value" (%.nat value))) + +(def: .public bit + (Parser Bit) + (do //.monad + [value (is (Parser Nat) + ..bits_8)] + (case value + 0 (in #0) + 1 (in #1) + _ (//.lifted (exception.except ..not_a_bit [value]))))) + +(def: .public (segment size) + (-> Nat (Parser Binary)) + (case size + 0 (//#in (/.empty 0)) + _ (function (_ [start binary]) + (let [end (n#+ size start)] + (if (n.< end (/.size binary)) + (exception.except ..range_out_of_bounds [(/.size binary) start end]) + (|> binary + (/.slice start size) + [[end binary]] + {try.#Success})))))) + +(with_template [ ] + [(`` (def: .public + (Parser Binary) + (do //.monad + [size (//#each (|>> .nat) )] + (..segment size))))] + + [08 binary_8 ..bits_8] + [16 binary_16 ..bits_16] + [32 binary_32 ..bits_32] + [64 binary_64 ..bits_64] + ) + +(with_template [ ] + [(`` (def: .public + (Parser Text) + (do //.monad + [utf8 ] + (//.lifted (at utf8.codec decoded utf8)))))] + + [08 utf8_8 ..binary_8] + [16 utf8_16 ..binary_16] + [32 utf8_32 ..binary_32] + [64 utf8_64 ..binary_64] + ) + +(def: .public text ..utf8_64) + +(with_template [ ] + [(def: .public ( valueP) + (All (_ v) (-> (Parser v) (Parser (Sequence v)))) + (do //.monad + [amount (is (Parser Nat) + )] + (loop (again [index 0 + output (sharing [v] + (Parser v) + valueP + + (Sequence v) + sequence.empty)]) + (if (n.< amount index) + (do //.monad + [value valueP] + (again (.++ index) + (sequence.suffix value output))) + (//#in output)))))] + + [08 sequence_8 ..bits_8] + [16 sequence_16 ..bits_16] + [32 sequence_32 ..bits_32] + [64 sequence_64 ..bits_64] + ) + +(def: .public maybe + (All (_ a) (-> (Parser a) (Parser (Maybe a)))) + (..or ..any)) + +(def: .public (list value) + (All (_ a) (-> (Parser a) (Parser (List a)))) + (..rec + (|>> (//.and value) + (..or ..any)))) + +(exception: .public set_elements_are_not_unique) + +(def: .public (set hash value) + (All (_ a) (-> (Hash a) (Parser a) (Parser (Set a)))) + (do //.monad + [raw (..list value) + .let [output (set.of_list hash raw)] + _ (//.assertion (exception.error ..set_elements_are_not_unique []) + (n#= (list.size raw) + (set.size output)))] + (in output))) + +(def: .public symbol + (Parser Symbol) + (//.and ..text ..text)) + +(def: .public type + (Parser Type) + (..rec + (function (_ type) + (let [pair (//.and type type) + indexed ..nat + quantified (//.and (..list type) type)] + (!variant [[0 [.#Primitive] (//.and ..text (..list type))] + [1 [.#Sum] pair] + [2 [.#Product] pair] + [3 [.#Function] pair] + [4 [.#Parameter] indexed] + [5 [.#Var] indexed] + [6 [.#Ex] indexed] + [7 [.#UnivQ] quantified] + [8 [.#ExQ] quantified] + [9 [.#Apply] pair] + [10 [.#Named] (//.and ..symbol type)]]))))) + +(def: .public location + (Parser Location) + (all //.and ..text ..nat ..nat)) + +(def: .public code + (Parser Code) + (..rec + (function (_ again) + (let [sequence (..list again)] + (//.and ..location + (!variant [[0 [.#Bit] ..bit] + [1 [.#Nat] ..nat] + [2 [.#Int] ..int] + [3 [.#Rev] ..rev] + [4 [.#Frac] ..frac] + [5 [.#Text] ..text] + [6 [.#Symbol] ..symbol] + [7 [.#Form] sequence] + [8 [.#Variant] sequence] + [9 [.#Tuple] sequence]])))))) diff --git a/stdlib/source/parser/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/parser/lux/tool/compiler/language/lux/synthesis.lux new file mode 100644 index 000000000..c6537531f --- /dev/null +++ b/stdlib/source/parser/lux/tool/compiler/language/lux/synthesis.lux @@ -0,0 +1,162 @@ +(.using + [library + [lux (.except function loop i64 local) + [abstract + [monad (.only do)]] + [control + ["//" parser] + ["[0]" try (.only Try)] + ["[0]" exception (.only exception:)]] + [data + ["[0]" bit] + ["[0]" text (.only) + ["%" \\format (.only format)]] + [collection + ["[0]" list]]] + [math + [number + ["n" nat] + ["[0]" i64] + ["[0]" frac]]] + [meta + ["[0]" symbol]] + [tool + [compiler + [reference (.only) + [variable (.only Register)]] + [arity (.only Arity)] + [language + [lux + [analysis (.only Environment)]]]]]]] + [\\library + ["[0]" / (.only Synthesis Abstraction)]]) + +(exception: .public (cannot_parse [input (List Synthesis)]) + (exception.report + "Input" (exception.listing /.%synthesis input))) + +(exception: .public (unconsumed_input [input (List Synthesis)]) + (exception.report + "Input" (exception.listing /.%synthesis input))) + +(exception: .public (expected_empty_input [input (List Synthesis)]) + (exception.report + "Input" (exception.listing /.%synthesis input))) + +(exception: .public (wrong_arity [expected Arity + actual Arity]) + (exception.report + "Expected" (%.nat expected) + "Actual" (%.nat actual))) + +(exception: .public empty_input) + +(type: .public Parser + (//.Parser (List Synthesis))) + +(def: .public (result parser input) + (All (_ a) (-> (Parser a) (List Synthesis) (Try a))) + (case (parser input) + {try.#Failure error} + {try.#Failure error} + + {try.#Success [{.#End} value]} + {try.#Success value} + + {try.#Success [unconsumed _]} + (exception.except ..unconsumed_input unconsumed))) + +(def: .public any + (Parser Synthesis) + (.function (_ input) + (case input + {.#End} + (exception.except ..empty_input []) + + {.#Item [head tail]} + {try.#Success [tail head]}))) + +(def: .public end + (Parser Any) + (.function (_ tokens) + (case tokens + {.#End} {try.#Success [tokens []]} + _ (exception.except ..expected_empty_input [tokens])))) + +(def: .public end? + (Parser Bit) + (.function (_ tokens) + {try.#Success [tokens (case tokens + {.#End} true + _ false)]})) + +(with_template [ ] + [(`` (def: .public + (Parser ) + (.function (_ input) + (case input + (pattern (list.partial ( x) input')) + {try.#Success [input' x]} + + _ + (exception.except ..cannot_parse input))))) + + (`` (def: .public ( expected) + (-> (Parser Any)) + (.function (_ input) + (case input + (pattern (list.partial ( actual) input')) + (if (at = expected actual) + {try.#Success [input' []]} + (exception.except ..cannot_parse input)) + + _ + (exception.except ..cannot_parse input)))))] + + [bit this_bit /.bit Bit bit.equivalence] + [i64 this_i64 /.i64 I64 i64.equivalence] + [f64 this_f64 /.f64 Frac frac.equivalence] + [text this_text /.text Text text.equivalence] + [local this_local /.variable/local Nat n.equivalence] + [foreign this_foreign /.variable/foreign Nat n.equivalence] + [constant this_constant /.constant Symbol symbol.equivalence] + ) + +(def: .public (tuple parser) + (All (_ a) (-> (Parser a) (Parser a))) + (.function (_ input) + (case input + (pattern (list.partial (/.tuple head) tail)) + (do try.monad + [output (..result parser head)] + {try.#Success [tail output]}) + + _ + (exception.except ..cannot_parse input)))) + +(def: .public (function expected parser) + (All (_ a) (-> Arity (Parser a) (Parser [(Environment Synthesis) a]))) + (.function (_ input) + (case input + (pattern (list.partial (/.function/abstraction [environment actual body]) tail)) + (if (n.= expected actual) + (do try.monad + [output (..result parser (list body))] + {try.#Success [tail [environment output]]}) + (exception.except ..wrong_arity [expected actual])) + + _ + (exception.except ..cannot_parse input)))) + +(def: .public (loop init_parsers iteration_parser) + (All (_ a b) (-> (Parser a) (Parser b) (Parser [Register a b]))) + (.function (_ input) + (case input + (pattern (list.partial (/.loop/scope [start inits iteration]) tail)) + (do try.monad + [inits (..result init_parsers inits) + iteration (..result iteration_parser (list iteration))] + {try.#Success [tail [start inits iteration]]}) + + _ + (exception.except ..cannot_parse input)))) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index 3b9029fca..cca247004 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -28,12 +28,10 @@ [\\library ["[0]" / (.only Parser)]] ["[0]" / - ["[1][0]" binary] ["[1][0]" cli] ["[1][0]" code] ["[1][0]" environment] ["[1][0]" json] - ["[1][0]" synthesis] ["[1][0]" tree] ["[1][0]" type] ["[1][0]" xml]]) @@ -384,12 +382,10 @@ ..combinators_1 ..combinators_2 - /binary.test /cli.test /code.test /environment.test /json.test - /synthesis.test /tree.test /type.test /xml.test diff --git a/stdlib/source/test/lux/control/parser/binary.lux b/stdlib/source/test/lux/control/parser/binary.lux deleted file mode 100644 index e8caa2dc9..000000000 --- a/stdlib/source/test/lux/control/parser/binary.lux +++ /dev/null @@ -1,392 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)] - ["[0]" type] - [abstract - [equivalence (.only Equivalence)] - [predicate (.only Predicate)] - [monad (.only do)]] - [control - ["[0]" pipe] - ["[0]" maybe] - ["[0]" try] - ["[0]" exception] - ["<>" parser]] - [data - ["[0]" sum] - ["[0]" bit] - ["[0]" binary (.only) - ["[0]" \\format]] - ["[0]" text (.open: "[1]#[0]" equivalence) - ["%" \\format (.only format)] - [encoding - ["[0]" utf8]]] - [collection - ["[0]" list] - ["[0]" sequence] - ["[0]" set]]] - [macro - ["^" pattern] - ["[0]" code]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["[0]" i64] - ["[0]" int] - ["[0]" rev] - ["[0]" frac]]] - [meta - ["[0]" symbol]]]] - [\\library - ["[0]" /]]) - -(def: !expect - (template (_ ) - [(case - - true - - _ - false)])) - -(def: segment_size 10) - -(def: (utf8_conversion_does_not_alter? value) - (Predicate Text) - (|> value - (at utf8.codec encoded) - (at utf8.codec decoded) - (pipe.case - {try.#Success converted} - (text#= value converted) - - {try.#Failure error} - false))) - -(def: random_text - (Random Text) - (random.only ..utf8_conversion_does_not_alter? - (random.unicode ..segment_size))) - -(def: random_symbol - (Random Symbol) - (random.and ..random_text ..random_text)) - -(def: location_equivalence - (Equivalence Location) - (implementation - (def: (= [expected_module expected_line expected_column] - [sample_module sample_line sample_column]) - (and (text#= expected_module sample_module) - (n.= expected_line sample_line) - (n.= expected_column sample_column))))) - -(def: random_location - (Random Location) - (all random.and - ..random_text - random.nat - random.nat)) - -(def: random_code - (Random Code) - (random.rec - (function (_ again) - (let [random_sequence (do [! random.monad] - [size (at ! each (n.% 2) random.nat)] - (random.list size again))] - (all random.and - ..random_location - (is (Random (Code' (Ann Location))) - (all random.or - random.bit - random.nat - random.int - random.rev - random.safe_frac - ..random_text - ..random_symbol - random_sequence - random_sequence - random_sequence - ))))))) - -(def: random_type - (Random Type) - (let [(open "[0]") random.monad] - (all random.either - (in .Nat) - (in .List) - (in .Code) - (in .Type)))) - -(def: size - Test - (<| (_.for [/.Size]) - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected (at ! each (i64.and (i64.mask )) - random.nat)] - (_.coverage [ ] - (|> (\\format.result expected) - (/.result ) - (!expect (^.multi {try.#Success actual} - (n.= (.nat expected) - (.nat actual)))))))] - - [/.size_8 /.bits_8 \\format.bits_8] - [/.size_16 /.bits_16 \\format.bits_16] - [/.size_32 /.bits_32 \\format.bits_32] - [/.size_64 /.bits_64 \\format.bits_64] - )))))) - -(def: binary - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [ ] - (|> (\\format.result expected) - (/.result ) - (!expect (^.multi {try.#Success actual} - (at binary.equivalence = expected actual))))))] - - [/.binary_8 \\format.binary_8] - [/.binary_16 \\format.binary_16] - [/.binary_32 \\format.binary_32] - [/.binary_64 \\format.binary_64] - ))))) - -(def: utf8 - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected (random.ascii ..segment_size)] - (_.coverage [ ] - (|> (\\format.result expected) - (/.result ) - (!expect (^.multi {try.#Success actual} - (at text.equivalence = expected actual))))))] - - [/.utf8_8 \\format.utf8_8] - [/.utf8_16 \\format.utf8_16] - [/.utf8_32 \\format.utf8_32] - [/.utf8_64 \\format.utf8_64] - [/.text \\format.text] - ))))) - -(def: sequence - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected (random.sequence ..segment_size random.nat)] - (_.coverage [ ] - (|> expected - (\\format.result ( \\format.nat)) - (/.result ( /.nat)) - (!expect (^.multi {try.#Success actual} - (at (sequence.equivalence n.equivalence) = expected actual))))))] - - [/.sequence_8 \\format.sequence_8] - [/.sequence_16 \\format.sequence_16] - [/.sequence_32 \\format.sequence_32] - [/.sequence_64 \\format.sequence_64] - ))))) - -(def: simple - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected ] - (_.coverage [ ] - (|> expected - (\\format.result ) - (/.result ) - (!expect (^.multi {try.#Success actual} - (at = expected actual))))))] - - [/.bit \\format.bit random.bit bit.equivalence] - [/.nat \\format.nat random.nat n.equivalence] - [/.int \\format.int random.int int.equivalence] - [/.rev \\format.rev random.rev rev.equivalence])) - (do [! random.monad] - [expected random.frac] - (_.coverage [/.frac \\format.frac] - (|> expected - (\\format.result \\format.frac) - (/.result /.frac) - (!expect (^.multi {try.#Success actual} - (or (at frac.equivalence = expected actual) - (and (frac.not_a_number? expected) - (frac.not_a_number? actual)))))))) - (do [! random.monad] - [expected (at ! each (|>> (i64.and (i64.mask /.size_8)) - (n.max 2)) - random.nat)] - (_.coverage [/.not_a_bit] - (|> expected - (\\format.result \\format.bits_8) - (/.result /.bit) - (!expect (^.multi {try.#Failure error} - (exception.match? /.not_a_bit error)))))) - ))) - -(def: complex - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected ] - (_.coverage [ ] - (|> expected - (\\format.result ) - (/.result ) - (!expect (^.multi {try.#Success actual} - (at = expected actual))))))] - - [/.location \\format.location random_location location_equivalence] - [/.code \\format.code random_code code.equivalence] - [/.type \\format.type random_type type.equivalence] - )) - (~~ (with_template [ ] - [(do [! random.monad] - [expected ] - (_.coverage [ ] - (|> expected - (\\format.result ) - (/.result ) - (!expect (^.multi {try.#Success actual} - (at = expected actual))))))] - - [/.maybe (/.maybe /.nat) \\format.maybe (\\format.maybe \\format.nat) (random.maybe random.nat) (maybe.equivalence n.equivalence)] - [/.list (/.list /.nat) \\format.list (\\format.list \\format.nat) (random.list ..segment_size random.nat) (list.equivalence n.equivalence)] - [/.set (/.set n.hash /.nat) \\format.set (\\format.set \\format.nat) (random.set n.hash ..segment_size random.nat) set.equivalence] - [/.symbol /.symbol \\format.symbol \\format.symbol ..random_symbol symbol.equivalence])) - (do [! random.monad] - [expected (at ! each (list.repeated ..segment_size) random.nat)] - (_.coverage [/.set_elements_are_not_unique] - (|> expected - (\\format.result (\\format.list \\format.nat)) - (/.result (/.set n.hash /.nat)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.set_elements_are_not_unique error)))))) - (do [! random.monad] - [expected (random.or random.bit random.nat)] - (_.coverage [/.or \\format.or] - (|> expected - (\\format.result (\\format.or \\format.bit \\format.nat)) - (/.result (is (/.Parser (Either Bit Nat)) - (/.or /.bit /.nat))) - (!expect (^.multi {try.#Success actual} - (at (sum.equivalence bit.equivalence n.equivalence) = - expected - actual)))))) - (do [! random.monad] - [tag (at ! each (|>> (i64.and (i64.mask /.size_8)) - (n.max 2)) - random.nat) - value random.bit] - (_.coverage [/.invalid_tag] - (|> [tag value] - (\\format.result (\\format.and \\format.bits_8 \\format.bit)) - (/.result (is (/.Parser (Either Bit Nat)) - (/.or /.bit /.nat))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.invalid_tag error)))))) - (do [! random.monad] - [expected (random.list ..segment_size random.nat)] - (_.coverage [/.rec \\format.rec \\format.and \\format.any] - (|> expected - (\\format.result (\\format.rec (|>> (\\format.and \\format.nat) - (\\format.or \\format.any)))) - (/.result (is (/.Parser (List Nat)) - (/.rec - (function (_ again) - (/.or /.any - (<>.and /.nat - again)))))) - (!expect (^.multi {try.#Success actual} - (at (list.equivalence n.equivalence) = - expected - actual)))))) - ))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (`` (all _.and - (_.coverage [/.result /.any - \\format.no_op \\format.instance] - (|> (\\format.instance \\format.no_op) - (/.result /.any) - (!expect {try.#Success _}))) - (do [! random.monad] - [data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [/.binary_was_not_fully_read] - (|> data - (/.result /.any) - (!expect (^.multi {try.#Failure error} - (exception.match? /.binary_was_not_fully_read error)))))) - (do [! random.monad] - [expected (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [/.segment \\format.segment \\format.result] - (|> expected - (\\format.result (\\format.segment ..segment_size)) - (/.result (/.segment ..segment_size)) - (!expect (^.multi {try.#Success actual} - (at binary.equivalence = expected actual)))))) - (do [! random.monad] - [data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [/.end?] - (|> data - (/.result (do <>.monad - [pre /.end? - _ (/.segment ..segment_size) - post /.end?] - (in (and (not pre) - post)))) - (!expect {try.#Success #1})))) - (do [! random.monad] - [to_read (at ! each (n.% (++ ..segment_size)) random.nat) - data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [/.Offset /.offset] - (|> data - (/.result (do <>.monad - [start /.offset - _ (/.segment to_read) - offset /.offset - _ (/.segment (n.- to_read ..segment_size)) - nothing_left /.offset] - (in (and (n.= 0 start) - (n.= to_read offset) - (n.= ..segment_size nothing_left))))) - (!expect {try.#Success #1})))) - (do [! random.monad] - [to_read (at ! each (n.% (++ ..segment_size)) random.nat) - data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] - (_.coverage [/.remaining] - (|> data - (/.result (do <>.monad - [_ (/.segment to_read) - remaining /.remaining - _ (/.segment (n.- to_read ..segment_size)) - nothing_left /.remaining] - (in (and (n.= ..segment_size - (n.+ to_read remaining)) - (n.= 0 nothing_left))))) - (!expect {try.#Success #1})))) - ..size - ..binary - ..utf8 - ..sequence - ..simple - ..complex - )))) diff --git a/stdlib/source/test/lux/control/parser/synthesis.lux b/stdlib/source/test/lux/control/parser/synthesis.lux deleted file mode 100644 index 9f765d0a5..000000000 --- a/stdlib/source/test/lux/control/parser/synthesis.lux +++ /dev/null @@ -1,205 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - ["[0]" monad (.only do)]] - [control - ["<>" parser] - ["[0]" try] - ["[0]" exception]] - [data - ["[0]" bit] - ["[0]" text] - [collection - ["[0]" list (.open: "[1]#[0]" functor)]]] - [macro - ["^" pattern]] - [math - ["[0]" random (.only Random)] - [number - ["n" nat] - ["[0]" i64] - ["[0]" frac]]] - [meta - ["[0]" symbol]] - [tool - [compiler - [reference (.only) - ["[0]" variable (.only Variable)]] - [language - [lux - [analysis (.only Environment)] - ["[0]" synthesis (.only Synthesis)]]]]]]] - [\\library - ["[0]" /]]) - -(def: !expect - (template (_ ) - [(case - - true - - _ - false)])) - -(def: random_constant - (Random Symbol) - (random.and (random.unicode 1) - (random.unicode 1))) - -(def: random_variable - (Random Variable) - (random.or random.nat - random.nat)) - -(def: random_environment - (Random (Environment Synthesis)) - (do [! random.monad] - [size (at ! each (n.% 5) random.nat)] - (|> ..random_variable - (at ! each (|>> synthesis.variable)) - (random.list size)))) - -(def: simple - Test - (`` (all _.and - (~~ (with_template [ ] - [(do [! random.monad] - [expected - dummy (|> (random.only (|>> (at = expected) not)))] - (all _.and - (_.coverage [] - (|> (/.result (list ( expected))) - (!expect (^.multi {try.#Success actual} - (at = expected actual))))) - (_.coverage [] - (and (|> (/.result ( expected) (list ( expected))) - (!expect {try.#Success _})) - (|> (/.result ( expected) (list ( dummy))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_parse error)))))) - ))] - - [/.bit /.this_bit random.bit synthesis.bit bit.equivalence] - [/.i64 /.this_i64 random.i64 synthesis.i64 i64.equivalence] - [/.f64 /.this_f64 random.safe_frac synthesis.f64 frac.equivalence] - [/.text /.this_text (random.unicode 1) synthesis.text text.equivalence] - [/.local /.this_local random.nat synthesis.variable/local n.equivalence] - [/.foreign /.this_foreign random.nat synthesis.variable/foreign n.equivalence] - [/.constant /.this_constant ..random_constant synthesis.constant symbol.equivalence] - )) - ))) - -(def: complex - Test - (all _.and - (do [! random.monad] - [expected_bit random.bit - expected_i64 random.i64 - expected_f64 random.safe_frac - expected_text (random.unicode 1)] - (_.coverage [/.tuple] - (and (|> (/.result (/.tuple (all <>.and /.bit /.i64 /.f64 /.text)) - (list (synthesis.tuple (list (synthesis.bit expected_bit) - (synthesis.i64 expected_i64) - (synthesis.f64 expected_f64) - (synthesis.text expected_text))))) - (!expect (^.multi {try.#Success [actual_bit actual_i64 actual_f64 actual_text]} - (and (at bit.equivalence = expected_bit actual_bit) - (at i64.equivalence = expected_i64 actual_i64) - (at frac.equivalence = expected_f64 actual_f64) - (at text.equivalence = expected_text actual_text))))) - (|> (/.result (/.tuple (all <>.and /.bit /.i64 /.f64 /.text)) - (list (synthesis.text expected_text))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_parse error))))))) - (do [! random.monad] - [arity random.nat - expected_environment ..random_environment - expected_body (random.unicode 1)] - (_.coverage [/.function] - (and (|> (/.result (/.function arity /.text) - (list (synthesis.function/abstraction [expected_environment arity (synthesis.text expected_body)]))) - (!expect (^.multi {try.#Success [actual_environment actual_body]} - (and (at (list.equivalence synthesis.equivalence) = - expected_environment - actual_environment) - (at text.equivalence = expected_body actual_body))))) - (|> (/.result (/.function arity /.text) - (list (synthesis.text expected_body))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_parse error))))))) - (do [! random.monad] - [arity random.nat - expected_environment ..random_environment - expected_body (random.unicode 1)] - (_.coverage [/.wrong_arity] - (|> (/.result (/.function (++ arity) /.text) - (list (synthesis.function/abstraction [expected_environment arity (synthesis.text expected_body)]))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.wrong_arity error)))))) - (do [! random.monad] - [arity (at ! each (|>> (n.% 10) ++) random.nat) - expected_offset random.nat - expected_inits (random.list arity random.bit) - expected_body (random.unicode 1)] - (_.coverage [/.loop] - (and (|> (/.result (/.loop (<>.many /.bit) /.text) - (list (synthesis.loop/scope [expected_offset - (list#each (|>> synthesis.bit) expected_inits) - (synthesis.text expected_body)]))) - (!expect (^.multi {try.#Success [actual_offset actual_inits actual_body]} - (and (at n.equivalence = expected_offset actual_offset) - (at (list.equivalence bit.equivalence) = - expected_inits - actual_inits) - (at text.equivalence = expected_body actual_body))))) - (|> (/.result (/.loop (<>.many /.bit) /.text) - (list (synthesis.text expected_body))) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_parse error))))))) - )) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (all _.and - (do [! random.monad] - [expected (at ! each (|>> synthesis.i64) random.i64)] - (_.coverage [/.result /.any] - (|> (/.result /.any (list expected)) - (!expect (^.multi {try.#Success actual} - (at synthesis.equivalence = expected actual)))))) - (_.coverage [/.empty_input] - (|> (/.result /.any (list)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.empty_input error))))) - (do [! random.monad] - [expected (at ! each (|>> synthesis.i64) random.i64)] - (_.coverage [/.unconsumed_input] - (|> (/.result /.any (list expected expected)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.unconsumed_input error)))))) - (do [! random.monad] - [dummy (at ! each (|>> synthesis.i64) random.i64)] - (_.coverage [/.end /.expected_empty_input] - (and (|> (/.result /.end (list)) - (!expect {try.#Success _})) - (|> (/.result /.end (list dummy)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.expected_empty_input error))))))) - (do [! random.monad] - [dummy (at ! each (|>> synthesis.i64) random.i64)] - (_.coverage [/.end?] - (and (|> (/.result /.end? (list)) - (!expect {try.#Success #1})) - (|> (/.result (<>.before /.any /.end?) (list dummy)) - (!expect {try.#Success #0}))))) - (_.for [/.cannot_parse] - (all _.and - ..simple - ..complex - )) - ))) diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux index 50a3f786f..691b6ff55 100644 --- a/stdlib/source/test/lux/data/binary.lux +++ b/stdlib/source/test/lux/data/binary.lux @@ -3,30 +3,401 @@ [lux (.except) [ffi (.only)] ["_" test (.only Test)] + ["[0]" type] [abstract [equivalence (.only Equivalence)] + [predicate (.only Predicate)] ["[0]" monad (.only do)] ["[0]" enum] [\\specification ["$[0]" equivalence] ["$[0]" monoid]]] [control + ["<>" parser] + ["[0]" pipe] + ["[0]" maybe] ["[0]" try (.only Try)] ["[0]" exception (.only Exception)]] [data + ["[0]" sum] + ["[0]" bit] + ["[0]" text (.open: "[1]#[0]" equivalence) + ["%" \\format (.only format)] + [encoding + ["[0]" utf8]]] [collection ["[0]" list (.open: "[1]#[0]" functor)] + ["[0]" sequence] + ["[0]" set] [array [\\unsafe (.only)]]]] + [macro + ["^" pattern] + ["[0]" code]] [math ["[0]" random (.only Random)] [number ["n" nat] - ["[0]" i64]]]]] + ["[0]" i64] + ["[0]" int] + ["[0]" rev] + ["[0]" frac]]] + [meta + ["[0]" symbol]]]] [\\library ["[0]" / (.only) (.open: "[1]#[0]" equivalence) ["!" \\unsafe] - ["[0]" \\format]]]) + ["[0]" \\format] + ["[0]" \\parser]]]) + +(def: !expect + (template (_ ) + [(case + + true + + _ + false)])) + +(def: segment_size 10) + +(def: (utf8_conversion_does_not_alter? value) + (Predicate Text) + (|> value + (at utf8.codec encoded) + (at utf8.codec decoded) + (pipe.case + {try.#Success converted} + (text#= value converted) + + {try.#Failure error} + false))) + +(def: random_text + (Random Text) + (random.only ..utf8_conversion_does_not_alter? + (random.unicode ..segment_size))) + +(def: random_symbol + (Random Symbol) + (random.and ..random_text ..random_text)) + +(def: location_equivalence + (Equivalence Location) + (implementation + (def: (= [expected_module expected_line expected_column] + [sample_module sample_line sample_column]) + (and (text#= expected_module sample_module) + (n.= expected_line sample_line) + (n.= expected_column sample_column))))) + +(def: random_location + (Random Location) + (all random.and + ..random_text + random.nat + random.nat)) + +(def: random_code + (Random Code) + (random.rec + (function (_ again) + (let [random_sequence (do [! random.monad] + [size (at ! each (n.% 2) random.nat)] + (random.list size again))] + (all random.and + ..random_location + (is (Random (Code' (Ann Location))) + (all random.or + random.bit + random.nat + random.int + random.rev + random.safe_frac + ..random_text + ..random_symbol + random_sequence + random_sequence + random_sequence + ))))))) + +(def: random_type + (Random Type) + (let [(open "[0]") random.monad] + (all random.either + (in .Nat) + (in .List) + (in .Code) + (in .Type)))) + +(def: size + Test + (<| (_.for [\\parser.Size]) + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected (at ! each (i64.and (i64.mask )) + random.nat)] + (_.coverage [ ] + (|> (\\format.result expected) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (n.= (.nat expected) + (.nat actual)))))))] + + [\\parser.size_8 \\parser.bits_8 \\format.bits_8] + [\\parser.size_16 \\parser.bits_16 \\format.bits_16] + [\\parser.size_32 \\parser.bits_32 \\format.bits_32] + [\\parser.size_64 \\parser.bits_64 \\format.bits_64] + )))))) + +(def: binary + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [ ] + (|> (\\format.result expected) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (at /.equivalence = expected actual))))))] + + [\\parser.binary_8 \\format.binary_8] + [\\parser.binary_16 \\format.binary_16] + [\\parser.binary_32 \\format.binary_32] + [\\parser.binary_64 \\format.binary_64] + ))))) + +(def: utf8 + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected (random.ascii ..segment_size)] + (_.coverage [ ] + (|> (\\format.result expected) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (at text.equivalence = expected actual))))))] + + [\\parser.utf8_8 \\format.utf8_8] + [\\parser.utf8_16 \\format.utf8_16] + [\\parser.utf8_32 \\format.utf8_32] + [\\parser.utf8_64 \\format.utf8_64] + [\\parser.text \\format.text] + ))))) + +(def: sequence + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected (random.sequence ..segment_size random.nat)] + (_.coverage [ ] + (|> expected + (\\format.result ( \\format.nat)) + (\\parser.result ( \\parser.nat)) + (!expect (^.multi {try.#Success actual} + (at (sequence.equivalence n.equivalence) = expected actual))))))] + + [\\parser.sequence_8 \\format.sequence_8] + [\\parser.sequence_16 \\format.sequence_16] + [\\parser.sequence_32 \\format.sequence_32] + [\\parser.sequence_64 \\format.sequence_64] + ))))) + +(def: simple + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected ] + (_.coverage [ ] + (|> expected + (\\format.result ) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (at = expected actual))))))] + + [\\parser.bit \\format.bit random.bit bit.equivalence] + [\\parser.nat \\format.nat random.nat n.equivalence] + [\\parser.int \\format.int random.int int.equivalence] + [\\parser.rev \\format.rev random.rev rev.equivalence])) + (do [! random.monad] + [expected random.frac] + (_.coverage [\\parser.frac \\format.frac] + (|> expected + (\\format.result \\format.frac) + (\\parser.result \\parser.frac) + (!expect (^.multi {try.#Success actual} + (or (at frac.equivalence = expected actual) + (and (frac.not_a_number? expected) + (frac.not_a_number? actual)))))))) + (do [! random.monad] + [expected (at ! each (|>> (i64.and (i64.mask \\parser.size_8)) + (n.max 2)) + random.nat)] + (_.coverage [\\parser.not_a_bit] + (|> expected + (\\format.result \\format.bits_8) + (\\parser.result \\parser.bit) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.not_a_bit error)))))) + ))) + +(def: complex + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected ] + (_.coverage [ ] + (|> expected + (\\format.result ) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (at = expected actual))))))] + + [\\parser.location \\format.location random_location location_equivalence] + [\\parser.code \\format.code random_code code.equivalence] + [\\parser.type \\format.type random_type type.equivalence] + )) + (~~ (with_template [ ] + [(do [! random.monad] + [expected ] + (_.coverage [ ] + (|> expected + (\\format.result ) + (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (at = expected actual))))))] + + [\\parser.maybe (\\parser.maybe \\parser.nat) \\format.maybe (\\format.maybe \\format.nat) (random.maybe random.nat) (maybe.equivalence n.equivalence)] + [\\parser.list (\\parser.list \\parser.nat) \\format.list (\\format.list \\format.nat) (random.list ..segment_size random.nat) (list.equivalence n.equivalence)] + [\\parser.set (\\parser.set n.hash \\parser.nat) \\format.set (\\format.set \\format.nat) (random.set n.hash ..segment_size random.nat) set.equivalence] + [\\parser.symbol \\parser.symbol \\format.symbol \\format.symbol ..random_symbol symbol.equivalence])) + (do [! random.monad] + [expected (at ! each (list.repeated ..segment_size) random.nat)] + (_.coverage [\\parser.set_elements_are_not_unique] + (|> expected + (\\format.result (\\format.list \\format.nat)) + (\\parser.result (\\parser.set n.hash \\parser.nat)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.set_elements_are_not_unique error)))))) + (do [! random.monad] + [expected (random.or random.bit random.nat)] + (_.coverage [\\parser.or \\format.or] + (|> expected + (\\format.result (\\format.or \\format.bit \\format.nat)) + (\\parser.result (is (\\parser.Parser (Either Bit Nat)) + (\\parser.or \\parser.bit \\parser.nat))) + (!expect (^.multi {try.#Success actual} + (at (sum.equivalence bit.equivalence n.equivalence) = + expected + actual)))))) + (do [! random.monad] + [tag (at ! each (|>> (i64.and (i64.mask \\parser.size_8)) + (n.max 2)) + random.nat) + value random.bit] + (_.coverage [\\parser.invalid_tag] + (|> [tag value] + (\\format.result (\\format.and \\format.bits_8 \\format.bit)) + (\\parser.result (is (\\parser.Parser (Either Bit Nat)) + (\\parser.or \\parser.bit \\parser.nat))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.invalid_tag error)))))) + (do [! random.monad] + [expected (random.list ..segment_size random.nat)] + (_.coverage [\\parser.rec \\format.rec \\format.and \\format.any] + (|> expected + (\\format.result (\\format.rec (|>> (\\format.and \\format.nat) + (\\format.or \\format.any)))) + (\\parser.result (is (\\parser.Parser (List Nat)) + (\\parser.rec + (function (_ again) + (\\parser.or \\parser.any + (<>.and \\parser.nat + again)))))) + (!expect (^.multi {try.#Success actual} + (at (list.equivalence n.equivalence) = + expected + actual)))))) + ))) + +(def: \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (`` (all _.and + (_.coverage [\\parser.result \\parser.any + \\format.no_op \\format.instance] + (|> (\\format.instance \\format.no_op) + (\\parser.result \\parser.any) + (!expect {try.#Success _}))) + (do [! random.monad] + [data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [\\parser.binary_was_not_fully_read] + (|> data + (\\parser.result \\parser.any) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.binary_was_not_fully_read error)))))) + (do [! random.monad] + [expected (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [\\parser.segment \\format.segment \\format.result] + (|> expected + (\\format.result (\\format.segment ..segment_size)) + (\\parser.result (\\parser.segment ..segment_size)) + (!expect (^.multi {try.#Success actual} + (at /.equivalence = expected actual)))))) + (do [! random.monad] + [data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [\\parser.end?] + (|> data + (\\parser.result (do <>.monad + [pre \\parser.end? + _ (\\parser.segment ..segment_size) + post \\parser.end?] + (in (and (not pre) + post)))) + (!expect {try.#Success #1})))) + (do [! random.monad] + [to_read (at ! each (n.% (++ ..segment_size)) random.nat) + data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [\\parser.Offset \\parser.offset] + (|> data + (\\parser.result (do <>.monad + [start \\parser.offset + _ (\\parser.segment to_read) + offset \\parser.offset + _ (\\parser.segment (n.- to_read ..segment_size)) + nothing_left \\parser.offset] + (in (and (n.= 0 start) + (n.= to_read offset) + (n.= ..segment_size nothing_left))))) + (!expect {try.#Success #1})))) + (do [! random.monad] + [to_read (at ! each (n.% (++ ..segment_size)) random.nat) + data (at ! each (at utf8.codec encoded) (random.ascii ..segment_size))] + (_.coverage [\\parser.remaining] + (|> data + (\\parser.result (do <>.monad + [_ (\\parser.segment to_read) + remaining \\parser.remaining + _ (\\parser.segment (n.- to_read ..segment_size)) + nothing_left \\parser.remaining] + (in (and (n.= ..segment_size + (n.+ to_read remaining)) + (n.= 0 nothing_left))))) + (!expect {try.#Success #1})))) + ..size + ..binary + ..utf8 + ..sequence + ..simple + ..complex + )))) (def: equivalence (Equivalence \\format.Specification) @@ -263,4 +634,5 @@ ..test|unsafe ..\\format + ..\\parser )))) diff --git a/stdlib/source/test/lux/data/format/tar.lux b/stdlib/source/test/lux/data/format/tar.lux index ba81d4153..16bf8fb62 100644 --- a/stdlib/source/test/lux/data/format/tar.lux +++ b/stdlib/source/test/lux/data/format/tar.lux @@ -5,14 +5,14 @@ [abstract [monad (.only do)]] [control + ["<>" parser (.only)] ["[0]" maybe] ["[0]" try] - ["[0]" exception] - ["<>" parser (.only) - ["" binary]]] + ["[0]" exception]] [data ["[0]" product] ["[0]" binary (.open: "[1]#[0]" equivalence monoid) + ["" \\parser] ["[0]" \\format]] ["[0]" text (.open: "[1]#[0]" equivalence) ["%" \\format (.only format)] diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index 70984d45e..30accf1b0 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -21,8 +21,7 @@ [control ["[0]" try (.open: "[1]#[0]" functor)] ["<>" parser (.only) - ["<[0]>" code] - ["<[0]>" synthesis]]] + ["<[0]>" code]]] [data ["[0]" product] ["[0]" binary (.only) @@ -46,12 +45,13 @@ ["[0]" unit]]] [language [lux - ["[0]" synthesis] ["[0]" generation] ["[0]" directive] ["[0]" analysis (.only) ["[0]" type] ["<[1]>" \\parser]] + ["[0]" synthesis (.only) + ["<[1]>" \\parser]] [phase [generation (~~ (.for "JVM" (~~ (.these ["[0]" jvm @@ -159,13 +159,13 @@ (try.else (binary.empty 0)) (try#each (binaryF.result class.writer)) (class.class version.v6_0 class.public - (name.internal $class) - {.#None} - (name.internal "java.lang.Object") - (list) - (list) - (list) - sequence.empty))) + (name.internal $class) + {.#None} + (name.internal "java.lang.Object") + (list) + (list) + (list) + sequence.empty))) @.js (js.comment commentary (js.statement (js.string commentary))) @.python (python.comment commentary diff --git a/stdlib/source/test/lux/tool.lux b/stdlib/source/test/lux/tool.lux index 542b33921..217647f2e 100644 --- a/stdlib/source/test/lux/tool.lux +++ b/stdlib/source/test/lux/tool.lux @@ -12,9 +12,7 @@ [lux ... ["[1][0]" syntax] ["[1][0]" analysis] - ["[1][0]" synthesis - ["[1]/[0]" simple] - ["[1]/[0]" access]] + ["[1][0]" synthesis] ["[1][0]" phase ["[1]/[0]" extension] ["[1]/[0]" analysis] @@ -37,8 +35,7 @@ /reference.test /phase.test /analysis.test - /synthesis/simple.test - /synthesis/access.test + /synthesis.test /meta/archive.test /meta/cli.test /meta/export.test diff --git a/stdlib/source/test/lux/tool/compiler/language/lux/synthesis.lux b/stdlib/source/test/lux/tool/compiler/language/lux/synthesis.lux new file mode 100644 index 000000000..38d846740 --- /dev/null +++ b/stdlib/source/test/lux/tool/compiler/language/lux/synthesis.lux @@ -0,0 +1,216 @@ +(.using + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + ["[0]" monad (.only do)]] + [control + ["<>" parser] + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" bit] + ["[0]" text] + [collection + ["[0]" list (.open: "[1]#[0]" functor)]]] + [macro + ["^" pattern]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat] + ["[0]" i64] + ["[0]" frac]]] + [meta + ["[0]" symbol]] + [tool + [compiler + [reference (.only) + ["[0]" variable (.only Variable)]] + [language + [lux + [analysis (.only Environment)] + ["[0]" synthesis (.only Synthesis)]]]]]]] + ["[0]" \\parser] + ["[0]" / + ["[1][0]" simple] + ["[1][0]" access]]) + +(def: !expect + (template (_ ) + [(case + + true + + _ + false)])) + +(def: random_constant + (Random Symbol) + (random.and (random.unicode 1) + (random.unicode 1))) + +(def: random_variable + (Random Variable) + (random.or random.nat + random.nat)) + +(def: random_environment + (Random (Environment Synthesis)) + (do [! random.monad] + [size (at ! each (n.% 5) random.nat)] + (|> ..random_variable + (at ! each (|>> synthesis.variable)) + (random.list size)))) + +(def: simple + Test + (`` (all _.and + (~~ (with_template [ ] + [(do [! random.monad] + [expected + dummy (|> (random.only (|>> (at = expected) not)))] + (all _.and + (_.coverage [] + (|> (\\parser.result (list ( expected))) + (!expect (^.multi {try.#Success actual} + (at = expected actual))))) + (_.coverage [] + (and (|> (\\parser.result ( expected) (list ( expected))) + (!expect {try.#Success _})) + (|> (\\parser.result ( expected) (list ( dummy))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_parse error)))))) + ))] + + [\\parser.bit \\parser.this_bit random.bit synthesis.bit bit.equivalence] + [\\parser.i64 \\parser.this_i64 random.i64 synthesis.i64 i64.equivalence] + [\\parser.f64 \\parser.this_f64 random.safe_frac synthesis.f64 frac.equivalence] + [\\parser.text \\parser.this_text (random.unicode 1) synthesis.text text.equivalence] + [\\parser.local \\parser.this_local random.nat synthesis.variable/local n.equivalence] + [\\parser.foreign \\parser.this_foreign random.nat synthesis.variable/foreign n.equivalence] + [\\parser.constant \\parser.this_constant ..random_constant synthesis.constant symbol.equivalence] + )) + ))) + +(def: complex + Test + (all _.and + (do [! random.monad] + [expected_bit random.bit + expected_i64 random.i64 + expected_f64 random.safe_frac + expected_text (random.unicode 1)] + (_.coverage [\\parser.tuple] + (and (|> (\\parser.result (\\parser.tuple (all <>.and \\parser.bit \\parser.i64 \\parser.f64 \\parser.text)) + (list (synthesis.tuple (list (synthesis.bit expected_bit) + (synthesis.i64 expected_i64) + (synthesis.f64 expected_f64) + (synthesis.text expected_text))))) + (!expect (^.multi {try.#Success [actual_bit actual_i64 actual_f64 actual_text]} + (and (at bit.equivalence = expected_bit actual_bit) + (at i64.equivalence = expected_i64 actual_i64) + (at frac.equivalence = expected_f64 actual_f64) + (at text.equivalence = expected_text actual_text))))) + (|> (\\parser.result (\\parser.tuple (all <>.and \\parser.bit \\parser.i64 \\parser.f64 \\parser.text)) + (list (synthesis.text expected_text))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_parse error))))))) + (do [! random.monad] + [arity random.nat + expected_environment ..random_environment + expected_body (random.unicode 1)] + (_.coverage [\\parser.function] + (and (|> (\\parser.result (\\parser.function arity \\parser.text) + (list (synthesis.function/abstraction [expected_environment arity (synthesis.text expected_body)]))) + (!expect (^.multi {try.#Success [actual_environment actual_body]} + (and (at (list.equivalence synthesis.equivalence) = + expected_environment + actual_environment) + (at text.equivalence = expected_body actual_body))))) + (|> (\\parser.result (\\parser.function arity \\parser.text) + (list (synthesis.text expected_body))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_parse error))))))) + (do [! random.monad] + [arity random.nat + expected_environment ..random_environment + expected_body (random.unicode 1)] + (_.coverage [\\parser.wrong_arity] + (|> (\\parser.result (\\parser.function (++ arity) \\parser.text) + (list (synthesis.function/abstraction [expected_environment arity (synthesis.text expected_body)]))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.wrong_arity error)))))) + (do [! random.monad] + [arity (at ! each (|>> (n.% 10) ++) random.nat) + expected_offset random.nat + expected_inits (random.list arity random.bit) + expected_body (random.unicode 1)] + (_.coverage [\\parser.loop] + (and (|> (\\parser.result (\\parser.loop (<>.many \\parser.bit) \\parser.text) + (list (synthesis.loop/scope [expected_offset + (list#each (|>> synthesis.bit) expected_inits) + (synthesis.text expected_body)]))) + (!expect (^.multi {try.#Success [actual_offset actual_inits actual_body]} + (and (at n.equivalence = expected_offset actual_offset) + (at (list.equivalence bit.equivalence) = + expected_inits + actual_inits) + (at text.equivalence = expected_body actual_body))))) + (|> (\\parser.result (\\parser.loop (<>.many \\parser.bit) \\parser.text) + (list (synthesis.text expected_body))) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_parse error))))))) + )) + +(def: \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (all _.and + (do [! random.monad] + [expected (at ! each (|>> synthesis.i64) random.i64)] + (_.coverage [\\parser.result \\parser.any] + (|> (\\parser.result \\parser.any (list expected)) + (!expect (^.multi {try.#Success actual} + (at synthesis.equivalence = expected actual)))))) + (_.coverage [\\parser.empty_input] + (|> (\\parser.result \\parser.any (list)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.empty_input error))))) + (do [! random.monad] + [expected (at ! each (|>> synthesis.i64) random.i64)] + (_.coverage [\\parser.unconsumed_input] + (|> (\\parser.result \\parser.any (list expected expected)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.unconsumed_input error)))))) + (do [! random.monad] + [dummy (at ! each (|>> synthesis.i64) random.i64)] + (_.coverage [\\parser.end \\parser.expected_empty_input] + (and (|> (\\parser.result \\parser.end (list)) + (!expect {try.#Success _})) + (|> (\\parser.result \\parser.end (list dummy)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.expected_empty_input error))))))) + (do [! random.monad] + [dummy (at ! each (|>> synthesis.i64) random.i64)] + (_.coverage [\\parser.end?] + (and (|> (\\parser.result \\parser.end? (list)) + (!expect {try.#Success #1})) + (|> (\\parser.result (<>.before \\parser.any \\parser.end?) (list dummy)) + (!expect {try.#Success #0}))))) + (_.for [\\parser.cannot_parse] + (all _.and + ..simple + ..complex + )) + ))) + +(def: .public test + Test + (all _.and + ..\\parser + + /simple.test + /access.test + )) diff --git a/stdlib/source/test/lux/tool/compiler/meta/archive/module/descriptor.lux b/stdlib/source/test/lux/tool/compiler/meta/archive/module/descriptor.lux index cc9093286..6d2acbc82 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/archive/module/descriptor.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/archive/module/descriptor.lux @@ -7,13 +7,12 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" binary]]] + ["[0]" try (.open: "[1]#[0]" functor)]] [data ["[0]" text (.open: "[1]#[0]" equivalence)] ["[0]" binary - ["[1]" \\format]]] + ["[1]" \\format] + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random) (.open: "[1]#[0]" monad)]]]] [\\library diff --git a/stdlib/source/test/lux/tool/compiler/meta/archive/module/document.lux b/stdlib/source/test/lux/tool/compiler/meta/archive/module/document.lux index e36561063..4f25ec351 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/archive/module/document.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/archive/module/document.lux @@ -7,12 +7,11 @@ [control ["[0]" pipe] ["[0]" try (.open: "[1]#[0]" functor)] - ["[0]" exception] - [parser - ["<[0]>" binary]]] + ["[0]" exception]] [data ["[0]" binary - ["[1]F" \\format]]] + ["[1]F" \\format] + ["<[1]>" \\parser]]] [math ["[0]" random] [number diff --git a/stdlib/source/test/lux/tool/compiler/meta/archive/registry.lux b/stdlib/source/test/lux/tool/compiler/meta/archive/registry.lux index a3dfe0677..3cd46c9c8 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/archive/registry.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/archive/registry.lux @@ -6,14 +6,13 @@ [monad (.only do)]] [control ["[0]" maybe (.open: "[1]#[0]" functor)] - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" binary]]] + ["[0]" try (.open: "[1]#[0]" functor)]] [data ["[0]" product] ["[0]" text] ["[0]" binary - ["[1]" \\format]] + ["[1]" \\format] + ["<[1]>" \\parser]] [collection ["[0]" sequence (.only Sequence)] ["[0]" set (.only Set)] diff --git a/stdlib/source/test/lux/tool/compiler/meta/archive/signature.lux b/stdlib/source/test/lux/tool/compiler/meta/archive/signature.lux index 15db5b167..2586666ee 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/archive/signature.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/archive/signature.lux @@ -7,14 +7,13 @@ [\\specification ["$[0]" equivalence]]] [control - ["[0]" try (.open: "[1]#[0]" functor)] - [parser - ["<[0]>" binary]]] + ["[0]" try (.open: "[1]#[0]" functor)]] [data ["[0]" bit (.open: "[1]#[0]" equivalence)] ["[0]" text (.open: "[1]#[0]" equivalence)] ["[0]" binary - ["[1]F" \\format]]] + ["[1]F" \\format] + ["<[1]>" \\parser]]] [math ["[0]" random (.only Random)]]]] [\\library diff --git a/stdlib/source/test/lux/tool/compiler/meta/export.lux b/stdlib/source/test/lux/tool/compiler/meta/export.lux index 1fb6d3a2d..134f62058 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/export.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/export.lux @@ -8,15 +8,14 @@ ["[0]" pipe] ["[0]" try (.open: "[1]#[0]" functor)] [concurrency - ["[0]" async]] - [parser - ["<[0]>" binary]]] + ["[0]" async]]] [data ["[0]" product] - ["[0]" binary (.only Binary) (.open: "[1]#[0]" equivalence)] ["[0]" bit (.open: "[1]#[0]" equivalence)] [format ["[0]" tar]] + ["[0]" binary (.only Binary) (.open: "[1]#[0]" equivalence) + ["<[1]>" \\parser]] ["[0]" text (.open: "[1]#[0]" equivalence) ["%" \\format (.only format)] [encoding diff --git a/stdlib/source/test/lux/tool/compiler/meta/import.lux b/stdlib/source/test/lux/tool/compiler/meta/import.lux index c37686e03..c5d2ce2b1 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/import.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/import.lux @@ -9,14 +9,13 @@ ["[0]" try (.open: "[1]#[0]" functor)] ["[0]" exception] [concurrency - ["[0]" async]] - [parser - ["<[0]>" binary]]] + ["[0]" async]]] [data ["[0]" product] ["[0]" bit (.open: "[1]#[0]" equivalence)] ["[0]" binary (.only Binary) (.open: "[1]#[0]" equivalence) - ["[0]" \\format]] + ["[0]" \\format] + ["<[1]>" \\parser]] ["[0]" format ["[0]" tar (.only Tar)]] ["[0]" text (.open: "[1]#[0]" equivalence) -- cgit v1.2.3