Skip to content

Commit

Permalink
remove Maybe Bool pattern in 'visible names' JSON, tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-yac committed Apr 13, 2023
1 parent e8fc8f3 commit 6b2154f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cryptol-remote-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Revision history for `cryptol-remote-api` and `cryptol-eval-server`

## 2.13.2 -- YYYY-MM-DD
## NEXT -- YYYY-MM-DD

* Add more fields (such as `pragmas`, `parameter`, `module`, and `infix`) to
the response to the RPC `visible names` method.
Expand Down
2 changes: 1 addition & 1 deletion cryptol-remote-api/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Revision history for `cryptol` Python package

## 2.13.2 -- YYYY-MM-DD
## NEXT -- YYYY-MM-DD

* Add `property_names` and `parameter_names` commands, used to get only those
loaded names which are properties or module parameters, respectively.
Expand Down
4 changes: 2 additions & 2 deletions cryptol-remote-api/python/tests/cryptol/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def test_names(self):
# names()

expected_names = [
{'module': 'Names', 'name': 'key', 'parameter': True },
{'module': 'Names', 'name': 'key', 'parameter': [] },
{'module': 'Names', 'name': 'enc' },
{'module': 'Names', 'name': 'enc_correct', 'pragmas': ['property'] },
{'module': 'Names', 'name': 'prim' },
{'module': 'Names', 'name': '(-!)', 'infix': True, 'infix associativity': 'left-associative', 'infix level': 100 }
{'module': 'Names', 'name': '(-!)', 'infix': {'associativity': 'left-associative', 'level': 100} }
]

names_to_check = filter_names(names(), module="Names", fields_to_exclude=["type", "type string"])
Expand Down
24 changes: 10 additions & 14 deletions cryptol-remote-api/src/CryptolServer/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,15 @@ instance Doc.DescribedMethod VisibleNamesParams [NameInfo] where
, ("module",
Doc.Paragraph [Doc.Text "A human-readable representation of the module from which the name originates"])
, ("parameter",
Doc.Paragraph [ Doc.Text "An optional field which is present and ",
Doc.Literal "True", Doc.Text " iff the name is a module parameter" ])
Doc.Paragraph [ Doc.Text "An optional field which is present iff the name is a module parameter" ])
, ("infix",
Doc.Paragraph [ Doc.Text "An optional field which is present and ",
Doc.Literal "True", Doc.Text " iff the name is an infix operator" ])
, ("infix associativity",
Doc.Paragraph [ Doc.Text "An optional field containing one of the strings ",
Doc.Paragraph [ Doc.Text "An optional field which is present iff the name is an infix operator. ",
Doc.Text "If present, it contains an object with two fields. One field is ",
Doc.Literal "associativity", Doc.Text ", containing one of the strings ",
Doc.Literal "left-associative", Doc.Text ", ",
Doc.Literal "right-associative", Doc.Text ", or ",
Doc.Literal "non-associative", Doc.Text " if the name is an infix operator" ])
, ("infix level",
Doc.Paragraph [ Doc.Text "An optional field containing the name's precedence level, ",
Doc.Text "if the name is an infix operator" ])
Doc.Literal "non-associative", Doc.Text ", and the other is ",
Doc.Literal "level", Doc.Text ", containing the name's precedence level." ])
, ("pragmas",
Doc.Paragraph [ Doc.Text "An optional field containing a list of the name's pragmas (e.g. ",
Doc.Literal "property", Doc.Text "), if it has any"])
Expand Down Expand Up @@ -122,10 +118,10 @@ instance JSON.ToJSON NameInfo where
, "type" .= JSONSchema schema
, "module" .= modl
] ++
(if isParam then ["parameter" .= isParam] else []) ++
(if isParam then ["parameter" .= ()] else []) ++
maybe [] (\(assoc, lvl) ->
[ "infix" .= True
, "infix associativity" .= assoc
, "infix level" .= lvl ]) fixity ++
["infix" .= JSON.object
[ "associativity" .= assoc
, "level" .= lvl ]]) fixity ++
(if null pragmas then [] else ["pragmas" .= pragmas]) ++
maybe [] (\d -> ["documentation" .= d]) nameDocs

0 comments on commit 6b2154f

Please sign in to comment.