Skip to content

Commit

Permalink
Add tokenization step to parsing pipeline, add support for options
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Feb 4, 2024
1 parent eb84d32 commit 732c3e5
Show file tree
Hide file tree
Showing 10 changed files with 1,043 additions and 172 deletions.
107 changes: 106 additions & 1 deletion cli-contract.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,121 @@ let normString : String -> String =
in
let TrimmedString : _ -> String -> String = fun _label => normString
in
let NotRequiredIfList = fun label args =>
args
|> std.array.map
(
fun arg =>
if arg."type" == 'List-Text then
if std.record.has_field "optional" arg && arg."optional" == false then
std.contract.blame_with_message
(
"Incorrect values for argument "
++ arg.name
++ ": Arguments of type "
++ std.string.from_enum arg.type
++ " must always be optional"
)
label
else
arg
else
arg
)
in
let EitherNameOrShortName = fun label options =>
options
|> std.array.map
(
fun option =>
let nameIsSet =
std.record.has_field "name" option
&& option.name != ""
in
let shortNameIsSet =
std.record.has_field "shortName" option
&& option.shortName != ""
in
if !nameIsSet && !shortNameIsSet then
std.contract.blame_with_message
"Option must have either a name or a shortName"
label
else
option
)
in
let Argument = {
name | String,
description | String,
type
| [|
'Text,
'Int,
'Float,
'Bool,
'List-Text,
'List-Int,
'List-Float,
'List-Bool,
|],
"optional"
| optional
| Bool,
"default"
| optional
| String
| Number
| Bool
| Array String
| Array Number
| Array Bool,
}
in
let Option = {
name
| doc "The name of the option (without the leading --)"
| optional
| TrimmedString,
shortName
| doc "The short name of the option"
| optional
| std.string.Character,
description
| doc "The description of the option"
| TrimmedString,
argument
| doc "The argument of the option"
| optional
| Argument
| EitherNameOrShortName,
"optional"
| optional
| Bool,
"default"
| optional
| String
| Number
| Bool
| Array String
| Array Number
| Array Bool,
}
in
let Command = {
name
| doc "The name of the command"
| TrimmedString,
description
| doc "The description of the command"
| TrimmedString,
options
| doc "The list of options"
| optional
| Array Option,
arguments
| doc "The list of arguments"
| Array String,
| Array Argument
| NotRequiredIfList,
funcName
| doc "The function to be called"
| optional
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ src/CliSpec/JsonEmbed.purs: cli-contract.ncl cli-spec.ncl

echo \
'(import "cli-contract.ncl") & (import "cli-spec.ncl")' \
| nickel export --format json \
| nickel --color=always export --format json \
>> $@

echo '"""' >> $@
Expand Down
13 changes: 13 additions & 0 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ workspace:
- rationals
- result
- strings
- stringutils
- transformers
- tuples
- unfoldable
Expand Down Expand Up @@ -117,6 +118,7 @@ workspace:
- spec
- st
- strings
- stringutils
- tailrec
- test-unit
- transformers
Expand Down Expand Up @@ -1491,6 +1493,17 @@ packages:
- tuples
- unfoldable
- unsafe-coerce
stringutils:
type: registry
version: 0.0.12
integrity: sha256-t63QWBlp49U0nRqUcFryKflSJsNKGTQAHKjn24/+ooI=
dependencies:
- arrays
- integers
- maybe
- partial
- prelude
- strings
tailrec:
type: registry
version: 6.1.0
Expand Down
1 change: 1 addition & 0 deletions spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package:
- rationals
- result
- strings
- stringutils
- transformers
- tuples
- unfoldable
Expand Down
Loading

0 comments on commit 732c3e5

Please sign in to comment.