diff options
Diffstat (limited to 'stdlib/source')
61 files changed, 570 insertions, 482 deletions
diff --git a/stdlib/source/lux/abstract/monad/indexed.lux b/stdlib/source/lux/abstract/monad/indexed.lux index 57a18c109..348a11024 100644 --- a/stdlib/source/lux/abstract/monad/indexed.lux +++ b/stdlib/source/lux/abstract/monad/indexed.lux @@ -2,12 +2,13 @@ [lux #* [control [monad] - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data [collection ["." list ("#;." functor fold)]]] ["." macro - ["s" syntax (#+ Syntax syntax:)]]]) + [syntax (#+ syntax:)]]]) (signature: #export (IxMonad m) (: (All [p a] @@ -23,7 +24,7 @@ (type: Binding [Code Code]) (def: binding - (Syntax Binding) + (Parser Binding) (p.and s.any s.any)) (type: Context @@ -31,7 +32,7 @@ (#Bind Binding)) (def: context - (Syntax Context) + (Parser Context) (p.or (p.after (s.this (' #let)) (s.tuple (p.some binding))) binding)) diff --git a/stdlib/source/lux/control/concatenative.lux b/stdlib/source/lux/control/concatenative.lux index 9a20132fd..d922e5264 100644 --- a/stdlib/source/lux/control/concatenative.lux +++ b/stdlib/source/lux/control/concatenative.lux @@ -14,13 +14,13 @@ ["." list ("#;." fold functor)]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)] - [syntax + [syntax (#+ syntax:) ["cs" common ["csr" reader] ["csw" writer]]]]] [// - ["p" parser ("#;." monad)]]) + ["p" parser ("#;." monad) + ["s" code (#+ Parser)]]]) ## [Syntax] (type: Alias [Text Code]) @@ -30,18 +30,18 @@ #top (List Code)}) (def: aliases^ - (s.Syntax (List Alias)) + (Parser (List Alias)) (|> (p.and s.local-identifier s.any) p.some s.record (p.default (list)))) (def: bottom^ - (s.Syntax Nat) + (Parser Nat) (s.form (p.after (s.this (` #.Parameter)) s.nat))) (def: stack^ - (s.Syntax Stack) + (Parser Stack) (p.either (p.and (p.maybe bottom^) (s.tuple (p.some s.any))) (p.and (|> bottom^ (p;map (|>> #.Some))) diff --git a/stdlib/source/lux/control/concurrency/actor.lux b/stdlib/source/lux/control/concurrency/actor.lux index 97aa88b5c..3754984d7 100644 --- a/stdlib/source/lux/control/concurrency/actor.lux +++ b/stdlib/source/lux/control/concurrency/actor.lux @@ -4,7 +4,8 @@ monad] [control ["." function] - ["p" parser] + ["p" parser + ["s" code (#+ Parser)]] ["ex" exception (#+ exception:)] ["." io (#+ IO io) ("#;." monad)]] [data @@ -16,8 +17,7 @@ ["." list ("#;." monoid monad fold)]]] ["." macro (#+ with-gensyms monad) ["." code] - ["s" syntax (#+ syntax: Syntax)] - [syntax + [syntax (#+ syntax:) ["cs" common ["csr" reader] ["csw" writer]]]] @@ -182,7 +182,7 @@ ) (def: actor-decl^ - (Syntax [Text (List Text)]) + (Parser [Text (List Text)]) (p.either (s.form (p.and s.local-identifier (p.some s.local-identifier))) (p.and s.local-identifier (:: p.monad wrap (list))))) @@ -206,7 +206,7 @@ [(Maybe HandleC) (Maybe StopC)]) (def: behavior^ - (s.Syntax BehaviorC) + (Parser BehaviorC) (let [handle-args ($_ p.and s.local-identifier s.local-identifier s.local-identifier) stop-args ($_ p.and s.local-identifier s.local-identifier)] (p.and (p.maybe (s.form (p.and (s.form (p.after (s.this (' handle)) handle-args)) @@ -295,7 +295,7 @@ #output Code}) (def: signature^ - (s.Syntax Signature) + (Parser Signature) (s.form ($_ p.and (p.default (list) (s.tuple (p.some s.local-identifier))) s.local-identifier @@ -305,7 +305,7 @@ s.any))) (def: reference^ - (s.Syntax [Name (List Text)]) + (Parser [Name (List Text)]) (p.either (s.form (p.and s.identifier (p.some s.local-identifier))) (p.and s.identifier (:: p.monad wrap (list))))) diff --git a/stdlib/source/lux/control/continuation.lux b/stdlib/source/lux/control/continuation.lux index 591966b89..cd8f6a131 100644 --- a/stdlib/source/lux/control/continuation.lux +++ b/stdlib/source/lux/control/continuation.lux @@ -5,10 +5,12 @@ [apply (#+ Apply)] [monad (#+ Monad do)]] [control - ["." function]] + ["." function] + [parser + ["s" code]]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]]]) + [syntax (#+ syntax:)]]]) (type: #export (Cont i o) {#.doc "Continuations."} diff --git a/stdlib/source/lux/control/contract.lux b/stdlib/source/lux/control/contract.lux index 1add3be8f..4e5e70317 100644 --- a/stdlib/source/lux/control/contract.lux +++ b/stdlib/source/lux/control/contract.lux @@ -2,12 +2,15 @@ [lux #* [abstract monad] + [control + [parser + ["s" code]]] [data [text format]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]]]) + [syntax (#+ syntax:)]]]) (def: #export (assert! message test) (-> Text Bit []) diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index d24277208..a8252977f 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -3,7 +3,8 @@ [abstract [monad (#+ do)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["//" error (#+ Error)] ["." maybe] @@ -15,7 +16,7 @@ ["." list ("#@." functor fold)]]] ["." macro ["." code] - ["s" syntax (#+ syntax: Syntax)] + [syntax (#+ syntax:)] [syntax ["cs" common ["csr" reader] diff --git a/stdlib/source/lux/control/io.lux b/stdlib/source/lux/control/io.lux index 4102ff9c4..e4e358878 100644 --- a/stdlib/source/lux/control/io.lux +++ b/stdlib/source/lux/control/io.lux @@ -4,10 +4,13 @@ [functor (#+ Functor)] [apply (#+ Apply)] [monad (#+ Monad do)]] + [control + [parser + ["s" code]]] [type abstract] ["." macro (#+ with-gensyms) - ["s" syntax (#+ syntax:)] + [syntax (#+ syntax:)] ["." template]]]) (abstract: #export (IO a) diff --git a/stdlib/source/lux/control/parser/cli.lux b/stdlib/source/lux/control/parser/cli.lux index e3ac37255..38f22602f 100644 --- a/stdlib/source/lux/control/parser/cli.lux +++ b/stdlib/source/lux/control/parser/cli.lux @@ -10,11 +10,12 @@ ["." error (#+ Error)]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ Syntax syntax:)]] + [syntax (#+ syntax:)]] [tool [compiler ["." host]]]] ["." // + ["s" code] [// ["." io] [concurrency @@ -113,7 +114,7 @@ (#Parsed (List [Code Code]))) (def: program-args^ - (Syntax Program-Args) + (s.Parser Program-Args) (//.or s.local-identifier (s.tuple (//.some (//.either (do //.monad [name s.local-identifier] diff --git a/stdlib/source/lux/control/parser/code.lux b/stdlib/source/lux/control/parser/code.lux new file mode 100644 index 000000000..56cbe5bc2 --- /dev/null +++ b/stdlib/source/lux/control/parser/code.lux @@ -0,0 +1,193 @@ +(.module: + [lux (#- nat int rev) + [abstract + ["." monad (#+ do)]] + [data + ["." bit] + ["." name] + ["." error (#+ Error)] + [number + ["." nat] + ["." int] + ["." rev] + ["." frac]] + ["." text ("#@." monoid)] + [collection + ["." list ("#@." functor)]]] + [macro + ["." code ("#@." equivalence)]]] + ["." //]) + +(def: (join-pairs pairs) + (All [a] (-> (List [a a]) (List a))) + (case pairs + #.Nil #.Nil + (#.Cons [[x y] pairs']) (list& x y (join-pairs pairs')))) + +(type: #export Parser + {#.doc "A Lux syntax parser."} + (//.Parser (List Code))) + +(def: (remaining-inputs asts) + (-> (List Code) Text) + ($_ text@compose text.new-line "Remaining input: " + (|> asts (list@map code.to-text) (list.interpose " ") (text.join-with "")))) + +(def: #export any + {#.doc "Just returns the next input without applying any logic."} + (Parser Code) + (function (_ tokens) + (case tokens + #.Nil (#error.Failure "There are no tokens to parse!") + (#.Cons [t tokens']) (#error.Success [tokens' t])))) + +(template [<get-name> <type> <tag> <eq> <desc>] + [(def: #export <get-name> + {#.doc (code.text ($_ text@compose "Parses the next " <desc> " input Code."))} + (Parser <type>) + (function (_ tokens) + (case tokens + (#.Cons [[_ (<tag> x)] tokens']) + (#error.Success [tokens' x]) + + _ + (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))] + + [ bit Bit #.Bit bit.equivalence "bit"] + [ nat Nat #.Nat nat.equivalence "nat"] + [ int Int #.Int int.equivalence "int"] + [ rev Rev #.Rev rev.equivalence "rev"] + [ frac Frac #.Frac frac.equivalence "frac"] + [ text Text #.Text text.equivalence "text"] + [identifier Name #.Identifier name.equivalence "identifier"] + [ tag Name #.Tag name.equivalence "tag"] + ) + +(def: #export (this? ast) + {#.doc "Asks if the given Code is the next input."} + (-> Code (Parser Bit)) + (function (_ tokens) + (case tokens + (#.Cons [token tokens']) + (let [is-it? (code@= ast token) + remaining (if is-it? + tokens' + tokens)] + (#error.Success [remaining is-it?])) + + _ + (#error.Success [tokens #0])))) + +(def: #export (this ast) + {#.doc "Ensures the given Code is the next input."} + (-> Code (Parser Any)) + (function (_ tokens) + (case tokens + (#.Cons [token tokens']) + (if (code@= ast token) + (#error.Success [tokens' []]) + (#error.Failure ($_ text@compose "Expected a " (code.to-text ast) " but instead got " (code.to-text token) + (remaining-inputs tokens)))) + + _ + (#error.Failure "There are no tokens to parse!")))) + +(template [<name> <tag> <desc>] + [(def: #export <name> + {#.doc (code.text ($_ text@compose "Parse a local " <desc> " (a " <desc> " that has no module prefix)."))} + (Parser Text) + (function (_ tokens) + (case tokens + (#.Cons [[_ (<tag> ["" x])] tokens']) + (#error.Success [tokens' x]) + + _ + (#error.Failure ($_ text@compose "Cannot parse local " <desc> (remaining-inputs tokens))))))] + + [local-identifier #.Identifier "identifier"] + [ local-tag #.Tag "tag"] + ) + +(template [<name> <tag> <desc>] + [(def: #export (<name> p) + {#.doc (code.text ($_ text@compose "Parse inside the contents of a " <desc> " as if they were the input Codes."))} + (All [a] + (-> (Parser a) (Parser a))) + (function (_ tokens) + (case tokens + (#.Cons [[_ (<tag> members)] tokens']) + (case (p members) + (#error.Success [#.Nil x]) (#error.Success [tokens' x]) + _ (#error.Failure ($_ text@compose "Parser was expected to fully consume " <desc> (remaining-inputs tokens)))) + + _ + (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))] + + [ form #.Form "form"] + [tuple #.Tuple "tuple"] + ) + +(def: #export (record p) + {#.doc (code.text ($_ text@compose "Parse inside the contents of a record as if they were the input Codes."))} + (All [a] + (-> (Parser a) (Parser a))) + (function (_ tokens) + (case tokens + (#.Cons [[_ (#.Record pairs)] tokens']) + (case (p (join-pairs pairs)) + (#error.Success [#.Nil x]) (#error.Success [tokens' x]) + _ (#error.Failure ($_ text@compose "Parser was expected to fully consume record" (remaining-inputs tokens)))) + + _ + (#error.Failure ($_ text@compose "Cannot parse record" (remaining-inputs tokens)))))) + +(def: #export end! + {#.doc "Ensures there are no more inputs."} + (Parser Any) + (function (_ tokens) + (case tokens + #.Nil (#error.Success [tokens []]) + _ (#error.Failure ($_ text@compose "Expected list of tokens to be empty!" (remaining-inputs tokens)))))) + +(def: #export end? + {#.doc "Checks whether there are no more inputs."} + (Parser Bit) + (function (_ tokens) + (case tokens + #.Nil (#error.Success [tokens #1]) + _ (#error.Success [tokens #0])))) + +(def: #export (lift outcome) + (All [a] (-> (Error a) (Parser a))) + (function (_ input) + (case outcome + (#error.Failure error) + (#error.Failure error) + + (#error.Success value) + (#error.Success [input value]) + ))) + +(def: #export (run inputs syntax) + (All [a] (-> (List Code) (Parser a) (Error a))) + (case (syntax inputs) + (#error.Failure error) + (#error.Failure error) + + (#error.Success [unconsumed value]) + (case unconsumed + #.Nil + (#error.Success value) + + _ + (#error.Failure (text@compose "Unconsumed inputs: " + (|> (list@map code.to-text unconsumed) + (text.join-with ", "))))))) + +(def: #export (local inputs syntax) + {#.doc "Run a syntax parser with the given list of inputs, instead of the real ones."} + (All [a] (-> (List Code) (Parser a) (Parser a))) + (function (_ real) + (do error.monad + [value (run inputs syntax)] + (wrap [real value])))) diff --git a/stdlib/source/lux/control/pipe.lux b/stdlib/source/lux/control/pipe.lux index b6381e7a6..a53b61164 100644 --- a/stdlib/source/lux/control/pipe.lux +++ b/stdlib/source/lux/control/pipe.lux @@ -3,17 +3,18 @@ [abstract [monad (#+ do)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["e" error] [collection ["." list ("#;." fold monad)]]] [macro (#+ with-gensyms) - ["s" syntax (#+ syntax: Syntax)] + [syntax (#+ syntax:)] ["." code]]]) (def: body^ - (Syntax (List Code)) + (Parser (List Code)) (s.tuple (p.some s.any))) (syntax: #export (new> start @@ -36,7 +37,7 @@ (~ body)))))) (def: _reverse_ - (Syntax Any) + (Parser Any) (function (_ tokens) (#e.Success [(list.reverse tokens) []]))) diff --git a/stdlib/source/lux/control/remember.lux b/stdlib/source/lux/control/remember.lux index 6d21a1948..58b576672 100644 --- a/stdlib/source/lux/control/remember.lux +++ b/stdlib/source/lux/control/remember.lux @@ -3,7 +3,8 @@ [abstract [monad (#+ do)]] [control - ["p" parser ("#@." functor)] + ["p" parser ("#@." functor) + ["s" code (#+ Parser)]] ["ex" exception (#+ exception:)]] [data ["." error] @@ -14,7 +15,7 @@ ["." date (#+ Date) ("#@." order codec)]] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)]] + [syntax (#+ syntax:)]] ["." io]]) (exception: #export (must-remember {message Text} {focus (Maybe Code)}) @@ -27,7 +28,7 @@ ""))) (def: deadline - (Syntax Date) + (Parser Date) ($_ p.either (p@map (|>> instant.from-millis instant.date) s.int) diff --git a/stdlib/source/lux/control/security/capability.lux b/stdlib/source/lux/control/security/capability.lux index 48392c045..fdf51d1b7 100644 --- a/stdlib/source/lux/control/security/capability.lux +++ b/stdlib/source/lux/control/security/capability.lux @@ -6,7 +6,9 @@ ["p" parser] ["." io (#+ IO)] [concurrency - ["." promise (#+ Promise)]]] + ["." promise (#+ Promise)]] + [parser + ["s" code]]] [data [text format] @@ -16,7 +18,7 @@ abstract] ["." macro ["." code] - ["s" syntax (#+ syntax:) + [syntax (#+ syntax:) [common ["." reader] ["." writer]]]]]) diff --git a/stdlib/source/lux/data/collection/dictionary/ordered.lux b/stdlib/source/lux/data/collection/dictionary/ordered.lux index d8cf01121..ed090a5d7 100644 --- a/stdlib/source/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/lux/data/collection/dictionary/ordered.lux @@ -10,8 +10,7 @@ [collection ["." list ("#@." monoid fold)]]] ["." macro - ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + ["." code]]]) (def: error-message Text "Invariant violation") diff --git a/stdlib/source/lux/data/collection/row.lux b/stdlib/source/lux/data/collection/row.lux index 1810ca828..722526e26 100644 --- a/stdlib/source/lux/data/collection/row.lux +++ b/stdlib/source/lux/data/collection/row.lux @@ -9,7 +9,8 @@ [fold (#+ Fold)] [predicate (#+ Predicate)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." maybe] ["." product] @@ -20,7 +21,7 @@ ["." array (#+ Array) ("#@." functor fold)]]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]] + [syntax (#+ syntax:)]] [tool [compiler ["@" host]]]]) diff --git a/stdlib/source/lux/data/collection/sequence.lux b/stdlib/source/lux/data/collection/sequence.lux index 07735cc26..ef61dd427 100644 --- a/stdlib/source/lux/data/collection/sequence.lux +++ b/stdlib/source/lux/data/collection/sequence.lux @@ -5,10 +5,11 @@ [comonad (#+ CoMonad)]] [control ["." continuation (#+ Cont pending)] - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]] + [syntax (#+ syntax:)]] [data ["." bit] [collection diff --git a/stdlib/source/lux/data/collection/tree.lux b/stdlib/source/lux/data/collection/tree.lux index ad64b72ed..6daf575a6 100644 --- a/stdlib/source/lux/data/collection/tree.lux +++ b/stdlib/source/lux/data/collection/tree.lux @@ -6,13 +6,14 @@ equivalence fold] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data [collection ["." list ("#@." monad fold)]]] ["." macro ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) (type: #export (Tree a) {#value a @@ -37,7 +38,7 @@ [Code (List Tree-Code)]) (def: tree^ - (Syntax Tree-Code) + (Parser Tree-Code) (|> (|>> p.some s.record (p.and s.any)) p.rec p.some diff --git a/stdlib/source/lux/data/collection/tree/zipper.lux b/stdlib/source/lux/data/collection/tree/zipper.lux index bac8961e3..1c94d734e 100644 --- a/stdlib/source/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/lux/data/collection/tree/zipper.lux @@ -8,10 +8,7 @@ ["." maybe ("#@." monad)] [collection ["." list ("#@." functor fold monoid)] - ["." stack (#+ Stack)]]] - ["." macro - ["." code] - ["s" syntax (#+ Syntax syntax:)]]] + ["." stack (#+ Stack)]]]] ["." // (#+ Tree) ("#@." functor)]) (type: #export (Zipper a) diff --git a/stdlib/source/lux/data/format/css/font.lux b/stdlib/source/lux/data/format/css/font.lux index 2ed7c0f4d..b809f45e6 100644 --- a/stdlib/source/lux/data/format/css/font.lux +++ b/stdlib/source/lux/data/format/css/font.lux @@ -2,8 +2,11 @@ [lux #* [type abstract] + [control + [parser + ["s" code]]] ["." macro - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [world [net (#+ URL)]]] ["." // #_ diff --git a/stdlib/source/lux/data/format/css/property.lux b/stdlib/source/lux/data/format/css/property.lux index 214a2f3c7..29e919501 100644 --- a/stdlib/source/lux/data/format/css/property.lux +++ b/stdlib/source/lux/data/format/css/property.lux @@ -1,11 +1,14 @@ (.module: [lux (#- All Cursor) + [control + [parser + ["s" code]]] [type abstract] [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]]] + [syntax (#+ syntax:)]]] [// [value (#+ All Number diff --git a/stdlib/source/lux/data/format/css/query.lux b/stdlib/source/lux/data/format/css/query.lux index 92dea7d19..6e0400ad4 100644 --- a/stdlib/source/lux/data/format/css/query.lux +++ b/stdlib/source/lux/data/format/css/query.lux @@ -1,12 +1,15 @@ (.module: [lux (#- and or not) + [control + [parser + ["s" code]]] [data [text format]] [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [type abstract]] ["." // #_ diff --git a/stdlib/source/lux/data/format/css/value.lux b/stdlib/source/lux/data/format/css/value.lux index 1dae87811..9d34d02f6 100644 --- a/stdlib/source/lux/data/format/css/value.lux +++ b/stdlib/source/lux/data/format/css/value.lux @@ -1,5 +1,8 @@ (.module: [lux (#- All Cursor and static false true) + [control + [parser + ["s" code]]] [data ["." color] ["." product] @@ -15,7 +18,7 @@ [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [world [net (#+ URL)]]] [// diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 417db04b6..1bbdc4ee0 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -8,7 +8,8 @@ [control pipe ["p" parser ("#@." monad) - ["l" text (#+ Parser)]]] + ["l" text (#+ Parser)] + ["s" code]]] [data ["." bit] ["." maybe] @@ -22,7 +23,7 @@ ["." row (#+ Row row) ("#@." monad)] ["." dictionary (#+ Dictionary)]]] ["." macro (#+ monad with-gensyms) - ["s" syntax (#+ syntax:)] + [syntax (#+ syntax:)] ["." code]]]) (template [<name> <type>] diff --git a/stdlib/source/lux/data/lazy.lux b/stdlib/source/lux/data/lazy.lux index 34bdf494f..89b75d3b6 100644 --- a/stdlib/source/lux/data/lazy.lux +++ b/stdlib/source/lux/data/lazy.lux @@ -7,10 +7,12 @@ [equivalence (#+ Equivalence)]] [control ["." io] + [parser + ["s" code]] [concurrency ["." atom]]] [macro (#+ with-gensyms) - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [type abstract]]) diff --git a/stdlib/source/lux/data/number/complex.lux b/stdlib/source/lux/data/number/complex.lux index 6c057ffb1..064a3a847 100644 --- a/stdlib/source/lux/data/number/complex.lux +++ b/stdlib/source/lux/data/number/complex.lux @@ -7,7 +7,8 @@ codec ["M" monad (#+ Monad do)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." maybe] [number @@ -17,7 +18,7 @@ ["." list ("#;." functor)]]] ["." macro ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) (type: #export Complex {#real Frac diff --git a/stdlib/source/lux/data/number/ratio.lux b/stdlib/source/lux/data/number/ratio.lux index e91c9ea97..8af1cf66c 100644 --- a/stdlib/source/lux/data/number/ratio.lux +++ b/stdlib/source/lux/data/number/ratio.lux @@ -9,7 +9,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." error] ["." product] @@ -20,7 +21,7 @@ ["." math] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)]]]) + [syntax (#+ syntax:)]]]) (type: #export Ratio {#numerator Nat diff --git a/stdlib/source/lux/data/text/format.lux b/stdlib/source/lux/data/text/format.lux index a204e567b..3da3fa548 100644 --- a/stdlib/source/lux/data/text/format.lux +++ b/stdlib/source/lux/data/text/format.lux @@ -3,7 +3,8 @@ [abstract [monad (#+ do)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." bit] ["." name] @@ -27,16 +28,14 @@ ["." modular]] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)]] + [syntax (#+ syntax:)]] ["." type]]) -## [Syntax] (syntax: #export (format {fragments (p.many s.any)}) {#.doc (doc "Text interpolation." (format "Static part " (%t static) " does not match URI: " uri))} (wrap (list (` ($_ "lux text concat" (~+ fragments)))))) -## [Formats] (type: #export (Format a) {#.doc "A way to produce readable text from values."} (-> a Text)) diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index b18fdfe0e..a7f778360 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -4,7 +4,8 @@ monad] [control ["p" parser ("#@." monad) - ["l" text (#+ Parser)]]] + ["l" text (#+ Parser)] + ["s" code]]] [data ["." product] ["." error] @@ -15,7 +16,7 @@ ["." list ("#@." fold monad)]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]]] + [syntax (#+ syntax:)]]] ["." // format]) diff --git a/stdlib/source/lux/host.js.lux b/stdlib/source/lux/host.js.lux index aec050642..7fd2a3420 100644 --- a/stdlib/source/lux/host.js.lux +++ b/stdlib/source/lux/host.js.lux @@ -3,13 +3,14 @@ [abstract monad] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data [collection ["." list #* ("#;." fold)]]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) (template [<name> <type>] [(type: #export <name> (#.Primitive <type> #.Nil))] diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index b7775b395..1787f5f45 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -4,9 +4,10 @@ ["." monad (#+ Monad do)] ["." enum]] [control - ["p" parser] ["." function] - ["." io]] + ["." io] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." maybe] ["." product] @@ -22,7 +23,7 @@ ["." type ("#@." equivalence)] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) (template [<name> <class>] [(type: #export <name> (primitive <class>))] @@ -581,24 +582,24 @@ )) (def: (make-get-const-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] _ (s.this (code.identifier ["" dotted-name]))] (wrap (get-static-field class-name field-name)))) (def: (make-get-var-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] _ (s.this (code.identifier ["" dotted-name]))] (wrap (get-virtual-field class-name field-name (' _jvm_this))))) (def: (make-put-var-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] - [_ _ value] (: (Syntax [Any Any Code]) + [_ _ value] (: (Parser [Any Any Code]) (s.form ($_ p.and (s.this (' :=)) (s.this (code.identifier ["" dotted-name])) s.any)))] (wrap (`' ((~ (code.text (format "jvm putfield" ":" class-name ":" field-name))) _jvm_this (~ value)))))) @@ -621,7 +622,7 @@ ast')) (def: (parser->replacer p ast) - (-> (Syntax Code) (-> Code Code)) + (-> (Parser Code) (-> Code Code)) (case (p.run (list ast) p) (#.Right [#.Nil ast']) ast' @@ -631,7 +632,7 @@ )) (def: (field->parser class-name [[field-name _ _] field]) - (-> Text [Member-Declaration FieldDecl] (Syntax Code)) + (-> Text [Member-Declaration FieldDecl] (Parser Code)) (case field (#ConstantField _) (make-get-const-parser class-name field-name) @@ -645,9 +646,9 @@ (` [(~ (code.text class)) (~ value)])) (def: (make-constructor-parser params class-name arg-decls) - (-> (List Type-Paramameter) Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text (List ArgDecl) (Parser Code)) (do p.monad - [args (: (Syntax (List Code)) + [args (: (Parser (List Code)) (s.form (p.after (s.this (' ::new!)) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -657,10 +658,10 @@ (list@map ..decorate-input)))))))) (def: (make-static-method-parser params class-name method-name arg-decls) - (-> (List Type-Paramameter) Text Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text Text (List ArgDecl) (Parser Code)) (do p.monad [#let [dotted-name (format "::" method-name "!")] - args (: (Syntax (List Code)) + args (: (Parser (List Code)) (s.form (p.after (s.this (code.identifier ["" dotted-name])) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -671,10 +672,10 @@ (template [<name> <jvm-op>] [(def: (<name> params class-name method-name arg-decls) - (-> (List Type-Paramameter) Text Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text Text (List ArgDecl) (Parser Code)) (do p.monad [#let [dotted-name (format "::" method-name "!")] - args (: (Syntax (List Code)) + args (: (Parser (List Code)) (s.form (p.after (s.this (code.identifier ["" dotted-name])) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -689,7 +690,7 @@ ) (def: (method->parser params class-name [[method-name _ _] meth-def]) - (-> (List Type-Paramameter) Text [Member-Declaration Method-Definition] (Syntax Code)) + (-> (List Type-Paramameter) Text [Member-Declaration Method-Definition] (Parser Code)) (case meth-def (#ConstructorMethod strict? type-vars args constructor-args return-expr exs) (make-constructor-parser params class-name args) @@ -708,13 +709,13 @@ (make-virtual-method-parser params class-name method-name args))) (def: (full-class-name^ imports) - (-> Class-Imports (Syntax Text)) + (-> Class-Imports (Parser Text)) (do p.monad [name s.local-identifier] (wrap (qualify imports name)))) (def: privacy-modifier^ - (Syntax PrivacyModifier) + (Parser PrivacyModifier) (let [(^open ".") p.monad] ($_ p.or (s.this (' #public)) @@ -723,7 +724,7 @@ (wrap [])))) (def: inheritance-modifier^ - (Syntax InheritanceModifier) + (Parser InheritanceModifier) (let [(^open ".") p.monad] ($_ p.or (s.this (' #final)) @@ -731,17 +732,17 @@ (wrap [])))) (def: bound-kind^ - (Syntax BoundKind) + (Parser BoundKind) (p.or (s.this (' <)) (s.this (' >)))) (def: (assert-no-periods name) - (-> Text (Syntax Any)) + (-> Text (Parser Any)) (p.assert "Names in class declarations cannot contain periods." (not (text.contains? "." name)))) (def: (generic-type^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax GenericType)) + (-> Class-Imports (List Type-Paramameter) (Parser GenericType)) ($_ p.either (do p.monad [_ (s.this (' ?))] @@ -785,7 +786,7 @@ )) (def: (type-param^ imports) - (-> Class-Imports (Syntax Type-Paramameter)) + (-> Class-Imports (Parser Type-Paramameter)) (p.either (do p.monad [param-name s.local-identifier] (wrap [param-name (list)])) @@ -796,11 +797,11 @@ (wrap [param-name bounds]))))) (def: (type-params^ imports) - (-> Class-Imports (Syntax (List Type-Paramameter))) + (-> Class-Imports (Parser (List Type-Paramameter))) (s.tuple (p.some (type-param^ imports)))) (def: (class-decl^ imports) - (-> Class-Imports (Syntax Class-Declaration)) + (-> Class-Imports (Parser Class-Declaration)) (p.either (do p.monad [name (full-class-name^ imports) _ (assert-no-periods name)] @@ -813,7 +814,7 @@ )) (def: (super-class-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax Super-Class-Decl)) + (-> Class-Imports (List Type-Paramameter) (Parser Super-Class-Decl)) (p.either (do p.monad [name (full-class-name^ imports) _ (assert-no-periods name)] @@ -825,11 +826,11 @@ (wrap [name params]))))) (def: annotation-params^ - (Syntax (List AnnotationParam)) + (Parser (List AnnotationParam)) (s.record (p.some (p.and s.local-tag s.any)))) (def: (annotation^ imports) - (-> Class-Imports (Syntax Annotation)) + (-> Class-Imports (Parser Annotation)) (p.either (do p.monad [ann-name (full-class-name^ imports)] (wrap [ann-name (list)])) @@ -837,31 +838,31 @@ annotation-params^)))) (def: (annotations^' imports) - (-> Class-Imports (Syntax (List Annotation))) + (-> Class-Imports (Parser (List Annotation))) (do p.monad [_ (s.this (' #ann))] (s.tuple (p.some (annotation^ imports))))) (def: (annotations^ imports) - (-> Class-Imports (Syntax (List Annotation))) + (-> Class-Imports (Parser (List Annotation))) (do p.monad [anns?? (p.maybe (annotations^' imports))] (wrap (maybe.default (list) anns??)))) (def: (throws-decl'^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List GenericType))) + (-> Class-Imports (List Type-Paramameter) (Parser (List GenericType))) (do p.monad [_ (s.this (' #throws))] (s.tuple (p.some (generic-type^ imports type-vars))))) (def: (throws-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List GenericType))) + (-> Class-Imports (List Type-Paramameter) (Parser (List GenericType))) (do p.monad [exs? (p.maybe (throws-decl'^ imports type-vars))] (wrap (maybe.default (list) exs?)))) (def: (method-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration MethodDecl])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration MethodDecl])) (s.form (do p.monad [tvars (p.default (list) (type-params^ imports)) name s.local-identifier @@ -875,14 +876,14 @@ #method-exs exs}])))) (def: state-modifier^ - (Syntax StateModifier) + (Parser StateModifier) ($_ p.or (s.this (' #volatile)) (s.this (' #final)) (:: p.monad wrap []))) (def: (field-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration FieldDecl])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration FieldDecl])) (p.either (s.form (do p.monad [_ (s.this (' #const)) name s.local-identifier @@ -899,24 +900,24 @@ (wrap [[name pm anns] (#VariableField [sm type])]))))) (def: (arg-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax ArgDecl)) + (-> Class-Imports (List Type-Paramameter) (Parser ArgDecl)) (s.record (p.and s.local-identifier (generic-type^ imports type-vars)))) (def: (arg-decls^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List ArgDecl))) + (-> Class-Imports (List Type-Paramameter) (Parser (List ArgDecl))) (p.some (arg-decl^ imports type-vars))) (def: (constructor-arg^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax ConstructorArg)) + (-> Class-Imports (List Type-Paramameter) (Parser ConstructorArg)) (s.record (p.and (generic-type^ imports type-vars) s.any))) (def: (constructor-args^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List ConstructorArg))) + (-> Class-Imports (List Type-Paramameter) (Parser (List ConstructorArg))) (s.tuple (p.some (constructor-arg^ imports type-vars)))) (def: (constructor-method^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -934,7 +935,7 @@ (#ConstructorMethod strict-fp? method-vars arg-decls constructor-args body exs)])))) (def: (virtual-method-def^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -953,7 +954,7 @@ (#VirtualMethod final? strict-fp? method-vars arg-decls return-type body exs)])))) (def: (overriden-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [strict-fp? (s.this? (' #strict)) owner-class (class-decl^ imports) @@ -971,7 +972,7 @@ (#OverridenMethod strict-fp? owner-class method-vars arg-decls return-type body exs)])))) (def: (static-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -990,7 +991,7 @@ (#StaticMethod strict-fp? method-vars arg-decls return-type body exs)])))) (def: (abstract-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ _ (s.this (' #abstract)) @@ -1007,7 +1008,7 @@ (#AbstractMethod method-vars arg-decls return-type exs)])))) (def: (native-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ _ (s.this (' #native)) @@ -1024,7 +1025,7 @@ (#NativeMethod method-vars arg-decls return-type exs)])))) (def: (method-def^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) ($_ p.either (constructor-method^ imports class-vars) (virtual-method-def^ imports class-vars) @@ -1034,11 +1035,11 @@ (native-method-def^ imports))) (def: partial-call^ - (Syntax Partial-Call) + (Parser Partial-Call) (s.form (p.and s.identifier (p.some s.any)))) (def: class-kind^ - (Syntax Class-Kind) + (Parser Class-Kind) (p.either (do p.monad [_ (s.this (' #class))] (wrap #Class)) @@ -1048,26 +1049,26 @@ )) (def: import-member-alias^ - (Syntax (Maybe Text)) + (Parser (Maybe Text)) (p.maybe (do p.monad [_ (s.this (' #as))] s.local-identifier))) (def: (import-member-args^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List [Bit GenericType]))) + (-> Class-Imports (List Type-Paramameter) (Parser (List [Bit GenericType]))) (s.tuple (p.some (p.and (s.this? (' #?)) (generic-type^ imports type-vars))))) (def: import-member-return-flags^ - (Syntax [Bit Bit Bit]) + (Parser [Bit Bit Bit]) ($_ p.and (s.this? (' #io)) (s.this? (' #try)) (s.this? (' #?)))) (def: primitive-mode^ - (Syntax Primitive-Mode) + (Parser Primitive-Mode) (p.or (s.this (' #manual)) (s.this (' #auto)))) (def: (import-member-decl^ imports owner-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax Import-Member-Declaration)) + (-> Class-Imports (List Type-Paramameter) (Parser Import-Member-Declaration)) ($_ p.either (s.form (do p.monad [_ (s.this (' #enum)) @@ -1092,7 +1093,7 @@ {}])) )) (s.form (do p.monad - [kind (: (Syntax ImportMethodKind) + [kind (: (Parser ImportMethodKind) (p.or (s.this (' #static)) (wrap []))) tvars (p.default (list) (type-params^ imports)) diff --git a/stdlib/source/lux/host.old.lux b/stdlib/source/lux/host.old.lux index 8785cb7ca..939e82310 100644 --- a/stdlib/source/lux/host.old.lux +++ b/stdlib/source/lux/host.old.lux @@ -4,9 +4,10 @@ ["." monad (#+ Monad do)] ["." enum]] [control - ["p" parser] ["." function] - ["." io]] + ["." io] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." maybe] ["." product] @@ -21,7 +22,7 @@ ["." type ("#@." equivalence)] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) (template [<name> <op> <from> <to>] [(def: #export (<name> value) @@ -515,24 +516,24 @@ )) (def: (make-get-const-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] _ (s.this (code.identifier ["" dotted-name]))] (wrap (`' ((~ (code.text (format "jvm getstatic" ":" class-name ":" field-name)))))))) (def: (make-get-var-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] _ (s.this (code.identifier ["" dotted-name]))] (wrap (`' ((~ (code.text (format "jvm getfield" ":" class-name ":" field-name))) _jvm_this))))) (def: (make-put-var-parser class-name field-name) - (-> Text Text (Syntax Code)) + (-> Text Text (Parser Code)) (do p.monad [#let [dotted-name (format "::" field-name)] - [_ _ value] (: (Syntax [Any Any Code]) + [_ _ value] (: (Parser [Any Any Code]) (s.form ($_ p.and (s.this (' :=)) (s.this (code.identifier ["" dotted-name])) s.any)))] (wrap (`' ((~ (code.text (format "jvm putfield" ":" class-name ":" field-name))) _jvm_this (~ value)))))) @@ -555,7 +556,7 @@ ast')) (def: (parser->replacer p ast) - (-> (Syntax Code) (-> Code Code)) + (-> (Parser Code) (-> Code Code)) (case (p.run (list ast) p) (#.Right [#.Nil ast']) ast' @@ -565,7 +566,7 @@ )) (def: (field->parser class-name [[field-name _ _] field]) - (-> Text [Member-Declaration FieldDecl] (Syntax Code)) + (-> Text [Member-Declaration FieldDecl] (Parser Code)) (case field (#ConstantField _) (make-get-const-parser class-name field-name) @@ -575,9 +576,9 @@ (make-put-var-parser class-name field-name)))) (def: (make-constructor-parser params class-name arg-decls) - (-> (List Type-Paramameter) Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text (List ArgDecl) (Parser Code)) (do p.monad - [args (: (Syntax (List Code)) + [args (: (Parser (List Code)) (s.form (p.after (s.this (' ::new!)) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -585,10 +586,10 @@ (~+ args)))))) (def: (make-static-method-parser params class-name method-name arg-decls) - (-> (List Type-Paramameter) Text Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text Text (List ArgDecl) (Parser Code)) (do p.monad [#let [dotted-name (format "::" method-name "!")] - args (: (Syntax (List Code)) + args (: (Parser (List Code)) (s.form (p.after (s.this (code.identifier ["" dotted-name])) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -597,10 +598,10 @@ (template [<name> <jvm-op>] [(def: (<name> params class-name method-name arg-decls) - (-> (List Type-Paramameter) Text Text (List ArgDecl) (Syntax Code)) + (-> (List Type-Paramameter) Text Text (List ArgDecl) (Parser Code)) (do p.monad [#let [dotted-name (format "::" method-name "!")] - args (: (Syntax (List Code)) + args (: (Parser (List Code)) (s.form (p.after (s.this (code.identifier ["" dotted-name])) (s.tuple (p.exactly (list.size arg-decls) s.any))))) #let [arg-decls' (: (List Text) (list@map (|>> product.right (simple-class$ params)) arg-decls))]] @@ -612,7 +613,7 @@ ) (def: (method->parser params class-name [[method-name _ _] meth-def]) - (-> (List Type-Paramameter) Text [Member-Declaration Method-Definition] (Syntax Code)) + (-> (List Type-Paramameter) Text [Member-Declaration Method-Definition] (Parser Code)) (case meth-def (#ConstructorMethod strict? type-vars args constructor-args return-expr exs) (make-constructor-parser params class-name args) @@ -630,15 +631,15 @@ (#NativeMethod type-vars args return-type exs) (make-virtual-method-parser params class-name method-name args))) -## Syntaxes +## Parsers (def: (full-class-name^ imports) - (-> Class-Imports (Syntax Text)) + (-> Class-Imports (Parser Text)) (do p.monad [name s.local-identifier] (wrap (qualify imports name)))) (def: privacy-modifier^ - (Syntax PrivacyModifier) + (Parser PrivacyModifier) (let [(^open ".") p.monad] ($_ p.or (s.this (' #public)) @@ -647,7 +648,7 @@ (wrap [])))) (def: inheritance-modifier^ - (Syntax InheritanceModifier) + (Parser InheritanceModifier) (let [(^open ".") p.monad] ($_ p.or (s.this (' #final)) @@ -655,17 +656,17 @@ (wrap [])))) (def: bound-kind^ - (Syntax BoundKind) + (Parser BoundKind) (p.or (s.this (' <)) (s.this (' >)))) (def: (assert-no-periods name) - (-> Text (Syntax Any)) + (-> Text (Parser Any)) (p.assert "Names in class declarations cannot contain periods." (not (text.contains? "." name)))) (def: (generic-type^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax GenericType)) + (-> Class-Imports (List Type-Paramameter) (Parser GenericType)) ($_ p.either (do p.monad [_ (s.this (' ?))] @@ -709,7 +710,7 @@ )) (def: (type-param^ imports) - (-> Class-Imports (Syntax Type-Paramameter)) + (-> Class-Imports (Parser Type-Paramameter)) (p.either (do p.monad [param-name s.local-identifier] (wrap [param-name (list)])) @@ -720,11 +721,11 @@ (wrap [param-name bounds]))))) (def: (type-params^ imports) - (-> Class-Imports (Syntax (List Type-Paramameter))) + (-> Class-Imports (Parser (List Type-Paramameter))) (s.tuple (p.some (type-param^ imports)))) (def: (class-decl^ imports) - (-> Class-Imports (Syntax Class-Declaration)) + (-> Class-Imports (Parser Class-Declaration)) (p.either (do p.monad [name (full-class-name^ imports) _ (assert-no-periods name)] @@ -737,7 +738,7 @@ )) (def: (super-class-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax Super-Class-Decl)) + (-> Class-Imports (List Type-Paramameter) (Parser Super-Class-Decl)) (p.either (do p.monad [name (full-class-name^ imports) _ (assert-no-periods name)] @@ -749,11 +750,11 @@ (wrap [name params]))))) (def: annotation-params^ - (Syntax (List AnnotationParam)) + (Parser (List AnnotationParam)) (s.record (p.some (p.and s.local-tag s.any)))) (def: (annotation^ imports) - (-> Class-Imports (Syntax Annotation)) + (-> Class-Imports (Parser Annotation)) (p.either (do p.monad [ann-name (full-class-name^ imports)] (wrap [ann-name (list)])) @@ -761,31 +762,31 @@ annotation-params^)))) (def: (annotations^' imports) - (-> Class-Imports (Syntax (List Annotation))) + (-> Class-Imports (Parser (List Annotation))) (do p.monad [_ (s.this (' #ann))] (s.tuple (p.some (annotation^ imports))))) (def: (annotations^ imports) - (-> Class-Imports (Syntax (List Annotation))) + (-> Class-Imports (Parser (List Annotation))) (do p.monad [anns?? (p.maybe (annotations^' imports))] (wrap (maybe.default (list) anns??)))) (def: (throws-decl'^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List GenericType))) + (-> Class-Imports (List Type-Paramameter) (Parser (List GenericType))) (do p.monad [_ (s.this (' #throws))] (s.tuple (p.some (generic-type^ imports type-vars))))) (def: (throws-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List GenericType))) + (-> Class-Imports (List Type-Paramameter) (Parser (List GenericType))) (do p.monad [exs? (p.maybe (throws-decl'^ imports type-vars))] (wrap (maybe.default (list) exs?)))) (def: (method-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration MethodDecl])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration MethodDecl])) (s.form (do p.monad [tvars (p.default (list) (type-params^ imports)) name s.local-identifier @@ -799,14 +800,14 @@ #method-exs exs}])))) (def: state-modifier^ - (Syntax StateModifier) + (Parser StateModifier) ($_ p.or (s.this (' #volatile)) (s.this (' #final)) (:: p.monad wrap []))) (def: (field-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration FieldDecl])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration FieldDecl])) (p.either (s.form (do p.monad [_ (s.this (' #const)) name s.local-identifier @@ -823,24 +824,24 @@ (wrap [[name pm anns] (#VariableField [sm type])]))))) (def: (arg-decl^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax ArgDecl)) + (-> Class-Imports (List Type-Paramameter) (Parser ArgDecl)) (s.record (p.and s.local-identifier (generic-type^ imports type-vars)))) (def: (arg-decls^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List ArgDecl))) + (-> Class-Imports (List Type-Paramameter) (Parser (List ArgDecl))) (p.some (arg-decl^ imports type-vars))) (def: (constructor-arg^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax ConstructorArg)) + (-> Class-Imports (List Type-Paramameter) (Parser ConstructorArg)) (s.record (p.and (generic-type^ imports type-vars) s.any))) (def: (constructor-args^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List ConstructorArg))) + (-> Class-Imports (List Type-Paramameter) (Parser (List ConstructorArg))) (s.tuple (p.some (constructor-arg^ imports type-vars)))) (def: (constructor-method^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -858,7 +859,7 @@ (#ConstructorMethod strict-fp? method-vars arg-decls constructor-args body exs)])))) (def: (virtual-method-def^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -877,7 +878,7 @@ (#VirtualMethod final? strict-fp? method-vars arg-decls return-type body exs)])))) (def: (overriden-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [strict-fp? (s.this? (' #strict)) owner-class (class-decl^ imports) @@ -895,7 +896,7 @@ (#OverridenMethod strict-fp? owner-class method-vars arg-decls return-type body exs)])))) (def: (static-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ strict-fp? (s.this? (' #strict)) @@ -914,7 +915,7 @@ (#StaticMethod strict-fp? method-vars arg-decls return-type body exs)])))) (def: (abstract-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ _ (s.this (' #abstract)) @@ -931,7 +932,7 @@ (#AbstractMethod method-vars arg-decls return-type exs)])))) (def: (native-method-def^ imports) - (-> Class-Imports (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (Parser [Member-Declaration Method-Definition])) (s.form (do p.monad [pm privacy-modifier^ _ (s.this (' #native)) @@ -948,7 +949,7 @@ (#NativeMethod method-vars arg-decls return-type exs)])))) (def: (method-def^ imports class-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax [Member-Declaration Method-Definition])) + (-> Class-Imports (List Type-Paramameter) (Parser [Member-Declaration Method-Definition])) ($_ p.either (constructor-method^ imports class-vars) (virtual-method-def^ imports class-vars) @@ -958,11 +959,11 @@ (native-method-def^ imports))) (def: partial-call^ - (Syntax Partial-Call) + (Parser Partial-Call) (s.form (p.and s.identifier (p.some s.any)))) (def: class-kind^ - (Syntax Class-Kind) + (Parser Class-Kind) (p.either (do p.monad [_ (s.this (' #class))] (wrap #Class)) @@ -972,26 +973,26 @@ )) (def: import-member-alias^ - (Syntax (Maybe Text)) + (Parser (Maybe Text)) (p.maybe (do p.monad [_ (s.this (' #as))] s.local-identifier))) (def: (import-member-args^ imports type-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax (List [Bit GenericType]))) + (-> Class-Imports (List Type-Paramameter) (Parser (List [Bit GenericType]))) (s.tuple (p.some (p.and (s.this? (' #?)) (generic-type^ imports type-vars))))) (def: import-member-return-flags^ - (Syntax [Bit Bit Bit]) + (Parser [Bit Bit Bit]) ($_ p.and (s.this? (' #io)) (s.this? (' #try)) (s.this? (' #?)))) (def: primitive-mode^ - (Syntax Primitive-Mode) + (Parser Primitive-Mode) (p.or (s.this (' #manual)) (s.this (' #auto)))) (def: (import-member-decl^ imports owner-vars) - (-> Class-Imports (List Type-Paramameter) (Syntax Import-Member-Declaration)) + (-> Class-Imports (List Type-Paramameter) (Parser Import-Member-Declaration)) ($_ p.either (s.form (do p.monad [_ (s.this (' #enum)) @@ -1016,7 +1017,7 @@ {}])) )) (s.form (do p.monad - [kind (: (Syntax ImportMethodKind) + [kind (: (Parser ImportMethodKind) (p.or (s.this (' #static)) (wrap []))) tvars (p.default (list) (type-params^ imports)) diff --git a/stdlib/source/lux/host/jvm/modifier.lux b/stdlib/source/lux/host/jvm/modifier.lux index ac8d1b201..f858e6548 100644 --- a/stdlib/source/lux/host/jvm/modifier.lux +++ b/stdlib/source/lux/host/jvm/modifier.lux @@ -4,7 +4,8 @@ ["." equivalence] ["." monoid]] [control - ["." parser]] + ["." parser + ["s" code (#+ Parser)]]] [data ["." number ["." i64]] @@ -16,7 +17,7 @@ ["." abstract]] [macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ Syntax syntax:)]]] + [syntax (#+ syntax:)]]] ["." // #_ ["#." encoding]]) @@ -25,7 +26,7 @@ #name Text}) (def: modifier - (Syntax Modifier) + (Parser Modifier) (s.tuple (parser.and s.text s.local-identifier))) diff --git a/stdlib/source/lux/host/lua.lux b/stdlib/source/lux/host/lua.lux index ca72f1678..8dde357cc 100644 --- a/stdlib/source/lux/host/lua.lux +++ b/stdlib/source/lux/host/lua.lux @@ -1,7 +1,9 @@ (.module: [lux (#- Code int if cond function or and not let) [control - [pipe (#+ case> cond> new>)]] + [pipe (#+ case> cond> new>)] + [parser + ["s" code]]] [data [number ["." frac]] @@ -12,7 +14,7 @@ [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [type abstract]]) diff --git a/stdlib/source/lux/host/python.lux b/stdlib/source/lux/host/python.lux index d2fe7f9c7..80f6b12de 100644 --- a/stdlib/source/lux/host/python.lux +++ b/stdlib/source/lux/host/python.lux @@ -1,7 +1,9 @@ (.module: [lux (#- Code not or and list if cond int comment) [control - [pipe (#+ new> case> cond>)]] + [pipe (#+ new> case> cond>)] + [parser + ["s" code]]] [data [number ["." frac]] @@ -12,7 +14,7 @@ [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [type abstract]]) diff --git a/stdlib/source/lux/host/ruby.lux b/stdlib/source/lux/host/ruby.lux index 8f54bbdeb..e52fb6f37 100644 --- a/stdlib/source/lux/host/ruby.lux +++ b/stdlib/source/lux/host/ruby.lux @@ -1,7 +1,9 @@ (.module: [lux (#- Code static int if cond function or and not comment) [control - [pipe (#+ case> cond> new>)]] + [pipe (#+ case> cond> new>)] + [parser + ["s" code]]] [data [number ["." frac]] @@ -12,7 +14,7 @@ [macro ["." template] ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [type abstract]]) diff --git a/stdlib/source/lux/macro/poly.lux b/stdlib/source/lux/macro/poly.lux index 695284e0a..825849cce 100644 --- a/stdlib/source/lux/macro/poly.lux +++ b/stdlib/source/lux/macro/poly.lux @@ -4,7 +4,8 @@ ["." monad (#+ do)]] [control ["p" parser - ["<.>" type (#+ Env)]]] + ["<.>" type (#+ Env)] + ["s" code]]] [data ["." product] ["." maybe] @@ -14,7 +15,7 @@ ["." dictionary]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:) + [syntax (#+ syntax:) [common ["csr" reader] ["csw" writer]]]] diff --git a/stdlib/source/lux/macro/poly/equivalence.lux b/stdlib/source/lux/macro/poly/equivalence.lux index b9bb1f335..fc1e579a2 100644 --- a/stdlib/source/lux/macro/poly/equivalence.lux +++ b/stdlib/source/lux/macro/poly/equivalence.lux @@ -5,7 +5,8 @@ ["/" equivalence]] [control ["p" parser - ["<.>" type]]] + ["<.>" type] + ["s" code (#+ Parser)]]] [data ["." product] ["." bit] @@ -33,7 +34,7 @@ ["." month]] ["." macro ["." code] - [syntax (#+ syntax: Syntax) + [syntax (#+ syntax:) ["." common]] ["." poly (#+ poly:)]] ["." type diff --git a/stdlib/source/lux/macro/poly/functor.lux b/stdlib/source/lux/macro/poly/functor.lux index 4ae02b8a3..0de5009fd 100644 --- a/stdlib/source/lux/macro/poly/functor.lux +++ b/stdlib/source/lux/macro/poly/functor.lux @@ -5,7 +5,8 @@ ["." functor]] [control ["p" parser - ["<.>" type]]] + ["<.>" type] + ["s" code (#+ Parser)]]] [data ["." product] ["." text @@ -14,7 +15,7 @@ ["." list ("#;." monad monoid)]]] ["." macro ["." code] - [syntax (#+ syntax: Syntax) + [syntax (#+ syntax:) ["." common]] ["." poly (#+ poly:)]] ["." type]]) diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index f30c26437..a967b4097 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -8,7 +8,8 @@ ["p" parser ["<.>" type] ["</>" json] - ["l" text]]] + ["l" text] + ["s" code]]] [data ["." bit] maybe @@ -34,7 +35,7 @@ ["." day] ["." month]] [macro (#+ with-gensyms) - ["s" syntax (#+ syntax:)] + [syntax (#+ syntax:)] ["." code] ["." poly (#+ poly:)]] ["." type diff --git a/stdlib/source/lux/macro/syntax.lux b/stdlib/source/lux/macro/syntax.lux index bd5372618..52966ea0d 100644 --- a/stdlib/source/lux/macro/syntax.lux +++ b/stdlib/source/lux/macro/syntax.lux @@ -1,13 +1,11 @@ (.module: - [lux (#- nat int rev) + [lux #* [abstract - [equivalence (#+ Equivalence)] - ["." monad (#+ Monad do)]] + ["." monad (#+ do)]] [control - ["p" parser]] + ["<>" parser + ["</>" code]]] [data - ["." bit] - ["." name] ["." maybe] ["." error (#+ Error)] [number @@ -19,7 +17,7 @@ [collection ["." list ("#@." functor)]]]] ["." // (#+ with-gensyms) - ["." code ("#@." equivalence)]]) + ["." code]]) (def: (join-pairs pairs) (All [a] (-> (List [a a]) (List a))) @@ -27,174 +25,6 @@ #.Nil #.Nil (#.Cons [[x y] pairs']) (list& x y (join-pairs pairs')))) -(type: #export Syntax - {#.doc "A Lux syntax parser."} - (p.Parser (List Code))) - -(def: (remaining-inputs asts) - (-> (List Code) Text) - ($_ text@compose text.new-line "Remaining input: " - (|> asts (list@map code.to-text) (list.interpose " ") (text.join-with "")))) - -(def: #export any - {#.doc "Just returns the next input without applying any logic."} - (Syntax Code) - (function (_ tokens) - (case tokens - #.Nil (#error.Failure "There are no tokens to parse!") - (#.Cons [t tokens']) (#error.Success [tokens' t])))) - -(template [<get-name> <type> <tag> <eq> <desc>] - [(def: #export <get-name> - {#.doc (code.text ($_ text@compose "Parses the next " <desc> " input Code."))} - (Syntax <type>) - (function (_ tokens) - (case tokens - (#.Cons [[_ (<tag> x)] tokens']) - (#error.Success [tokens' x]) - - _ - (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))] - - [ bit Bit #.Bit bit.equivalence "bit"] - [ nat Nat #.Nat nat.equivalence "nat"] - [ int Int #.Int int.equivalence "int"] - [ rev Rev #.Rev rev.equivalence "rev"] - [ frac Frac #.Frac frac.equivalence "frac"] - [ text Text #.Text text.equivalence "text"] - [identifier Name #.Identifier name.equivalence "identifier"] - [ tag Name #.Tag name.equivalence "tag"] - ) - -(def: #export (this? ast) - {#.doc "Asks if the given Code is the next input."} - (-> Code (Syntax Bit)) - (function (_ tokens) - (case tokens - (#.Cons [token tokens']) - (let [is-it? (code@= ast token) - remaining (if is-it? - tokens' - tokens)] - (#error.Success [remaining is-it?])) - - _ - (#error.Success [tokens #0])))) - -(def: #export (this ast) - {#.doc "Ensures the given Code is the next input."} - (-> Code (Syntax Any)) - (function (_ tokens) - (case tokens - (#.Cons [token tokens']) - (if (code@= ast token) - (#error.Success [tokens' []]) - (#error.Failure ($_ text@compose "Expected a " (code.to-text ast) " but instead got " (code.to-text token) - (remaining-inputs tokens)))) - - _ - (#error.Failure "There are no tokens to parse!")))) - -(template [<name> <tag> <desc>] - [(def: #export <name> - {#.doc (code.text ($_ text@compose "Parse a local " <desc> " (a " <desc> " that has no module prefix)."))} - (Syntax Text) - (function (_ tokens) - (case tokens - (#.Cons [[_ (<tag> ["" x])] tokens']) - (#error.Success [tokens' x]) - - _ - (#error.Failure ($_ text@compose "Cannot parse local " <desc> (remaining-inputs tokens))))))] - - [local-identifier #.Identifier "identifier"] - [ local-tag #.Tag "tag"] - ) - -(template [<name> <tag> <desc>] - [(def: #export (<name> p) - {#.doc (code.text ($_ text@compose "Parse inside the contents of a " <desc> " as if they were the input Codes."))} - (All [a] - (-> (Syntax a) (Syntax a))) - (function (_ tokens) - (case tokens - (#.Cons [[_ (<tag> members)] tokens']) - (case (p members) - (#error.Success [#.Nil x]) (#error.Success [tokens' x]) - _ (#error.Failure ($_ text@compose "Syntax was expected to fully consume " <desc> (remaining-inputs tokens)))) - - _ - (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))] - - [ form #.Form "form"] - [tuple #.Tuple "tuple"] - ) - -(def: #export (record p) - {#.doc (code.text ($_ text@compose "Parse inside the contents of a record as if they were the input Codes."))} - (All [a] - (-> (Syntax a) (Syntax a))) - (function (_ tokens) - (case tokens - (#.Cons [[_ (#.Record pairs)] tokens']) - (case (p (join-pairs pairs)) - (#error.Success [#.Nil x]) (#error.Success [tokens' x]) - _ (#error.Failure ($_ text@compose "Syntax was expected to fully consume record" (remaining-inputs tokens)))) - - _ - (#error.Failure ($_ text@compose "Cannot parse record" (remaining-inputs tokens)))))) - -(def: #export end! - {#.doc "Ensures there are no more inputs."} - (Syntax Any) - (function (_ tokens) - (case tokens - #.Nil (#error.Success [tokens []]) - _ (#error.Failure ($_ text@compose "Expected list of tokens to be empty!" (remaining-inputs tokens)))))) - -(def: #export end? - {#.doc "Checks whether there are no more inputs."} - (Syntax Bit) - (function (_ tokens) - (case tokens - #.Nil (#error.Success [tokens #1]) - _ (#error.Success [tokens #0])))) - -(def: #export (lift outcome) - (All [a] (-> (Error a) (Syntax a))) - (function (_ input) - (case outcome - (#error.Failure error) - (#error.Failure error) - - (#error.Success value) - (#error.Success [input value]) - ))) - -(def: #export (run inputs syntax) - (All [a] (-> (List Code) (Syntax a) (Error a))) - (case (syntax inputs) - (#error.Failure error) - (#error.Failure error) - - (#error.Success [unconsumed value]) - (case unconsumed - #.Nil - (#error.Success value) - - _ - (#error.Failure (text@compose "Unconsumed inputs: " - (|> (list@map code.to-text unconsumed) - (text.join-with ", "))))))) - -(def: #export (local inputs syntax) - {#.doc "Run a syntax parser with the given list of inputs, instead of the real ones."} - (All [a] (-> (List Code) (Syntax a) (Syntax a))) - (function (_ real) - (do error.monad - [value (run inputs syntax)] - (wrap [real value])))) - (macro: #export (syntax: tokens) {#.doc (doc "A more advanced way to define macros than 'macro:'." "The inputs to the macro can be parsed in complex ways through the use of syntax parsers." @@ -244,7 +74,7 @@ (wrap [var parser]) [_ (#.Identifier var-name)] - (wrap [(code.identifier var-name) (` (~! any))]) + (wrap [(code.identifier var-name) (` (~! </>.any))]) _ (//.fail "Syntax pattern expects records or identifiers.")))) @@ -263,9 +93,9 @@ (#.Left (~ g!error)) (#.Left ((~! text.join-with) ": " (list (~ error-msg) (~ g!error))))} - ((~! ..run) (~ g!tokens) - (: ((~! ..Syntax) (Meta (List Code))) - ((~! do) (~! p.monad) + ((~! </>.run) (~ g!tokens) + (: ((~! </>.Parser) (Meta (List Code))) + ((~! do) (~! <>.monad) [(~+ (join-pairs vars+parsers))] ((~' wrap) ((~! do) (~! //.monad) [] diff --git a/stdlib/source/lux/macro/syntax/common/reader.lux b/stdlib/source/lux/macro/syntax/common/reader.lux index 7f66a3879..069bf1cf0 100644 --- a/stdlib/source/lux/macro/syntax/common/reader.lux +++ b/stdlib/source/lux/macro/syntax/common/reader.lux @@ -3,7 +3,8 @@ [abstract monad] [control - ["p" parser ("#@." monad)]] + ["p" parser ("#@." monad) + ["s" code (#+ Parser)]]] [data ["." name ("#@." equivalence)] ["." product] @@ -12,35 +13,31 @@ ["." list]]]] ["." // ["#//" /// - ["s" syntax (#+ syntax: Syntax)]]]) + [syntax (#+ syntax:)]]]) -## Exports (def: #export export - (Syntax Bit) + (Parser Bit) (p.either (p.after (s.this (' #export)) (p@wrap #1)) (p@wrap #0))) -## Declarations (def: #export declaration {#.doc (doc "A reader for declaration syntax." "Such as:" quux (foo bar baz))} - (Syntax //.Declaration) + (Parser //.Declaration) (p.either (p.and s.local-identifier (p@wrap (list))) (s.form (p.and s.local-identifier (p.some s.local-identifier))))) -## Annotations (def: #export annotations {#.doc "Reader for the common annotations syntax used by def: statements."} - (Syntax //.Annotations) + (Parser //.Annotations) (s.record (p.some (p.and s.tag s.any)))) -## Definitions (def: check^ - (Syntax [(Maybe Code) Code]) + (Parser [(Maybe Code) Code]) (p.either (s.form (do p.monad [_ (s.this (' "lux check")) type s.any @@ -50,11 +47,11 @@ s.any))) (def: _definition-anns-tag^ - (Syntax Name) + (Parser Name) (s.tuple (p.and s.text s.text))) (def: (_definition-anns^ _) - (-> Any (Syntax //.Annotations)) + (-> Any (Parser //.Annotations)) (p.or (s.this (' #.Nil)) (s.form (do p.monad [_ (s.this (' #.Cons)) @@ -64,7 +61,7 @@ )) (def: (flat-list^ _) - (-> Any (Syntax (List Code))) + (-> Any (Parser (List Code))) (p.either (do p.monad [_ (s.this (' #.Nil))] (wrap (list))) @@ -76,7 +73,7 @@ (template [<name> <type> <tag> <then>] [(def: <name> - (Syntax <type>) + (Parser <type>) (<| s.tuple (p.after s.any) s.form @@ -105,7 +102,7 @@ (def: #export (definition compiler) {#.doc "A reader that first macro-expands and then analyses the input Code, to ensure it's a definition."} - (-> Lux (Syntax //.Definition)) + (-> Lux (Parser //.Definition)) (do p.monad [definition-raw s.any me-definition-raw (|> definition-raw @@ -129,7 +126,7 @@ (def: #export (typed-definition compiler) {#.doc "A reader for definitions that ensures the input syntax is typed."} - (-> Lux (Syntax //.Definition)) + (-> Lux (Parser //.Definition)) (do p.monad [_definition (definition compiler) _ (case (get@ #//.definition-type _definition) @@ -142,10 +139,10 @@ (def: #export typed-input {#.doc "Reader for the common typed-argument syntax used by many macros."} - (Syntax //.Typed-Input) + (Parser //.Typed-Input) (s.record (p.and s.any s.any))) (def: #export type-variables {#.doc "Reader for the common type var/param used by many macros."} - (Syntax (List Text)) + (Parser (List Text)) (s.tuple (p.some s.local-identifier))) diff --git a/stdlib/source/lux/macro/template.lux b/stdlib/source/lux/macro/template.lux index 55000aa31..5c163aabd 100644 --- a/stdlib/source/lux/macro/template.lux +++ b/stdlib/source/lux/macro/template.lux @@ -3,7 +3,8 @@ [abstract ["." monad (#+ do)]] [control - ["p" parser ("#@." functor)]] + ["p" parser ("#@." functor) + ["s" code (#+ Parser)]]] [data ["." bit ("#@." codec)] ["." text] @@ -16,7 +17,7 @@ ["." list ("#@." monad)]]]] ["." // ["." code] - ["s" syntax (#+ Syntax syntax:)]]) + [syntax (#+ syntax:)]]) (syntax: #export (splice {parts (s.tuple (p.some s.any))}) (wrap parts)) @@ -34,7 +35,7 @@ (~ body))))))) (def: snippet - (Syntax Text) + (Parser Text) ($_ p.either s.text s.local-identifier @@ -47,7 +48,7 @@ )) (def: part - (Syntax (List Text)) + (Parser (List Text)) (s.tuple (p.many ..snippet))) (syntax: #export (text {simple ..part}) diff --git a/stdlib/source/lux/math/infix.lux b/stdlib/source/lux/math/infix.lux index ecb309d13..051ef9929 100644 --- a/stdlib/source/lux/math/infix.lux +++ b/stdlib/source/lux/math/infix.lux @@ -3,13 +3,14 @@ [abstract monad] [control - ["p" parser ("#;." functor)]] + ["p" parser ("#;." functor) + ["s" code (#+ Parser)]]] [data ["." product] [collection ["." list ("#;." fold)]]] [macro - ["s" syntax (#+ syntax: Syntax)] + [syntax (#+ syntax:)] ["." code]]]) (type: #rec Infix @@ -19,7 +20,7 @@ (#Binary Infix Code Infix)) (def: infix^ - (Syntax Infix) + (Parser Infix) (<| p.rec (function (_ infix^)) ($_ p.or ($_ p.either diff --git a/stdlib/source/lux/math/modular.lux b/stdlib/source/lux/math/modular.lux index a6b905360..76c85ec1b 100644 --- a/stdlib/source/lux/math/modular.lux +++ b/stdlib/source/lux/math/modular.lux @@ -6,7 +6,8 @@ [control ["ex" exception (#+ exception:)] ["p" parser - ["l" text (#+ Parser)]]] + ["l" text (#+ Parser)] + ["s" code]]] [data ["." error (#+ Error)] [number @@ -16,7 +17,7 @@ abstract] [macro ["." code] - ["s" syntax (#+ syntax:)]]]) + [syntax (#+ syntax:)]]]) (exception: #export zero-cannot-be-a-modulus) diff --git a/stdlib/source/lux/tool/compiler/phase.lux b/stdlib/source/lux/tool/compiler/phase.lux index 2590b7048..a6b080a19 100644 --- a/stdlib/source/lux/tool/compiler/phase.lux +++ b/stdlib/source/lux/tool/compiler/phase.lux @@ -5,7 +5,9 @@ [control ["." state] ["ex" exception (#+ Exception exception:)] - ["." io]] + ["." io] + [parser + ["s" code]]] [data ["." product] ["." error (#+ Error) ("#;." functor)] @@ -15,7 +17,7 @@ ["." instant] ["." duration]] [macro - ["s" syntax (#+ syntax:)]]]) + [syntax (#+ syntax:)]]]) (type: #export (Operation s o) (state.State' Error s o)) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux index 998590d1c..14a77c65c 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux @@ -3,7 +3,8 @@ [abstract ["." monad (#+ do)]] [control - ["p" parser] + ["p" parser + ["s" code (#+ Parser)]] ["." exception (#+ exception:)] pipe] [data @@ -18,8 +19,7 @@ ["." dictionary (#+ Dictionary)]]] ["." type ["." check]] - ["." macro - ["s" syntax (#+ Syntax)]] + ["." macro] ["." host (#+ import:)]] ["." // #_ ["#." common] @@ -35,7 +35,7 @@ (def: (custom [syntax handler]) (All [s] - (-> [(Syntax s) + (-> [(Parser s) (-> Text Phase s (Operation Analysis))] Handler)) (function (_ extension-name analyse args) @@ -51,7 +51,7 @@ #member Text}) (def: member - (Syntax Member) + (Parser Member) ($_ p.and s.text s.text)) (type: Method-Signature @@ -1180,7 +1180,7 @@ (/////analysis.throw too-many-candidates [class-name ..constructor-method candidates])))) (def: typed-input - (Syntax [Text Code]) + (Parser [Text Code]) (s.tuple (p.and s.text s.any))) (def: (decorate-inputs typesT inputsA) diff --git a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux index 629e5af59..61243a9bc 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension/statement.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension/statement.lux @@ -4,7 +4,8 @@ ["." monad (#+ do)]] [control [io (#+ IO)] - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." product] ["." maybe] @@ -15,8 +16,7 @@ ["." list ("#;." functor)] ["." dictionary]]] ["." macro - ["." code] - ["s" syntax (#+ Syntax)]] + ["." code]] [type (#+ :share :by-example) ["." check]]] ["." // @@ -171,7 +171,7 @@ (///.throw //.invalid-syntax [extension-name %code inputsC+])))) (def: imports - (Syntax (List Import)) + (Parser (List Import)) (|> (s.tuple (p.and s.text s.text)) p.some s.tuple)) diff --git a/stdlib/source/lux/tool/compiler/phase/generation/extension.lux b/stdlib/source/lux/tool/compiler/phase/generation/extension.lux index 7c08e94cc..2dddb89f6 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/extension.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/extension.lux @@ -2,12 +2,15 @@ [lux #* [abstract ["." monad (#+ do)]] + [control + [parser + ["s" code]]] [data [collection ["." list ("#@." functor)]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]]] + [syntax (#+ syntax:)]]] ["." // ["#/" // ["#." extension] diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux index 8908c3335..c94b68337 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/js/runtime.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser]] + ["p" parser + ["s" code]]] [data [number (#+ hex) ["." i64]] @@ -14,7 +15,7 @@ ["." list ("#;." functor)]]] ["." macro ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host ["_" js (#+ Expression Var Computation Statement)]]] ["." /// diff --git a/stdlib/source/lux/tool/compiler/phase/generation/lua/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/lua/runtime.lux index 648d35d32..6eeddc5ff 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/lua/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/lua/runtime.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser]] + ["p" parser + ["s" code]]] [data [number (#+ hex) ["." i64]] @@ -14,7 +15,7 @@ ["." list ("#@." functor)]]] ["." macro ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host ["_" lua (#+ Expression Location Var Computation Literal Statement)]]] ["." /// diff --git a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux index 896b9e18a..44b9d290f 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/python/runtime.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser]] + ["p" parser + ["s" code]]] [data [number (#+ hex) ["." i64]] @@ -14,7 +15,7 @@ ["." list ("#@." functor)]]] ["." macro ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host ["_" python (#+ Expression SVar Computation Literal Statement)]]] ["." /// diff --git a/stdlib/source/lux/tool/compiler/phase/generation/ruby/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/ruby/runtime.lux index 71edc3e07..81bdc8702 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/ruby/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/ruby/runtime.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser]] + ["p" parser + ["s" code]]] [data [number (#+ hex) ["." i64]] @@ -14,7 +15,7 @@ ["." list ("#@." functor)]]] ["." macro ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host ["_" ruby (#+ Expression LVar Computation Literal Statement)]]] ["." /// diff --git a/stdlib/source/lux/tool/compiler/phase/generation/scheme/extension/common.lux b/stdlib/source/lux/tool/compiler/phase/generation/scheme/extension/common.lux index cb96a5718..31c101fdf 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/scheme/extension/common.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/scheme/extension/common.lux @@ -3,7 +3,9 @@ [abstract ["." monad (#+ do)]] [control - ["ex" exception (#+ exception:)]] + ["ex" exception (#+ exception:)] + [parser + ["s" code]]] [data ["e" error] ["." product] @@ -15,7 +17,7 @@ ["dict" dictionary (#+ Dictionary)]]] ["." macro (#+ with-gensyms) ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host (#+ import:) ["_" scheme (#+ Expression Computation)]]] ["." /// #_ diff --git a/stdlib/source/lux/tool/compiler/phase/generation/scheme/runtime.lux b/stdlib/source/lux/tool/compiler/phase/generation/scheme/runtime.lux index b66b7abaf..bda2f7783 100644 --- a/stdlib/source/lux/tool/compiler/phase/generation/scheme/runtime.lux +++ b/stdlib/source/lux/tool/compiler/phase/generation/scheme/runtime.lux @@ -4,7 +4,8 @@ [monad (#+ do)]] [control ["." function] - ["p" parser ("#;." monad)]] + ["p" parser ("#;." monad) + ["s" code (#+ Parser)]]] [data [number (#+ hex)] [text @@ -13,7 +14,7 @@ ["." list ("#;." monad)]]] [macro ["." code] - ["s" syntax (#+ syntax:)]] + [syntax (#+ syntax:)]] [host ["_" scheme (#+ Expression Computation Var)]]] ["." /// @@ -73,7 +74,7 @@ (|>> [0 #1] ..variant)) (def: declaration - (s.Syntax [Text (List Text)]) + (Parser [Text (List Text)]) (p.either (p.and s.local-identifier (p;wrap (list))) (s.form (p.and s.local-identifier (p.some s.local-identifier))))) diff --git a/stdlib/source/lux/type.lux b/stdlib/source/lux/type.lux index d8288314c..c540e6499 100644 --- a/stdlib/source/lux/type.lux +++ b/stdlib/source/lux/type.lux @@ -4,7 +4,8 @@ [equivalence (#+ Equivalence)] [monad (#+ Monad do)]] [control - ["p" parser] + ["p" parser + ["s" code (#+ Parser)]] ["." function]] [data ["." text ("#@." monoid equivalence)] @@ -17,7 +18,7 @@ ["." list ("#@." functor monoid fold)]]] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)]]]) + [syntax (#+ syntax:)]]]) (template [<name> <tag>] [(def: #export (<name> type) @@ -365,7 +366,7 @@ (..:log! (~ g!value))))))))) (def: type-parameters - (Syntax (List Text)) + (Parser (List Text)) (s.tuple (p.some s.local-identifier))) (syntax: #export (:cast {type-vars type-parameters} @@ -387,7 +388,7 @@ #expression Code}) (def: typed - (Syntax Typed) + (Parser Typed) (s.record (p.and s.any s.any))) ## TODO: Make sure the generated code always gets optimized away. diff --git a/stdlib/source/lux/type/abstract.lux b/stdlib/source/lux/type/abstract.lux index d293c4083..7c5804e04 100644 --- a/stdlib/source/lux/type/abstract.lux +++ b/stdlib/source/lux/type/abstract.lux @@ -3,8 +3,9 @@ [abstract [monad (#+ Monad do)]] [control - ["p" parser ("#;." monad)] - ["ex" exception (#+ exception:)]] + ["ex" exception (#+ exception:)] + ["p" parser ("#;." monad) + ["s" code (#+ Parser)]]] [data ["." name ("#;." codec)] ["." text ("#;." equivalence monoid)] @@ -13,8 +14,7 @@ ["." stack (#+ Stack)]]] ["." macro ("#;." monad) ["." code] - ["s" syntax (#+ Syntax syntax:)] - [syntax + [syntax (#+ syntax:) ["cs" common ["csr" reader] ["csw" writer]]]] @@ -135,7 +135,7 @@ (list)]))) (def: cast - (Syntax [(Maybe Text) Code]) + (Parser [(Maybe Text) Code]) (p.either (p.and (p.maybe s.local-identifier) s.any) (p.and (p;wrap #.None) s.any))) @@ -164,7 +164,7 @@ " "))) (def: declaration - (Syntax [Text (List Text)]) + (Parser [Text (List Text)]) (p.either (s.form (p.and s.local-identifier (p.some s.local-identifier))) (p.and s.local-identifier (:: p.monad wrap (list))))) diff --git a/stdlib/source/lux/type/implicit.lux b/stdlib/source/lux/type/implicit.lux index d8ce47c2c..5e72b7a79 100644 --- a/stdlib/source/lux/type/implicit.lux +++ b/stdlib/source/lux/type/implicit.lux @@ -4,7 +4,8 @@ ["." monad (#+ do Monad)] ["eq" equivalence]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." product] ["." maybe] @@ -16,7 +17,7 @@ ["dict" dictionary (#+ Dictionary)]]] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)]] + [syntax (#+ syntax:)]] ["." type ["." check (#+ Check)]]]) @@ -370,7 +371,7 @@ (monad.seq macro.monad))) (def: implicits - (Syntax (List Code)) + (Parser (List Code)) (s.tuple (p.many s.any))) (syntax: #export (implicit {structures ..implicits} body) diff --git a/stdlib/source/lux/type/resource.lux b/stdlib/source/lux/type/resource.lux index 8e4b63679..7c9201057 100644 --- a/stdlib/source/lux/type/resource.lux +++ b/stdlib/source/lux/type/resource.lux @@ -4,7 +4,8 @@ ["." monad (#+ Monad do) [indexed (#+ IxMonad)]]] [control - ["p" parser] + ["p" parser + ["s" code (#+ Parser)]] ["ex" exception (#+ exception:)] ["." io (#+ IO)] [concurrency @@ -22,7 +23,7 @@ ["." row (#+ Row)] ["." list ("#@." functor fold)]]] ["." macro - ["s" syntax (#+ Syntax syntax:)]] + [syntax (#+ syntax:)]] [type abstract]]) @@ -130,7 +131,7 @@ (exception: #export amount-cannot-be-zero) (def: indices - (Syntax (List Nat)) + (Parser (List Nat)) (s.tuple (loop [seen (set.new nat.hash)] (do p.monad [done? s.end?] @@ -182,7 +183,7 @@ [exchange-async Promise promise.monad]) (def: amount - (Syntax Nat) + (Parser Nat) (do p.monad [raw s.nat _ (p.assert (ex.construct amount-cannot-be-zero []) diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux index 1437f862c..15ff953d2 100644 --- a/stdlib/source/lux/type/unit.lux +++ b/stdlib/source/lux/type/unit.lux @@ -7,7 +7,8 @@ [order (#+ Order)] [enum (#+ Enum)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data [number ["r" ratio (#+ Ratio)]] @@ -15,8 +16,7 @@ format]] ["." macro ["." code] - ["s" syntax (#+ Syntax syntax:)] - [syntax + [syntax (#+ syntax:) ["cs" common ["csr" reader] ["csw" writer]]]] @@ -82,7 +82,7 @@ ))) (def: ratio^ - (Syntax Ratio) + (Parser Ratio) (s.tuple (do p.monad [numerator s.int _ (p.assert (format "Numerator must be positive: " (%i numerator)) diff --git a/stdlib/source/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index da6c0a381..01dbd1415 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -9,6 +9,9 @@ ["$." functor (#+ Injection Comparison)] ["$." apply] ["$." monad]]}] + [control + [parser + ["s" code (#+ Parser)]]] [data ["." error (#+ Error)] [number @@ -21,7 +24,7 @@ ["r" random]] [macro ["." code] - ["s" syntax (#+ Syntax syntax:)]]] + [syntax (#+ syntax:)]]] {1 ["." / (#+ Parser)]}) diff --git a/stdlib/source/test/lux/data/text/regex.lux b/stdlib/source/test/lux/data/text/regex.lux index f456aac73..3a9fc740d 100644 --- a/stdlib/source/test/lux/data/text/regex.lux +++ b/stdlib/source/test/lux/data/text/regex.lux @@ -6,7 +6,8 @@ [control pipe ["p" parser - ["<.>" text (#+ Parser)]]] + ["<.>" text (#+ Parser)] + ["s" code]]] [data [number (#+ hex)] ["." error] @@ -14,7 +15,7 @@ [math ["r" random]] ["." macro - ["s" syntax (#+ syntax:)]]] + [syntax (#+ syntax:)]]] {1 ["." /]}) diff --git a/stdlib/source/test/lux/macro/syntax.lux b/stdlib/source/test/lux/macro/syntax.lux index 92ba86d4d..8422bb4e1 100644 --- a/stdlib/source/test/lux/macro/syntax.lux +++ b/stdlib/source/test/lux/macro/syntax.lux @@ -7,7 +7,8 @@ [abstract [equivalence (#+ Equivalence)]] [control - ["p" parser]] + ["p" parser + ["s" code (#+ Parser)]]] [data ["." bit] ["." name] @@ -21,10 +22,10 @@ ["." macro ["." code]]] {1 - ["." / (#+ syntax: Syntax)]}) + ["." / (#+ syntax:)]}) (def: (enforced? parser input) - (-> (Syntax []) (List Code) Bit) + (-> (Parser []) (List Code) Bit) (case (p.run input parser) (#.Right [_ []]) #1 @@ -33,7 +34,7 @@ #0)) (def: (found? parser input) - (-> (Syntax Bit) (List Code) Bit) + (-> (Parser Bit) (List Code) Bit) (case (p.run input parser) (#.Right [_ #1]) #1 @@ -42,7 +43,7 @@ #0)) (def: (equals? Equivalence<a> reference parser input) - (All [a] (-> (Equivalence a) a (Syntax a) (List Code) Bit)) + (All [a] (-> (Equivalence a) a (Parser a) (List Code) Bit)) (case (p.run input parser) (#.Right [_ output]) (:: Equivalence<a> = reference output) @@ -73,30 +74,30 @@ (~~ (template [<assertion> <value> <ctor> <Equivalence> <get>] [(_.test <assertion> (and (equals? <Equivalence> <value> <get> (list (<ctor> <value>))) - (found? (/.this? (<ctor> <value>)) (list (<ctor> <value>))) - (enforced? (/.this (<ctor> <value>)) (list (<ctor> <value>)))))] + (found? (s.this? (<ctor> <value>)) (list (<ctor> <value>))) + (enforced? (s.this (<ctor> <value>)) (list (<ctor> <value>)))))] - ["Can parse Bit syntax." #1 code.bit bit.equivalence /.bit] - ["Can parse Nat syntax." 123 code.nat nat.equivalence /.nat] - ["Can parse Int syntax." +123 code.int int.equivalence /.int] - ["Can parse Rev syntax." .123 code.rev rev.equivalence /.rev] - ["Can parse Frac syntax." +123.0 code.frac frac.equivalence /.frac] - ["Can parse Text syntax." text.new-line code.text text.equivalence /.text] - ["Can parse Identifier syntax." ["yolo" "lol"] code.identifier name.equivalence /.identifier] - ["Can parse Tag syntax." ["yolo" "lol"] code.tag name.equivalence /.tag] + ["Can parse Bit syntax." #1 code.bit bit.equivalence s.bit] + ["Can parse Nat syntax." 123 code.nat nat.equivalence s.nat] + ["Can parse Int syntax." +123 code.int int.equivalence s.int] + ["Can parse Rev syntax." .123 code.rev rev.equivalence s.rev] + ["Can parse Frac syntax." +123.0 code.frac frac.equivalence s.frac] + ["Can parse Text syntax." text.new-line code.text text.equivalence s.text] + ["Can parse Identifier syntax." ["yolo" "lol"] code.identifier name.equivalence s.identifier] + ["Can parse Tag syntax." ["yolo" "lol"] code.tag name.equivalence s.tag] )) (_.test "Can parse identifiers belonging to the current namespace." (and (match "yolo" (p.run (list (code.local-identifier "yolo")) - /.local-identifier)) + s.local-identifier)) (fails? (p.run (list (code.identifier ["yolo" "lol"])) - /.local-identifier)))) + s.local-identifier)))) (_.test "Can parse tags belonging to the current namespace." (and (match "yolo" (p.run (list (code.local-tag "yolo")) - /.local-tag)) + s.local-tag)) (fails? (p.run (list (code.tag ["yolo" "lol"])) - /.local-tag)))) + s.local-tag)))) ))) (def: complex-values @@ -106,32 +107,32 @@ [(_.test (format "Can parse " <type> " syntax.") (and (match [#1 +123] (p.run (list (<ctor> (list (code.bit #1) (code.int +123)))) - (<parser> (p.and /.bit /.int)))) + (<parser> (p.and s.bit s.int)))) (match #1 (p.run (list (<ctor> (list (code.bit #1)))) - (<parser> /.bit))) + (<parser> s.bit))) (fails? (p.run (list (<ctor> (list (code.bit #1) (code.int +123)))) - (<parser> /.bit))) + (<parser> s.bit))) (match (#.Left #1) (p.run (list (<ctor> (list (code.bit #1)))) - (<parser> (p.or /.bit /.int)))) + (<parser> (p.or s.bit s.int)))) (match (#.Right +123) (p.run (list (<ctor> (list (code.int +123)))) - (<parser> (p.or /.bit /.int)))) + (<parser> (p.or s.bit s.int)))) (fails? (p.run (list (<ctor> (list (code.frac +123.0)))) - (<parser> (p.or /.bit /.int))))))] + (<parser> (p.or s.bit s.int))))))] - ["form" /.form code.form] - ["tuple" /.tuple code.tuple])) + ["form" s.form code.form] + ["tuple" s.tuple code.tuple])) (_.test "Can parse record syntax." (match [#1 +123] (p.run (list (code.record (list [(code.bit #1) (code.int +123)]))) - (/.record (p.and /.bit /.int))))) + (s.record (p.and s.bit s.int))))) ))) (def: #export test Test - (<| (_.context (%name (name-of /._))) + (<| (_.context (name.module (name-of /._))) ($_ _.and ..simple-values ..complex-values @@ -139,18 +140,18 @@ (_.test "Can parse any Code." (match [_ (#.Bit #1)] (p.run (list (code.bit #1) (code.int +123)) - /.any))) + s.any))) (_.test "Can check whether the end has been reached." (and (match #1 (p.run (list) - /.end?)) + s.end?)) (match #0 (p.run (list (code.bit #1)) - /.end?)))) + s.end?)))) (_.test "Can ensure the end has been reached." (and (match [] (p.run (list) - /.end!)) + s.end!)) (fails? (p.run (list (code.bit #1)) - /.end!)))) + s.end!)))) )))) |