From 149515fd173947dcff20558fca077fbd16dc9b6c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 27 Jun 2022 03:26:33 -0400 Subject: New "parser" hierarchy. [Part 5] --- stdlib/source/documentation/lux/target.lux | 15 +- stdlib/source/documentation/lux/target/js.lux | 2 +- stdlib/source/documentation/lux/target/jvm.lux | 2 +- .../source/documentation/lux/target/jvm/type.lux | 2 +- .../documentation/lux/target/jvm/type/alias.lux | 2 +- .../documentation/lux/target/jvm/type/box.lux | 2 +- .../documentation/lux/target/jvm/type/category.lux | 2 +- .../lux/target/jvm/type/descriptor.lux | 2 +- .../documentation/lux/target/jvm/type/lux.lux | 2 +- .../documentation/lux/target/jvm/type/parser.lux | 2 +- .../lux/target/jvm/type/reflection.lux | 2 +- .../lux/target/jvm/type/signature.lux | 2 +- stdlib/source/documentation/lux/target/lua.lux | 2 +- stdlib/source/documentation/lux/target/python.lux | 2 +- stdlib/source/documentation/lux/target/ruby.lux | 2 +- stdlib/source/documentation/lux/time.lux | 103 ++++++------ stdlib/source/documentation/lux/time/date.lux | 31 ++-- stdlib/source/documentation/lux/time/day.lux | 20 ++- stdlib/source/documentation/lux/time/duration.lux | 22 ++- stdlib/source/documentation/lux/time/instant.lux | 81 +++++----- stdlib/source/documentation/lux/time/month.lux | 38 ++--- stdlib/source/documentation/lux/time/year.lux | 58 +++---- stdlib/source/library/lux/control/parser/cli.lux | 93 ----------- stdlib/source/library/lux/control/parser/tree.lux | 60 ------- stdlib/source/library/lux/program.lux | 18 +-- .../source/library/lux/tool/compiler/meta/cli.lux | 29 ++-- stdlib/source/parser/lux/data/collection/tree.lux | 59 +++++++ stdlib/source/parser/lux/program.lux | 93 +++++++++++ stdlib/source/test/lux/control/parser.lux | 6 +- stdlib/source/test/lux/control/parser/cli.lux | 86 ---------- stdlib/source/test/lux/control/parser/tree.lux | 178 --------------------- stdlib/source/test/lux/data/collection/tree.lux | 168 ++++++++++++++++++- stdlib/source/test/lux/program.lux | 162 +++++++++++++------ stdlib/source/test/lux/tool/compiler/meta/cli.lux | 15 +- 34 files changed, 648 insertions(+), 715 deletions(-) delete mode 100644 stdlib/source/library/lux/control/parser/cli.lux delete mode 100644 stdlib/source/library/lux/control/parser/tree.lux create mode 100644 stdlib/source/parser/lux/data/collection/tree.lux create mode 100644 stdlib/source/parser/lux/program.lux delete mode 100644 stdlib/source/test/lux/control/parser/cli.lux delete mode 100644 stdlib/source/test/lux/control/parser/tree.lux (limited to 'stdlib/source') diff --git a/stdlib/source/documentation/lux/target.lux b/stdlib/source/documentation/lux/target.lux index 306876f18..70ba24c62 100644 --- a/stdlib/source/documentation/lux/target.lux +++ b/stdlib/source/documentation/lux/target.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] @@ -16,16 +16,11 @@ ["[1][0]" python] ["[1][0]" ruby]]) -(documentation: /.Target - (format "The name/ID of a platform targetted by a Lux compiler." - \n "This information can be used to generate code targetting specific platforms, and to make programs cross-platform.")) - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Target - ($.default /.old) + [($.default /.old) ($.default /.js) ($.default /.jvm) ($.default /.lua) @@ -34,7 +29,11 @@ ($.default /.common_lisp) ($.default /.php) ($.default /.r) - ($.default /.scheme)] + ($.default /.scheme) + + ($.documentation /.Target + (format "The name/ID of a platform targetted by a Lux compiler." + \n "This information can be used to generate code targetting specific platforms, and to make programs cross-platform."))] [/js.documentation /jvm.documentation /lua.documentation diff --git a/stdlib/source/documentation/lux/target/js.lux b/stdlib/source/documentation/lux/target/js.lux index 864a5e2c7..68f67d560 100644 --- a/stdlib/source/documentation/lux/target/js.lux +++ b/stdlib/source/documentation/lux/target/js.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm.lux b/stdlib/source/documentation/lux/target/jvm.lux index 85ec6ea01..440ef5775 100644 --- a/stdlib/source/documentation/lux/target/jvm.lux +++ b/stdlib/source/documentation/lux/target/jvm.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type.lux b/stdlib/source/documentation/lux/target/jvm/type.lux index 902683d16..39bded852 100644 --- a/stdlib/source/documentation/lux/target/jvm/type.lux +++ b/stdlib/source/documentation/lux/target/jvm/type.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/alias.lux b/stdlib/source/documentation/lux/target/jvm/type/alias.lux index 3af9a8997..d8e17f39a 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/alias.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/alias.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/box.lux b/stdlib/source/documentation/lux/target/jvm/type/box.lux index 04ddd5a9d..1f393eb2e 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/box.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/box.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/category.lux b/stdlib/source/documentation/lux/target/jvm/type/category.lux index 1b17ca5a7..123041fcb 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/category.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/category.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux b/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux index 9eaa79e17..8a484151c 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/descriptor.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/lux.lux b/stdlib/source/documentation/lux/target/jvm/type/lux.lux index 0b09556dc..408b5c6f4 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/lux.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/lux.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/parser.lux b/stdlib/source/documentation/lux/target/jvm/type/parser.lux index afd3515f2..81e9d4bee 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/parser.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/parser.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/reflection.lux b/stdlib/source/documentation/lux/target/jvm/type/reflection.lux index 4cd2327ee..64ecb135c 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/reflection.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/reflection.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/jvm/type/signature.lux b/stdlib/source/documentation/lux/target/jvm/type/signature.lux index dd2234c90..8991f34ee 100644 --- a/stdlib/source/documentation/lux/target/jvm/type/signature.lux +++ b/stdlib/source/documentation/lux/target/jvm/type/signature.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except char) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/lua.lux b/stdlib/source/documentation/lux/target/lua.lux index 651d70c7b..dbbd515a5 100644 --- a/stdlib/source/documentation/lux/target/lua.lux +++ b/stdlib/source/documentation/lux/target/lua.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/python.lux b/stdlib/source/documentation/lux/target/python.lux index 69bec7b7e..c531707ae 100644 --- a/stdlib/source/documentation/lux/target/python.lux +++ b/stdlib/source/documentation/lux/target/python.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/target/ruby.lux b/stdlib/source/documentation/lux/target/ruby.lux index bddc34acc..a678fe81b 100644 --- a/stdlib/source/documentation/lux/target/ruby.lux +++ b/stdlib/source/documentation/lux/target/ruby.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except) - ["$" documentation (.only documentation:)] + ["$" documentation] [data [text (.only \n) ["%" \\format (.only format)]] diff --git a/stdlib/source/documentation/lux/time.lux b/stdlib/source/documentation/lux/time.lux index 1b0b5ac6c..3041638d5 100644 --- a/stdlib/source/documentation/lux/time.lux +++ b/stdlib/source/documentation/lux/time.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -17,68 +17,57 @@ ["[1][0]" month] ["[1][0]" year]]) -(with_template [ ] - [(documentation: - )] +(`` (.def .public documentation + (.List $.Module) + ($.module /._ + "" + [($.default /.time_exceeds_a_day) + ($.default /.invalid_hour) + ($.default /.invalid_minute) + ($.default /.invalid_second) + ($.default /.millis) + ($.default /.equivalence) + ($.default /.order) + ($.default /.enum) + ($.default /.parser) - [/.milli_seconds "Number of milli-seconds in a second."] - [/.seconds "Number of seconds in a minute."] - [/.minutes "Number of minutes in an hour."] - [/.hours "Number of hours in an day."] - ) + (~~ (with_template [ ] + [($.documentation + )] -(documentation: /.Time - "Time is defined as milliseconds since the start of the day (00:00:00.000).") + [/.milli_seconds "Number of milli-seconds in a second."] + [/.seconds "Number of seconds in a minute."] + [/.minutes "Number of minutes in an hour."] + [/.hours "Number of hours in an day."] + )) -(documentation: /.midnight - "The instant corresponding to the start of the day: 00:00:00.000") + ($.documentation /.Time + "Time is defined as milliseconds since the start of the day (00:00:00.000).") -(documentation: /.of_millis - "" - [(of_millis milli_seconds)]) + ($.documentation /.midnight + "The instant corresponding to the start of the day: 00:00:00.000") -(documentation: /.Clock - "A clock marking the specific hour, minute, second, and milli-second in a day.") + ($.documentation /.of_millis + "" + [(of_millis milli_seconds)]) -(documentation: /.clock - "" - [(clock time)]) + ($.documentation /.Clock + "A clock marking the specific hour, minute, second, and milli-second in a day.") -(documentation: /.time - "" - [(time clock)]) + ($.documentation /.clock + "" + [(clock time)]) -(documentation: /.codec - (format "Based on ISO 8601." - \n "For example: 21:14:51.827")) + ($.documentation /.time + "" + [(time clock)]) -(.def .public documentation - (.List $.Module) - ($.module /._ - "" - [..milli_seconds - ..seconds - ..minutes - ..hours - ..Time - ..midnight - ..of_millis - ..Clock - ..clock - ..time - ..codec - ($.default /.time_exceeds_a_day) - ($.default /.invalid_hour) - ($.default /.invalid_minute) - ($.default /.invalid_second) - ($.default /.millis) - ($.default /.equivalence) - ($.default /.order) - ($.default /.enum) - ($.default /.parser)] - [/date.documentation - /day.documentation - /duration.documentation - /instant.documentation - /month.documentation - /year.documentation])) + ($.documentation /.codec + (format "Based on ISO 8601." + \n "For example: 21:14:51.827"))] + [/date.documentation + /day.documentation + /duration.documentation + /instant.documentation + /month.documentation + /year.documentation]))) diff --git a/stdlib/source/documentation/lux/time/date.lux b/stdlib/source/documentation/lux/time/date.lux index 818371741..15bfdafbb 100644 --- a/stdlib/source/documentation/lux/time/date.lux +++ b/stdlib/source/documentation/lux/time/date.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,25 +10,11 @@ [\\library ["[0]" /]]) -(documentation: /.Date - "A date specified as a year/month/day triplet.") - -(documentation: /.date - "A date, within the allowed limits." - [(date year month day_of_month)]) - -(documentation: /.codec - (format "Based on ISO 8601." - \n "For example: 2017-01-15")) - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Date - ..date - ..codec - ($.default /.invalid_day) + [($.default /.invalid_day) ($.default /.epoch) ($.default /.year) ($.default /.month) @@ -39,5 +25,16 @@ ($.default /.parser) ($.default /.days) ($.default /.of_days) - ($.default /.enum)] + ($.default /.enum) + + ($.documentation /.Date + "A date specified as a year/month/day triplet.") + + ($.documentation /.date + "A date, within the allowed limits." + [(date year month day_of_month)]) + + ($.documentation /.codec + (format "Based on ISO 8601." + \n "For example: 2017-01-15"))] [])) diff --git a/stdlib/source/documentation/lux/time/day.lux b/stdlib/source/documentation/lux/time/day.lux index 5cd046493..29db3b570 100644 --- a/stdlib/source/documentation/lux/time/day.lux +++ b/stdlib/source/documentation/lux/time/day.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,19 +10,11 @@ [\\library ["[0]" /]]) -(documentation: /.Day - "A day of the week.") - -(documentation: /.week - "All the days, ordered by when they come in a week.") - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Day - ..week - ($.default /.equivalence) + [($.default /.equivalence) ($.default /.order) ($.default /.enum) ($.default /.not_a_day_of_the_week) @@ -30,5 +22,11 @@ ($.default /.number) ($.default /.invalid_day) ($.default /.by_number) - ($.default /.hash)] + ($.default /.hash) + + ($.documentation /.Day + "A day of the week.") + + ($.documentation /.week + "All the days, ordered by when they come in a week.")] [])) diff --git a/stdlib/source/documentation/lux/time/duration.lux b/stdlib/source/documentation/lux/time/duration.lux index 448ea46eb..1340f3460 100644 --- a/stdlib/source/documentation/lux/time/duration.lux +++ b/stdlib/source/documentation/lux/time/duration.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,20 +10,11 @@ [\\library ["[0]" /]]) -(documentation: /.Duration - "Durations have a resolution of milli-seconds.") - -(documentation: /.difference - "" - [(difference from to)]) - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Duration - ..difference - ($.default /.of_millis) + [($.default /.of_millis) ($.default /.millis) ($.default /.composite) ($.default /.framed) @@ -47,5 +38,12 @@ ($.default /.leap_year) ($.default /.monoid) ($.default /.codec) - ($.default /.enum)] + ($.default /.enum) + + ($.documentation /.Duration + "Durations have a resolution of milli-seconds.") + + ($.documentation /.difference + "" + [(difference from to)])] [])) diff --git a/stdlib/source/documentation/lux/time/instant.lux b/stdlib/source/documentation/lux/time/instant.lux index 9eb35f53d..b40489b5c 100644 --- a/stdlib/source/documentation/lux/time/instant.lux +++ b/stdlib/source/documentation/lux/time/instant.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,58 +10,49 @@ [\\library ["[0]" /]]) -(documentation: /.Instant - "Instant is defined as milli-seconds since the epoch.") - -(documentation: /.span - "" - [(span from to)]) - -(documentation: /.after - "" - [(after duration instant)]) - -(documentation: /.relative - "" - [(relative instant)]) - -(documentation: /.absolute - "" - [(absolute offset)]) - -(documentation: /.epoch - "The instant corresponding to 1970-01-01T00:00:00Z.") - -(documentation: /.codec - (format "Based on ISO 8601." - \n "For example: 2017-01-15T21:14:51.827Z")) - -(documentation: /.now - "Yields the current instant, as measured from the operating-system's clock.") - -(documentation: /.of_date_time - "" - [(of_date_time date time)]) - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Instant - ..span - ..after - ..relative - ..absolute - ..epoch - ..codec - ..now - ..of_date_time - ($.default /.of_millis) + [($.default /.of_millis) ($.default /.millis) ($.default /.equivalence) ($.default /.order) ($.default /.enum) ($.default /.date) ($.default /.time) - ($.default /.day_of_week)] + ($.default /.day_of_week) + + ($.documentation /.Instant + "Instant is defined as milli-seconds since the epoch.") + + ($.documentation /.span + "" + [(span from to)]) + + ($.documentation /.after + "" + [(after duration instant)]) + + ($.documentation /.relative + "" + [(relative instant)]) + + ($.documentation /.absolute + "" + [(absolute offset)]) + + ($.documentation /.epoch + "The instant corresponding to 1970-01-01T00:00:00Z.") + + ($.documentation /.codec + (format "Based on ISO 8601." + \n "For example: 2017-01-15T21:14:51.827Z")) + + ($.documentation /.now + "Yields the current instant, as measured from the operating-system's clock.") + + ($.documentation /.of_date_time + "" + [(of_date_time date time)])] [])) diff --git a/stdlib/source/documentation/lux/time/month.lux b/stdlib/source/documentation/lux/time/month.lux index ccd31a8c4..05103ec1f 100644 --- a/stdlib/source/documentation/lux/time/month.lux +++ b/stdlib/source/documentation/lux/time/month.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,29 +10,11 @@ [\\library ["[0]" /]]) -(documentation: /.Month - "A month of the year.") - -(documentation: /.days - "The amount of days of a month." - [(days month)]) - -(documentation: /.leap_year_days - "The amount of days of a month (in a leap year)." - [(leap_year_days month)]) - -(documentation: /.year - "All the months, ordered by when they come in a year.") - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Month - ..days - ..leap_year_days - ..year - ($.default /.equivalence) + [($.default /.equivalence) ($.default /.number) ($.default /.invalid_month) ($.default /.by_number) @@ -40,5 +22,19 @@ ($.default /.order) ($.default /.enum) ($.default /.not_a_month_of_the_year) - ($.default /.codec)] + ($.default /.codec) + + ($.documentation /.Month + "A month of the year.") + + ($.documentation /.days + "The amount of days of a month." + [(days month)]) + + ($.documentation /.leap_year_days + "The amount of days of a month (in a leap year)." + [(leap_year_days month)]) + + ($.documentation /.year + "All the months, ordered by when they come in a year.")] [])) diff --git a/stdlib/source/documentation/lux/time/year.lux b/stdlib/source/documentation/lux/time/year.lux index b8dc23837..85341eb24 100644 --- a/stdlib/source/documentation/lux/time/year.lux +++ b/stdlib/source/documentation/lux/time/year.lux @@ -1,7 +1,7 @@ (.require [library [lux (.except and) - ["$" documentation (.only documentation:)] + ["$" documentation] [data ["[0]" text (.only \n) ["%" \\format (.only format)]]] @@ -10,40 +10,11 @@ [\\library ["[0]" /]]) -(documentation: /.Year - (format "A year in the gregorian calendar." - \n "Both negative (< 0) and positive (> 0) values are valid, but not 0." - \n "This is because the first year of the gregorian calendar was year 1.")) - -(documentation: /.year - "A valid year in the gregorian calendar, if possible." - [(year value)]) - -(documentation: /.days - "The amount of days in a typical year.") - -(documentation: /.Period - "An amount of years.") - -(documentation: /.leaps - "The number of leap years in a period of years." - [(leaps year)]) - -(documentation: /.codec - (format "Based on ISO 8601." - \n "For example: 2017")) - (.def .public documentation (.List $.Module) ($.module /._ "" - [..Year - ..year - ..days - ..Period - ..leaps - ..codec - ($.default /.there_is_no_year_0) + [($.default /.there_is_no_year_0) ($.default /.value) ($.default /.epoch) ($.default /.leap) @@ -52,5 +23,28 @@ ($.default /.leap?) ($.default /.parser) ($.default /.equivalence) - ($.default /.order)] + ($.default /.order) + + ($.documentation /.Year + (format "A year in the gregorian calendar." + \n "Both negative (< 0) and positive (> 0) values are valid, but not 0." + \n "This is because the first year of the gregorian calendar was year 1.")) + + ($.documentation /.year + "A valid year in the gregorian calendar, if possible." + [(year value)]) + + ($.documentation /.days + "The amount of days in a typical year.") + + ($.documentation /.Period + "An amount of years.") + + ($.documentation /.leaps + "The number of leap years in a period of years." + [(leaps year)]) + + ($.documentation /.codec + (format "Based on ISO 8601." + \n "For example: 2017"))] [])) 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 [ ] - [(def .public - (All (_ t) (Parser t [])) - (function (_ zipper) - (case ( 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 ((~! .result) (.is (~! (.Parser (io.IO .Any))) - ((~! do) (~! <>.monad) - [(~+ args) - (~ g!_) (~! .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 [ ] [(def (Parser ) - (.named ))] + (.named ))] - [host_dependency_parser "--host_dependency" Host_Dependency .any] - [library_parser "--library" Library .any] - [compiler_parser "--compiler" Compiler (.then /compiler.parser .any)] - [source_parser "--source" Source .any] - [target_parser "--target" Target .any] - [module_parser "--module" Module .any] - [configuration_parser "--configuration" Configuration (.then configuration.parser .any)] + [host_dependency_parser "--host_dependency" Host_Dependency .any] + [library_parser "--library" Library .any] + [compiler_parser "--compiler" Compiler (.then /compiler.parser .any)] + [source_parser "--source" Source .any] + [target_parser "--target" Target .any] + [module_parser "--module" Module .any] + [configuration_parser "--configuration" Configuration (.then configuration.parser .any)] ) (def .public service @@ -96,11 +97,11 @@ ..module_parser (<>.else configuration.empty ..configuration_parser)))] (all <>.or - (<>.after (.this "build") + (<>.after (.this "build") compilation) - (<>.after (.this "repl") + (<>.after (.this "repl") compilation) - (<>.after (.this "export") + (<>.after (.this "export") (all <>.and (<>.some ..source_parser) ..target_parser)) diff --git a/stdlib/source/parser/lux/data/collection/tree.lux b/stdlib/source/parser/lux/data/collection/tree.lux new file mode 100644 index 000000000..5d10ce15b --- /dev/null +++ b/stdlib/source/parser/lux/data/collection/tree.lux @@ -0,0 +1,59 @@ +(.require + [library + [lux (.except left right) + [abstract + [monad (.only do)]] + [control + ["//" parser] + ["[0]" try (.only Try)] + ["[0]" exception (.only exception)]]]] + [\\library + [/ (.only Tree) + ["[0]" zipper (.only Zipper)]]]) + +(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 [ ] + [(def .public + (All (_ t) (Parser t [])) + (function (_ zipper) + (case ( 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/parser/lux/program.lux b/stdlib/source/parser/lux/program.lux new file mode 100644 index 000000000..e834136d8 --- /dev/null +++ b/stdlib/source/parser/lux/program.lux @@ -0,0 +1,93 @@ +(.require + [library + [lux (.except parameter) + [abstract + [monad (.only do)]] + [control + ["//" parser] + ["[0]" try (.only Try)]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format (.only format)]]]]]) + +(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/test/lux/control/parser.lux b/stdlib/source/test/lux/control/parser.lux index e977e9df3..624999201 100644 --- a/stdlib/source/test/lux/control/parser.lux +++ b/stdlib/source/test/lux/control/parser.lux @@ -27,9 +27,7 @@ [\\library ["[0]" / (.only Parser)]] ["[0]" / - ["[1][0]" cli] - ["[1][0]" environment] - ["[1][0]" tree]]) + ["[1][0]" environment]]) (def (should_fail expected input) (All (_ a) (-> Text (Try a) Bit)) @@ -377,7 +375,5 @@ ..combinators_1 ..combinators_2 - /cli.test /environment.test - /tree.test )))) diff --git a/stdlib/source/test/lux/control/parser/cli.lux b/stdlib/source/test/lux/control/parser/cli.lux deleted file mode 100644 index 46f04712c..000000000 --- a/stdlib/source/test/lux/control/parser/cli.lux +++ /dev/null @@ -1,86 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" try] - ["<>" parser]] - [data - ["[0]" text (.use "[1]#[0]" equivalence)] - [collection - ["[0]" list]]] - [macro - ["^" pattern]] - [math - ["[0]" random] - [number - ["n" nat (.use "[1]#[0]" decimal)]]]]] - [\\library - ["[0]" /]]) - -(def !expect - (template (_ ) - [(case - - true - - _ - false)])) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (do [! random.monad] - [expected (at ! each n#encoded random.nat) - .let [random_dummy (random.only (|>> (text#= expected) not) - (random.unicode 5))] - dummy random_dummy - short (random.unicode 1) - long (random.unicode 2) - pre_ignore (random.list 5 random_dummy) - post_ignore (random.list 5 random_dummy)] - (all _.and - (_.coverage [/.result /.any] - (|> (/.result /.any (list expected)) - (!expect (^.multi {try.#Success actual} - (text#= expected actual))))) - (_.coverage [/.parse] - (|> (/.result (/.parse n#decoded) (list expected)) - (!expect (^.multi {try.#Success actual} - (text#= expected - (n#encoded actual)))))) - (_.coverage [/.this] - (and (|> (/.result (/.this expected) (list expected)) - (!expect {try.#Success _})) - (|> (/.result (/.this expected) (list dummy)) - (!expect {try.#Failure _})))) - (_.coverage [/.somewhere] - (|> (/.result (|> (/.somewhere (/.this expected)) - (<>.before (<>.some /.any))) - (list.together (list pre_ignore (list expected) post_ignore))) - (!expect {try.#Success _}))) - (_.coverage [/.end] - (and (|> (/.result /.end (list)) - (!expect {try.#Success _})) - (|> (/.result (<>.not /.end) (list expected)) - (!expect {try.#Failure _})))) - (_.coverage [/.named] - (|> (/.result (/.named dummy /.any) (list dummy expected)) - (!expect (^.multi {try.#Success actual} - (text#= expected actual))))) - (_.coverage [/.parameter] - (and (|> (/.result (/.parameter [short long] /.any) - (list short expected)) - (!expect (^.multi {try.#Success actual} - (text#= expected actual)))) - (|> (/.result (/.parameter [short long] /.any) - (list long expected)) - (!expect (^.multi {try.#Success actual} - (text#= expected actual)))) - (|> (/.result (/.parameter [short long] /.any) - (list dummy expected)) - (!expect {try.#Failure _})))) - )))) diff --git a/stdlib/source/test/lux/control/parser/tree.lux b/stdlib/source/test/lux/control/parser/tree.lux deleted file mode 100644 index 9ac82705e..000000000 --- a/stdlib/source/test/lux/control/parser/tree.lux +++ /dev/null @@ -1,178 +0,0 @@ -(.require - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [monad (.only do)]] - [control - ["[0]" try] - ["[0]" exception]] - [data - [collection - ["[0]" tree (.only) - ["[0]" zipper]]]] - [macro - ["^" pattern]] - [math - ["[0]" random] - [number - ["n" nat]]]]] - [\\library - ["[0]" / (.only) - ["/[1]" //]]]) - -(def !expect - (template (_ ) - [(case - - true - - _ - false)])) - -(def !cover - (template (_ ) - [(do [! random.monad] - [dummy random.nat - expected (|> random.nat (random.only (|>> (n.= dummy) not)))] - (_.coverage - (|> (/.result - ) - (!expect (^.multi {try.#Success actual} - (n.= expected actual))))))])) - -(def !cover/2 - (template (_ ) - [(do [! random.monad] - [dummy random.nat - expected (|> random.nat (random.only (|>> (n.= dummy) not)))] - (_.coverage - (and (|> (/.result ) - (!expect (^.multi {try.#Success actual} - (n.= expected actual)))) - (|> (/.result ) - (!expect (^.multi {try.#Success actual} - (n.= expected actual)))))))])) - -(def .public test - Test - (<| (_.covering /._) - (_.for [/.Parser]) - (all _.and - (!cover [/.result /.value] - /.value - (tree.leaf expected)) - (do [! random.monad] - [expected random.nat] - (_.coverage [/.result'] - (|> (/.result' /.value - (zipper.zipper (tree.leaf expected))) - (!expect (^.multi {try.#Success actual} - (n.= expected actual)))))) - (!cover [/.down] - (do //.monad - [_ /.down] - /.value) - (tree.branch dummy - (list (tree.leaf expected)))) - (!cover [/.up] - (do //.monad - [_ /.down - _ /.up] - /.value) - (tree.branch expected - (list (tree.leaf dummy)))) - (!cover [/.right] - (do //.monad - [_ /.down - _ /.right] - /.value) - (tree.branch dummy - (list (tree.leaf dummy) - (tree.leaf expected)))) - (!cover [/.left] - (do //.monad - [_ /.down - _ /.right - _ /.left] - /.value) - (tree.branch dummy - (list (tree.leaf expected) - (tree.leaf dummy)))) - (!cover [/.rightmost] - (do //.monad - [_ /.down - _ /.rightmost] - /.value) - (tree.branch dummy - (list (tree.leaf dummy) - (tree.leaf dummy) - (tree.leaf expected)))) - (!cover [/.leftmost] - (do //.monad - [_ /.down - _ /.rightmost - _ /.leftmost] - /.value) - (tree.branch dummy - (list (tree.leaf expected) - (tree.leaf dummy) - (tree.leaf dummy)))) - (!cover/2 [/.next] - (do //.monad - [_ /.next - _ /.next] - /.value) - (tree.branch dummy - (list (tree.branch dummy - (list (tree.leaf expected))))) - (tree.branch dummy - (list (tree.leaf dummy) - (tree.leaf expected)))) - (!cover/2 [/.previous] - (do //.monad - [_ /.next - _ /.next - _ /.previous] - /.value) - (tree.branch dummy - (list (tree.branch expected - (list (tree.leaf dummy))))) - (tree.branch dummy - (list (tree.leaf expected) - (tree.leaf dummy)))) - (!cover/2 [/.end] - (do //.monad - [_ /.end] - /.value) - (tree.branch dummy - (list (tree.branch dummy - (list (tree.leaf expected))))) - (tree.branch dummy - (list (tree.leaf dummy) - (tree.leaf expected)))) - (!cover/2 [/.start] - (do //.monad - [_ /.end - _ /.start] - /.value) - (tree.branch expected - (list (tree.branch dummy - (list (tree.leaf dummy))))) - (tree.branch expected - (list (tree.leaf dummy) - (tree.leaf dummy)))) - (do [! random.monad] - [dummy random.nat] - (_.coverage [/.cannot_move_further] - (`` (and (~~ (with_template [] - [(|> (/.result - (tree.leaf dummy)) - (!expect (^.multi {try.#Failure error} - (exception.match? /.cannot_move_further error))))] - - [/.down] [/.up] - [/.right] [/.left] - [/.next] [/.previous] - )))))) - ))) diff --git a/stdlib/source/test/lux/data/collection/tree.lux b/stdlib/source/test/lux/data/collection/tree.lux index 6e5c5fde7..f03c2725f 100644 --- a/stdlib/source/test/lux/data/collection/tree.lux +++ b/stdlib/source/test/lux/data/collection/tree.lux @@ -8,16 +8,180 @@ ["$[0]" equivalence] ["$[0]" mix] ["$[0]" functor]]] + [control + ["//" parser] + ["[0]" try] + ["[0]" exception]] [data ["[0]" product] [collection ["[0]" list (.use "[1]#[0]" functor mix)]]] + [macro + ["^" pattern]] [math ["[0]" random (.only Random)] [number ["n" nat]]]]] + ["[0]" \\parser] [\\library - ["[0]" / (.only Tree)]]) + ["[0]" / (.only Tree) + ["[0]" zipper]]]) + +(def !expect + (template (_ ) + [(case + + true + + _ + false)])) + +(def !cover + (template (_ ) + [(do [! random.monad] + [dummy random.nat + expected (|> random.nat (random.only (|>> (n.= dummy) not)))] + (_.coverage + (|> (\\parser.result + ) + (!expect (^.multi {try.#Success actual} + (n.= expected actual))))))])) + +(def !cover/2 + (template (_ ) + [(do [! random.monad] + [dummy random.nat + expected (|> random.nat (random.only (|>> (n.= dummy) not)))] + (_.coverage + (and (|> (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (n.= expected actual)))) + (|> (\\parser.result ) + (!expect (^.multi {try.#Success actual} + (n.= expected actual)))))))])) + +(def \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (all _.and + (!cover [\\parser.result \\parser.value] + \\parser.value + (/.leaf expected)) + (do [! random.monad] + [expected random.nat] + (_.coverage [\\parser.result'] + (|> (\\parser.result' \\parser.value + (zipper.zipper (/.leaf expected))) + (!expect (^.multi {try.#Success actual} + (n.= expected actual)))))) + (!cover [\\parser.down] + (do //.monad + [_ \\parser.down] + \\parser.value) + (/.branch dummy + (list (/.leaf expected)))) + (!cover [\\parser.up] + (do //.monad + [_ \\parser.down + _ \\parser.up] + \\parser.value) + (/.branch expected + (list (/.leaf dummy)))) + (!cover [\\parser.right] + (do //.monad + [_ \\parser.down + _ \\parser.right] + \\parser.value) + (/.branch dummy + (list (/.leaf dummy) + (/.leaf expected)))) + (!cover [\\parser.left] + (do //.monad + [_ \\parser.down + _ \\parser.right + _ \\parser.left] + \\parser.value) + (/.branch dummy + (list (/.leaf expected) + (/.leaf dummy)))) + (!cover [\\parser.rightmost] + (do //.monad + [_ \\parser.down + _ \\parser.rightmost] + \\parser.value) + (/.branch dummy + (list (/.leaf dummy) + (/.leaf dummy) + (/.leaf expected)))) + (!cover [\\parser.leftmost] + (do //.monad + [_ \\parser.down + _ \\parser.rightmost + _ \\parser.leftmost] + \\parser.value) + (/.branch dummy + (list (/.leaf expected) + (/.leaf dummy) + (/.leaf dummy)))) + (!cover/2 [\\parser.next] + (do //.monad + [_ \\parser.next + _ \\parser.next] + \\parser.value) + (/.branch dummy + (list (/.branch dummy + (list (/.leaf expected))))) + (/.branch dummy + (list (/.leaf dummy) + (/.leaf expected)))) + (!cover/2 [\\parser.previous] + (do //.monad + [_ \\parser.next + _ \\parser.next + _ \\parser.previous] + \\parser.value) + (/.branch dummy + (list (/.branch expected + (list (/.leaf dummy))))) + (/.branch dummy + (list (/.leaf expected) + (/.leaf dummy)))) + (!cover/2 [\\parser.end] + (do //.monad + [_ \\parser.end] + \\parser.value) + (/.branch dummy + (list (/.branch dummy + (list (/.leaf expected))))) + (/.branch dummy + (list (/.leaf dummy) + (/.leaf expected)))) + (!cover/2 [\\parser.start] + (do //.monad + [_ \\parser.end + _ \\parser.start] + \\parser.value) + (/.branch expected + (list (/.branch dummy + (list (/.leaf dummy))))) + (/.branch expected + (list (/.leaf dummy) + (/.leaf dummy)))) + (do [! random.monad] + [dummy random.nat] + (_.coverage [\\parser.cannot_move_further] + (`` (and (~~ (with_template [] + [(|> (\\parser.result + (/.leaf dummy)) + (!expect (^.multi {try.#Failure error} + (exception.match? \\parser.cannot_move_further error))))] + + [\\parser.down] [\\parser.up] + [\\parser.right] [\\parser.left] + [\\parser.next] [\\parser.previous] + )))))) + ))) (def .public (tree gen_value) (All (_ a) (-> (Random a) (Random [Nat (Tree a)]))) @@ -88,4 +252,6 @@ expected/2 {expected/3 {} expected/4 {expected/5 {}}}}))) ))) + + ..\\parser ))) diff --git a/stdlib/source/test/lux/program.lux b/stdlib/source/test/lux/program.lux index 6b462da5e..8d534dd6e 100644 --- a/stdlib/source/test/lux/program.lux +++ b/stdlib/source/test/lux/program.lux @@ -5,23 +5,91 @@ [abstract [monad (.only do)]] [control + ["<>" parser] ["[0]" io] - ["[0]" try] - ["<>" parser (.only) - ["<[0]>" cli]]] + ["[0]" try]] [data - ["[0]" text] + ["[0]" text (.use "[1]#[0]" equivalence)] [collection ["[0]" list]]] [macro [syntax (.only syntax)] + ["^" pattern] ["[0]" code ["<[1]>" \\parser]]] [math - ["[0]" random]]]] + ["[0]" random] + [number + ["n" nat (.use "[1]#[0]" decimal)]]]]] + ["[0]" \\parser] [\\library ["[0]" /]]) +(def !expect + (template (_ ) + [(case + + true + + _ + false)])) + +(def \\parser + Test + (<| (_.covering \\parser._) + (_.for [\\parser.Parser]) + (do [! random.monad] + [expected (at ! each n#encoded random.nat) + .let [random_dummy (random.only (|>> (text#= expected) not) + (random.unicode 5))] + dummy random_dummy + short (random.unicode 1) + long (random.unicode 2) + pre_ignore (random.list 5 random_dummy) + post_ignore (random.list 5 random_dummy)] + (all _.and + (_.coverage [\\parser.result \\parser.any] + (|> (\\parser.result \\parser.any (list expected)) + (!expect (^.multi {try.#Success actual} + (text#= expected actual))))) + (_.coverage [\\parser.parse] + (|> (\\parser.result (\\parser.parse n#decoded) (list expected)) + (!expect (^.multi {try.#Success actual} + (text#= expected + (n#encoded actual)))))) + (_.coverage [\\parser.this] + (and (|> (\\parser.result (\\parser.this expected) (list expected)) + (!expect {try.#Success _})) + (|> (\\parser.result (\\parser.this expected) (list dummy)) + (!expect {try.#Failure _})))) + (_.coverage [\\parser.somewhere] + (|> (\\parser.result (|> (\\parser.somewhere (\\parser.this expected)) + (<>.before (<>.some \\parser.any))) + (list.together (list pre_ignore (list expected) post_ignore))) + (!expect {try.#Success _}))) + (_.coverage [\\parser.end] + (and (|> (\\parser.result \\parser.end (list)) + (!expect {try.#Success _})) + (|> (\\parser.result (<>.not \\parser.end) (list expected)) + (!expect {try.#Failure _})))) + (_.coverage [\\parser.named] + (|> (\\parser.result (\\parser.named dummy \\parser.any) (list dummy expected)) + (!expect (^.multi {try.#Success actual} + (text#= expected actual))))) + (_.coverage [\\parser.parameter] + (and (|> (\\parser.result (\\parser.parameter [short long] \\parser.any) + (list short expected)) + (!expect (^.multi {try.#Success actual} + (text#= expected actual)))) + (|> (\\parser.result (\\parser.parameter [short long] \\parser.any) + (list long expected)) + (!expect (^.multi {try.#Success actual} + (text#= expected actual)))) + (|> (\\parser.result (\\parser.parameter [short long] \\parser.any) + (list dummy expected)) + (!expect {try.#Failure _})))) + )))) + (def actual_program (syntax (_ [actual_program (<| .form (<>.after (.this_text "lux def program")) @@ -33,43 +101,47 @@ (<| (_.covering /._) (do random.monad [inputs (random.list 5 (random.upper_case 5))] - (_.coverage [/.program:] - (let [(open "list#[0]") (list.equivalence text.equivalence)] - (and (with_expansions [ (/.program: all_arguments - (io.io all_arguments))] - (let [outcome ((is (-> (List Text) (io.IO Any)) - (..actual_program )) - inputs)] - (same? (is Any inputs) - (io.run! outcome)))) - (with_expansions [ (/.program: [arg/0 .any - arg/1 .any - arg/2 .any - arg/3 .any - arg/4 .any] - (io.io (list arg/4 arg/3 arg/2 arg/1 arg/0)))] - (let [outcome ((is (-> (List Text) (io.IO Any)) - (..actual_program )) - inputs)] - (list#= (list.reversed inputs) - (as (List Text) (io.run! outcome))))) - (with_expansions [ (/.program: [all_arguments (<>.many .any)] - (io.io all_arguments))] - (let [outcome ((is (-> (List Text) (io.IO Any)) - (..actual_program )) - inputs)] - (list#= inputs - (as (List Text) (io.run! outcome))))) - (with_expansions [ (/.program: [arg/0 .any - arg/1 .any - arg/2 .any - arg/3 .any] - (io.io []))] - (case (try ((is (-> (List Text) (io.IO Any)) - (..actual_program )) - inputs)) - {try.#Success _} - false - - {try.#Failure _} - true)))))))) + (all _.and + (_.coverage [/.program:] + (let [(open "list#[0]") (list.equivalence text.equivalence)] + (and (with_expansions [ (/.program: all_arguments + (io.io all_arguments))] + (let [outcome ((is (-> (List Text) (io.IO Any)) + (..actual_program )) + inputs)] + (same? (is Any inputs) + (io.run! outcome)))) + (with_expansions [ (/.program: [arg/0 \\parser.any + arg/1 \\parser.any + arg/2 \\parser.any + arg/3 \\parser.any + arg/4 \\parser.any] + (io.io (list arg/4 arg/3 arg/2 arg/1 arg/0)))] + (let [outcome ((is (-> (List Text) (io.IO Any)) + (..actual_program )) + inputs)] + (list#= (list.reversed inputs) + (as (List Text) (io.run! outcome))))) + (with_expansions [ (/.program: [all_arguments (<>.many \\parser.any)] + (io.io all_arguments))] + (let [outcome ((is (-> (List Text) (io.IO Any)) + (..actual_program )) + inputs)] + (list#= inputs + (as (List Text) (io.run! outcome))))) + (with_expansions [ (/.program: [arg/0 \\parser.any + arg/1 \\parser.any + arg/2 \\parser.any + arg/3 \\parser.any] + (io.io []))] + (case (try ((is (-> (List Text) (io.IO Any)) + (..actual_program )) + inputs)) + {try.#Success _} + false + + {try.#Failure _} + true))))) + + ..\\parser + )))) diff --git a/stdlib/source/test/lux/tool/compiler/meta/cli.lux b/stdlib/source/test/lux/tool/compiler/meta/cli.lux index fe630e128..dcf28757f 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/cli.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/cli.lux @@ -5,10 +5,9 @@ [abstract [monad (.only do)]] [control + ["<>" parser] ["[0]" pipe] - ["[0]" try (.use "[1]#[0]" functor)] - ["<>" parser (.only) - ["<[0]>" cli]]] + ["[0]" try (.use "[1]#[0]" functor)]] [data ["[0]" product] ["[0]" text] @@ -20,7 +19,9 @@ ["n" nat]]] [meta ["[0]" configuration (.use "[1]#[0]" equivalence) - ["$[1]" \\test]]]]] + ["$[1]" \\test]]] + ["[0]" program + ["<[1]>" \\parser]]]] [\\library ["[0]" / (.only) ["[1][0]" compiler (.only Compiler)]]] @@ -58,7 +59,7 @@ (~~ (with_template [ ] [(_.coverage [] (|> (list.partial "build" compilation') - (.result /.service) + (.result /.service) (try#each (|>> (pipe.case {/.#Compilation it} (|> it @@ -81,7 +82,7 @@ (_.coverage [/.Interpretation] (`` (and (~~ (with_template [ ] [(|> (list.partial "repl" compilation') - (.result /.service) + (.result /.service) (try#each (|>> (pipe.case {/.#Interpretation it} (|> it @@ -103,7 +104,7 @@ (_.coverage [/.Export] (`` (and (~~ (with_template [ ] [(|> (list.partial "export" export) - (.result /.service) + (.result /.service) (try#each (|>> (pipe.case {/.#Export it} (|> it -- cgit v1.2.3