aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/tool/compiler/default/init.lux26
-rw-r--r--stdlib/source/lux/tool/compiler/default/syntax.lux58
2 files changed, 51 insertions, 33 deletions
diff --git a/stdlib/source/lux/tool/compiler/default/init.lux b/stdlib/source/lux/tool/compiler/default/init.lux
index f5166fc25..34ba2a1fd 100644
--- a/stdlib/source/lux/tool/compiler/default/init.lux
+++ b/stdlib/source/lux/tool/compiler/default/init.lux
@@ -8,7 +8,7 @@
[data
["." product]
["." error (#+ Error)]
- ["." text ("#;." hash)
+ ["." text ("#@." hash)
format]
[collection
["." list ("#@." functor)]
@@ -181,15 +181,15 @@
_ (..refresh expander)]
(wrap [source requirements post-buffer])))
-(def: (iterate expander module source pre-buffer)
+(def: (iterate expander module source pre-buffer aliases)
(All [statement]
- (-> Expander Module Source (generation.Buffer statement)
+ (-> Expander Module Source (generation.Buffer statement) Aliases
(All [anchor expression]
(///statement.Operation anchor expression statement
(Maybe [Source Requirements (generation.Buffer statement)])))))
(do ///phase.monad
[reader (///statement.lift-analysis
- (..reader module //syntax.no-aliases source))]
+ (..reader module aliases source))]
(function (_ state)
(case (///phase.run' state (..iteration expander reader source pre-buffer))
(#error.Success [state source&requirements&buffer])
@@ -202,10 +202,14 @@
(def: (default-dependencies prelude input)
(-> Module ///.Input (List Module))
- (if (text;= prelude (get@ #///.module input))
+ (if (text@= prelude (get@ #///.module input))
(list)
(list prelude)))
+(def: module-aliases
+ (-> .Module Aliases)
+ (|>> (get@ #.module-aliases) (dictionary.from-list text.hash)))
+
(def: #export (compiler expander prelude)
(-> Expander Module
(All [anchor expression statement]
@@ -216,12 +220,12 @@
{#///.dependencies dependencies
#///.process (function (_ state archive)
(do error.monad
- [#let [hash (text;hash (get@ #///.code input))]
+ [#let [hash (text@hash (get@ #///.code input))]
[state [source buffer]] (<| (///phase.run' state)
(..begin dependencies hash input))
#let [module (get@ #///.module input)]]
(loop [iteration (<| (///phase.run' state)
- (..iterate expander module source buffer))]
+ (..iterate expander module source buffer //syntax.no-aliases))]
(do @
[[state ?source&requirements&buffer] iteration]
(case ?source&requirements&buffer
@@ -251,9 +255,13 @@
#///.process (function (_ state archive)
(recur (<| (///phase.run' state)
(do ///phase.monad
- [_ (monad.map @ execute! (get@ #///statement.referrals requirements))
+ [analysis-module (<| (: (Operation .Module))
+ ///statement.lift-analysis
+ extension.lift
+ macro.current-module)
+ _ (monad.map @ execute! (get@ #///statement.referrals requirements))
_ (..refresh expander)]
- (..iterate expander module source buffer)))))})])
+ (..iterate expander module source buffer (..module-aliases analysis-module))))))})])
)))))}))))
(def: #export key
diff --git a/stdlib/source/lux/tool/compiler/default/syntax.lux b/stdlib/source/lux/tool/compiler/default/syntax.lux
index b7197f3af..2962a5ea8 100644
--- a/stdlib/source/lux/tool/compiler/default/syntax.lux
+++ b/stdlib/source/lux/tool/compiler/default/syntax.lux
@@ -29,8 +29,9 @@
[abstract
monad]
[control
- ["ex" exception (#+ exception:)]]
+ ["." exception (#+ exception:)]]
[data
+ ["." maybe]
["." error (#+ Error)]
[number
["." nat]
@@ -126,7 +127,8 @@
(def: #export name-separator ".")
(exception: #export (end-of-file {module Text})
- (ex.report ["Module" (%t module)]))
+ (exception.report
+ ["Module" (%t module)]))
(def: amount-of-input-shown 64)
@@ -136,14 +138,16 @@
(!clip start end input)))
(exception: #export (unrecognized-input {[file line column] Cursor} {context Text} {input Text} {offset Offset})
- (ex.report ["File" file]
- ["Line" (%n line)]
- ["Column" (%n column)]
- ["Context" (%t context)]
- ["Input" (input-at offset input)]))
+ (exception.report
+ ["File" file]
+ ["Line" (%n line)]
+ ["Column" (%n column)]
+ ["Context" (%t context)]
+ ["Input" (input-at offset input)]))
(exception: #export (text-cannot-contain-new-lines {text Text})
- (ex.report ["Text" (%t text)]))
+ (exception.report
+ ["Text" (%t text)]))
(type: (Parser a)
(-> Source (Either [Source Text] [Source a])))
@@ -231,7 +235,7 @@
g!_
(#.Left [[where offset source-code]
- (ex.construct ..text-cannot-contain-new-lines content)])))
+ (exception.construct ..text-cannot-contain-new-lines content)])))
(template: (!read-text where offset source-code)
(case ("lux text index" offset (static ..text-delimiter) source-code)
@@ -246,7 +250,7 @@
_
(#.Left [[where offset source-code]
- (ex.construct unrecognized-input [where "Text" source-code offset])])))
+ (exception.construct unrecognized-input [where "Text" source-code offset])])))
(def: digit-bottom Nat (!dec (char "0")))
(def: digit-top Nat (!inc (char "9")))
@@ -284,7 +288,10 @@
(!digit? char)))
(template: (!number-output <start> <end> <codec> <tag>)
- (case (:: <codec> decode (!clip <start> <end> source-code))
+ (case (|> source-code
+ (!clip <start> <end>)
+ (text.replace-all ..digit-separator "")
+ (:: <codec> decode))
(#.Right output)
(#.Right [[(update@ #.column (n/+ (!n/- <start> <end>)) where)
<end>
@@ -300,7 +307,7 @@
(with-expansions [<int-output> (as-is (!number-output start end int.decimal #.Int))
<frac-output> (as-is (!number-output start end frac.decimal #.Frac))
<failure> (#.Left [[where offset source-code]
- (ex.construct unrecognized-input [where "Frac" source-code offset])])]
+ (exception.construct unrecognized-input [where "Frac" source-code offset])])]
(def: (parse-frac source-code//size start [where offset source-code])
(-> Nat Offset (Parser Code))
(loop [end offset
@@ -351,12 +358,12 @@
[!parse-rev rev.decimal #.Rev]
)
-(template: (!parse-signed source-code//size offset where source-code @end)
+(template: (!parse-signed source-code//size offset where source-code @aliases @end)
(let [g!offset/1 (!inc offset)]
(<| (!with-char+ source-code//size source-code g!offset/1 g!char/1 @end)
(if (!digit? g!char/1)
(parse-signed offset [where (!inc/2 offset) source-code])
- (!parse-full-name offset [where (!inc offset) source-code] where #.Identifier)))))
+ (!parse-full-name offset [where (!inc offset) source-code] where @aliases #.Identifier)))))
(with-expansions [<output> (#.Right [[(update@ #.column (n/+ (!n/- start end)) where)
end
@@ -373,11 +380,11 @@
(template: (!failure where offset source-code)
(#.Left [[where offset source-code]
- (ex.construct unrecognized-input [where "General" source-code offset])]))
+ (exception.construct unrecognized-input [where "General" source-code offset])]))
(template: (!end-of-file where offset source-code current-module)
(#.Left [[where offset source-code]
- (ex.construct ..end-of-file current-module)]))
+ (exception.construct ..end-of-file current-module)]))
(with-expansions [<consume-1> (as-is [where (!inc offset/0) source-code])
<consume-2> (as-is [where (!inc/2 offset/0) source-code])]
@@ -406,19 +413,22 @@
(#.Right [source' [@where (@tag name)]])))
(with-expansions [<simple> (as-is (#.Right [source' ["" simple]]))]
- (`` (def: (parse-full-name start source)
- (-> Offset (Parser Name))
+ (`` (def: (parse-full-name aliases start source)
+ (-> Aliases Offset (Parser Name))
(!letE [source' simple] (..parse-name-part start source)
(let [[where' offset' source-code'] source']
(<| (!with-char source-code' offset' char/separator <simple>)
(if (!n/= (char (~~ (static ..name-separator))) char/separator)
(let [offset'' (!inc offset')]
(!letE [source'' complex] (..parse-name-part offset'' [where' offset'' source-code'])
- (#.Right [source'' [simple complex]])))
+ (#.Right [source'' [(|> aliases
+ (dictionary.get simple)
+ (maybe.default simple))
+ complex]])))
<simple>)))))))
- (template: (!parse-full-name @offset @source @where @tag)
- (!letE [source' full-name] (..parse-full-name @offset @source)
+ (template: (!parse-full-name @offset @source @where @aliases @tag)
+ (!letE [source' full-name] (..parse-full-name @aliases @offset @source)
(#.Right [source' [@where (@tag full-name)]])))
## TODO: Grammar macro for specifying syntax.
@@ -507,7 +517,7 @@
## else
(cond (!name-char?|head char/1) ## Tag
- (!parse-full-name offset/1 <consume-2> where #.Tag)
+ (!parse-full-name offset/1 <consume-2> where aliases #.Tag)
## else
(!failure where offset/0 source-code)))))
@@ -524,7 +534,7 @@
[(~~ (static ..positive-sign))
(~~ (static ..negative-sign))]
- (!parse-signed source-code//size offset/0 where source-code
+ (!parse-signed source-code//size offset/0 where source-code aliases
(!end-of-file where offset/0 source-code current-module))]
## else
@@ -533,7 +543,7 @@
(let [offset/1 (!inc offset/0)]
(!parse-nat source-code//size offset/0 where offset/1 source-code))
## Identifier
- (!parse-full-name offset/0 <consume-1> where #.Identifier))
+ (!parse-full-name offset/0 <consume-1> where aliases #.Identifier))
)))
)))
))