aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library')
-rw-r--r--stdlib/source/library/lux/control/parser/cli.lux93
-rw-r--r--stdlib/source/library/lux/control/parser/tree.lux60
-rw-r--r--stdlib/source/library/lux/program.lux18
-rw-r--r--stdlib/source/library/lux/tool/compiler/meta/cli.lux29
4 files changed, 24 insertions, 176 deletions
diff --git a/stdlib/source/library/lux/control/parser/cli.lux b/stdlib/source/library/lux/control/parser/cli.lux
deleted file mode 100644
index 694cb93fc..000000000
--- a/stdlib/source/library/lux/control/parser/cli.lux
+++ /dev/null
@@ -1,93 +0,0 @@
-(.require
- [library
- [lux (.except parameter)
- [abstract
- [monad (.only do)]]
- [control
- ["[0]" try (.only Try)]]
- [data
- ["[0]" text (.use "[1]#[0]" equivalence)
- ["%" \\format (.only format)]]]]]
- ["[0]" //])
-
-(type .public (Parser a)
- (//.Parser (List Text) a))
-
-(def .public (result parser inputs)
- (All (_ a) (-> (Parser a) (List Text) (Try a)))
- (case (//.result parser inputs)
- {try.#Success [remaining output]}
- (case remaining
- {.#End}
- {try.#Success output}
-
- _
- {try.#Failure (format "Remaining CLI inputs: " (text.interposed " " remaining))})
-
- {try.#Failure try}
- {try.#Failure try}))
-
-(def .public any
- (Parser Text)
- (function (_ inputs)
- (case inputs
- {.#Item arg inputs'}
- {try.#Success [inputs' arg]}
-
- _
- {try.#Failure "Cannot parse empty arguments."})))
-
-(def .public (parse parser)
- (All (_ a) (-> (-> Text (Try a)) (Parser a)))
- (function (_ inputs)
- (do try.monad
- [[remaining raw] (any inputs)
- output (parser raw)]
- (in [remaining output]))))
-
-(def .public (this reference)
- (-> Text (Parser Any))
- (function (_ inputs)
- (do try.monad
- [[remaining raw] (any inputs)]
- (if (text#= reference raw)
- (in [remaining []])
- {try.#Failure (format "Missing token: '" reference "'")}))))
-
-(def .public (somewhere cli)
- (All (_ a) (-> (Parser a) (Parser a)))
- (function (_ inputs)
- (loop (again [immediate inputs])
- (case (//.result cli immediate)
- {try.#Success [remaining output]}
- {try.#Success [remaining output]}
-
- {try.#Failure try}
- (case immediate
- {.#End}
- {try.#Failure try}
-
- {.#Item to_omit immediate'}
- (do try.monad
- [[remaining output] (again immediate')]
- (in [{.#Item to_omit remaining}
- output])))))))
-
-(def .public end
- (Parser Any)
- (function (_ inputs)
- (case inputs
- {.#End} {try.#Success [inputs []]}
- _ {try.#Failure (format "Unknown parameters: " (text.interposed " " inputs))})))
-
-(def .public (named name value)
- (All (_ a) (-> Text (Parser a) (Parser a)))
- (|> value
- (//.after (..this name))
- ..somewhere))
-
-(def .public (parameter [short long] value)
- (All (_ a) (-> [Text Text] (Parser a) (Parser a)))
- (|> value
- (//.after (//.either (..this short) (..this long)))
- ..somewhere))
diff --git a/stdlib/source/library/lux/control/parser/tree.lux b/stdlib/source/library/lux/control/parser/tree.lux
deleted file mode 100644
index e94e8a96c..000000000
--- a/stdlib/source/library/lux/control/parser/tree.lux
+++ /dev/null
@@ -1,60 +0,0 @@
-(.require
- [library
- [lux (.except left right)
- [abstract
- [monad (.only do)]]
- [control
- ["[0]" try (.only Try)]
- ["[0]" exception (.only exception)]]
- [data
- [collection
- [tree (.only Tree)
- ["[0]" zipper (.only Zipper)]]]]]]
- ["[0]" //])
-
-(type .public (Parser t a)
- (//.Parser (Zipper t) a))
-
-(def .public (result' parser zipper)
- (All (_ t a) (-> (Parser t a) (Zipper t) (Try a)))
- (do try.monad
- [[zipper output] (//.result parser zipper)]
- (in output)))
-
-(def .public (result parser tree)
- (All (_ t a) (-> (Parser t a) (Tree t) (Try a)))
- (result' parser (zipper.zipper tree)))
-
-(def .public value
- (All (_ t) (Parser t t))
- (function (_ zipper)
- {try.#Success [zipper (zipper.value zipper)]}))
-
-(exception .public cannot_move_further)
-
-(with_template [<name> <direction>]
- [(def .public <name>
- (All (_ t) (Parser t []))
- (function (_ zipper)
- (case (<direction> zipper)
- {.#None}
- (exception.except ..cannot_move_further [])
-
- {.#Some next}
- {try.#Success [next []]})))]
-
- [down zipper.down]
- [up zipper.up]
-
- [right zipper.right]
- [rightmost zipper.rightmost]
-
- [left zipper.left]
- [leftmost zipper.leftmost]
-
- [next zipper.next]
- [end zipper.end]
-
- [previous zipper.previous]
- [start zipper.start]
- )
diff --git a/stdlib/source/library/lux/program.lux b/stdlib/source/library/lux/program.lux
index 99fb1832e..81b455cb1 100644
--- a/stdlib/source/library/lux/program.lux
+++ b/stdlib/source/library/lux/program.lux
@@ -5,15 +5,15 @@
[abstract
[monad (.only do)]]
[control
+ ["<>" parser]
["[0]" io]
[concurrency
- ["[0]" thread]]
- ["<>" parser (.only)
- ["<[0]>" cli]]]
+ ["[0]" thread]]]
[macro (.only with_symbols)
[syntax (.only syntax)]
["[0]" code (.only)
- ["<[1]>" \\parser]]]]])
+ ["<[1]>" \\parser]]]]]
+ ["</>" \\parser])
(type Arguments
(Variant
@@ -46,11 +46,11 @@
{#Parsed args}
(` (.function ((~ g!program) (~ g!args))
- (case ((~! <cli>.result) (.is (~! (<cli>.Parser (io.IO .Any)))
- ((~! do) (~! <>.monad)
- [(~+ args)
- (~ g!_) (~! <cli>.end)]
- ((~' in) (~ initialization+event_loop))))
+ (case ((~! </>.result) (.is (~! (</>.Parser (io.IO .Any)))
+ ((~! do) (~! <>.monad)
+ [(~+ args)
+ (~ g!_) (~! </>.end)]
+ ((~' in) (~ initialization+event_loop))))
(~ g!args))
{.#Right (~ g!output)}
(~ g!output)
diff --git a/stdlib/source/library/lux/tool/compiler/meta/cli.lux b/stdlib/source/library/lux/tool/compiler/meta/cli.lux
index 685467d32..caeb07961 100644
--- a/stdlib/source/library/lux/tool/compiler/meta/cli.lux
+++ b/stdlib/source/library/lux/tool/compiler/meta/cli.lux
@@ -5,9 +5,8 @@
[monad (.only do)]
[equivalence (.only Equivalence)]]
[control
- ["[0]" pipe]
- ["<>" parser (.only)
- ["<[0]>" cli (.only Parser)]]]
+ ["<>" parser]
+ ["[0]" pipe]]
[data
["[0]" product]
["[0]" text (.only)
@@ -22,6 +21,8 @@
[meta
["[0]" symbol]
["[0]" configuration (.only Configuration)]]
+ ["[0]" program
+ ["<[1]>" \\parser (.only Parser)]]
[tool
[compiler
[meta
@@ -73,15 +74,15 @@
(with_template [<name> <long> <type> <parser>]
[(def <name>
(Parser <type>)
- (<cli>.named <long> <parser>))]
+ (<program>.named <long> <parser>))]
- [host_dependency_parser "--host_dependency" Host_Dependency <cli>.any]
- [library_parser "--library" Library <cli>.any]
- [compiler_parser "--compiler" Compiler (<text>.then /compiler.parser <cli>.any)]
- [source_parser "--source" Source <cli>.any]
- [target_parser "--target" Target <cli>.any]
- [module_parser "--module" Module <cli>.any]
- [configuration_parser "--configuration" Configuration (<text>.then configuration.parser <cli>.any)]
+ [host_dependency_parser "--host_dependency" Host_Dependency <program>.any]
+ [library_parser "--library" Library <program>.any]
+ [compiler_parser "--compiler" Compiler (<text>.then /compiler.parser <program>.any)]
+ [source_parser "--source" Source <program>.any]
+ [target_parser "--target" Target <program>.any]
+ [module_parser "--module" Module <program>.any]
+ [configuration_parser "--configuration" Configuration (<text>.then configuration.parser <program>.any)]
)
(def .public service
@@ -96,11 +97,11 @@
..module_parser
(<>.else configuration.empty ..configuration_parser)))]
(all <>.or
- (<>.after (<cli>.this "build")
+ (<>.after (<program>.this "build")
compilation)
- (<>.after (<cli>.this "repl")
+ (<>.after (<program>.this "repl")
compilation)
- (<>.after (<cli>.this "export")
+ (<>.after (<program>.this "export")
(all <>.and
(<>.some ..source_parser)
..target_parser))