aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/data/format/json.lux39
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux24
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux15
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux14
-rw-r--r--stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux2
5 files changed, 61 insertions, 33 deletions
diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux
index aa6ef2279..f29042a83 100644
--- a/stdlib/source/library/lux/data/format/json.lux
+++ b/stdlib/source/library/lux/data/format/json.lux
@@ -67,8 +67,19 @@
(-> (List [String JSON]) JSON)
(|>> (dictionary.of_list text.hash) #..Object))
+(type: JSON'
+ (Rec JSON'
+ (Variant
+ {#Null' Null}
+ {#Boolean' Boolean}
+ {#Number' Number}
+ {#String' String}
+ {#Array' (Row JSON')}
+ {#Object' (Dictionary String JSON')}
+ {#Code' Code})))
+
(def: jsonP
- (<code>.Parser JSON)
+ (<code>.Parser JSON')
(<>.rec
(function (_ jsonP)
($_ <>.or
@@ -80,31 +91,35 @@
(<code>.tuple (<>.some jsonP)))
(<>\each (dictionary.of_list text.hash)
(<code>.variant (<>.some (<>.and <code>.text jsonP))))
+ <code>.any
))))
(def: (jsonF token)
- (-> JSON Code)
+ (-> JSON' Code)
(case token
- {#Null _}
+ {#Null' _}
(` #..Null)
- (^template [<ctor> <json_tag>]
- [{<json_tag> value}
- (` {<json_tag> (~ (<ctor> value))})])
- ([code.bit #..Boolean]
- [code.frac #..Number]
- [code.text #..String])
+ (^template [<ctor> <input_tag> <output_tag>]
+ [{<input_tag> value}
+ (` {<output_tag> (~ (<ctor> value))})])
+ ([code.bit #..Boolean' #..Boolean]
+ [code.frac #..Number' #..Number]
+ [code.text #..String' #..String])
- {#Array members}
+ {#Array' members}
(` {#..Array ((~! row.row) (~+ (row.list (row\each jsonF members))))})
- {#Object pairs}
+ {#Object' pairs}
(` {#..Object ((~! dictionary.of_list)
(~! text.hash)
(list (~+ (|> pairs
dictionary.entries
(list\each (function (_ [key_name value])
- (` [(~ (code.text key_name)) (~ (jsonF value))])))))))})))
+ (` [(~ (code.text key_name)) (~ (jsonF value))])))))))})
+
+ {#Code' code}
+ code))
(syntax: .public (json [token ..jsonP])
(in (list (` (: JSON (~ (jsonF token)))))))
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
index 53968905c..5bebbcde9 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux
@@ -7,7 +7,12 @@
["[0]" exception {"+" [exception:]}]]
[data
[text
- ["%" format {"+" [format]}]]]
+ ["%" format {"+" [format]}]]
+ [collection
+ ["[0]" list]]]
+ [math
+ [number
+ ["n" nat]]]
["[0]" meta
["[0]" location]]]]
["[0]" / "_"
@@ -29,7 +34,8 @@
[archive {"+" [Archive]}]]]]]])
(exception: .public (unrecognized_syntax [code Code])
- (exception.report ["Code" (%.code code)]))
+ (exception.report
+ ["Code" (%.code code)]))
... TODO: Had to split the 'compile' function due to compilation issues
... with old-luxc. Must re-combine all the code ASAP
@@ -50,8 +56,8 @@
[#.Frac /primitive.frac]
[#.Text /primitive.text])
- (^ {#.Form (list& [_ {#.Tag tag}]
- values)})
+ (^ {#.Variant (list& [_ {#.Tag tag}]
+ values)})
(case values
{#.Item value #.End}
(/structure.tagged_sum compile tag archive value)
@@ -59,8 +65,8 @@
_
(/structure.tagged_sum compile tag archive (` [(~+ values)])))
- (^ {#.Form (list& [_ {#.Nat lefts}] [_ {#.Bit right?}]
- values)})
+ (^ {#.Variant (list& [_ {#.Nat lefts}] [_ {#.Bit right?}]
+ values)})
(case values
{#.Item value #.End}
(/structure.sum compile lefts right? archive value)
@@ -83,8 +89,10 @@
{#.Identifier reference}
(/reference.reference reference)
- (^ {#.Form (list [_ {#.Record branches}] input)})
- (/case.case compile branches archive input)
+ (^ {#.Form (list [_ {#.Variant branches}] input)})
+ (if (n.even? (list.size branches))
+ (/case.case compile (list.pairs branches) archive input)
+ (//.except ..unrecognized_syntax [location.dummy code']))
(^ {#.Form (list& [_ {#.Text extension_name}] extension_args)})
(//extension.apply archive compile [extension_name extension_args])
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux
index d7a7bf6ab..69307c2ac 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux
@@ -13,7 +13,7 @@
[text
["%" format {"+" [format]}]]
[collection
- ["[0]" list ("[1]\[0]" mix monoid functor)]]]
+ ["[0]" list ("[1]\[0]" mix monoid monad)]]]
[math
[number
["n" nat]]]
@@ -57,7 +57,10 @@
coverage Coverage])
(exception.report
["Input" (%.code input)]
- ["Branches" (%.code (code.record branches))]
+ ["Branches" (%.code (code.tuple (|> branches
+ (list\each (function (_ [slot value])
+ (list slot value)))
+ list\conjoint)))]
["Coverage" (/coverage.%coverage coverage)]))
(exception: .public (cannot_have_empty_branches [message Text])
@@ -263,9 +266,9 @@
[location {#.Tag tag}]
(/.with_location location
- (analyse_pattern #.None inputT (` ((~ pattern))) next))
+ (analyse_pattern #.None inputT (` {(~ pattern)}) next))
- (^ [location {#.Form (list& [_ {#.Nat lefts}] [_ {#.Bit right?}] values)}])
+ (^ [location {#.Variant (list& [_ {#.Nat lefts}] [_ {#.Bit right?}] values)}])
(/.with_location location
(do ///.monad
[inputT' (simplify_case inputT)]
@@ -304,7 +307,7 @@
_
(/.except ..cannot_match_with_pattern [inputT' pattern]))))
- (^ [location {#.Form (list& [_ {#.Tag tag}] values)}])
+ (^ [location {#.Variant (list& [_ {#.Tag tag}] values)}])
(/.with_location location
(do ///.monad
[tag (///extension.lifted (meta.normal tag))
@@ -312,7 +315,7 @@
_ (//type.with_env
(check.check inputT variantT))
.let [[lefts right?] (/.choice (list.size group) idx)]]
- (analyse_pattern {#.Some (list.size group)} inputT (` ((~ (code.nat lefts)) (~ (code.bit right?)) (~+ values))) next)))
+ (analyse_pattern {#.Some (list.size group)} inputT (` {(~ (code.nat lefts)) (~ (code.bit right?)) (~+ values)}) next)))
_
(/.except ..not_a_pattern pattern)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux
index 417fe9709..0ccb8f1e0 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux
@@ -15,7 +15,7 @@
[text
["%" format {"+" [format]}]]
[collection
- ["[0]" list ("[1]\[0]" functor)]
+ ["[0]" list ("[1]\[0]" monad)]
["[0]" dictionary {"+" [Dictionary]}]]]
[macro
["[0]" code]]
@@ -77,9 +77,10 @@
record (List [Name Code])])
(exception.report
["Tag" (%.code (code.tag key))]
- ["Record" (%.code (code.record (list\each (function (_ [keyI valC])
- [(code.tag keyI) valC])
- record)))]))]
+ ["Record" (%.code (code.tuple (|> record
+ (list\each (function (_ [keyI valC])
+ (list (code.tag keyI) valC)))
+ list\conjoint)))]))]
[cannot_repeat_tag]
)
@@ -100,8 +101,9 @@
["Type" (%.type type)]
["Expression" (%.code (|> record
(list\each (function (_ [keyI valueC])
- [(code.tag keyI) valueC]))
- code.record))]))
+ (list (code.tag keyI) valueC)))
+ list\conjoint
+ code.tuple))]))
(def: .public (sum analyse lefts right? archive)
(-> Phase Nat Bit Phase)
diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
index 4ea0c4e7a..95775c22a 100644
--- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
+++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux
@@ -248,7 +248,7 @@
(-> Expander /////analysis.Bundle Handler)
(..custom
[($_ <>.and <code>.local_identifier <code>.any
- (<>.or (<code>.form (<>.some <code>.text))
+ (<>.or (<code>.variant (<>.some <code>.text))
(<code>.tuple (<>.some <code>.text)))
<code>.any)
(function (_ extension_name phase archive [short_name valueC labels exported?C])