Skip to content

Commit

Permalink
start documenting productions + lexical syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Dec 11, 2023
1 parent 948076f commit 757856e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pact-core-tests/Pact/Core/Test/LexerParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ tokenGen = Gen.choice $ unary ++ [ TokenIdent <$> identGen, number, string]
number = do
n <- Gen.int $ Range.linear (-1000) 1000
pure . TokenNumber $ T.pack $ show n
-- Todo: maybe we separate into keyword + ident
-- and num and turn this into an enum bounded call
unary = Gen.constant
<$> [ TokenLet
, TokenIf
, TokenLambda
, TokenTry
, TokenError
, TokenModule
, TokenKeyGov
, TokenCapGov
, TokenInterface
, TokenImport
Expand Down
72 changes: 71 additions & 1 deletion pact-core/Pact/Core/Semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,79 @@ This document should serve as a record of known pact semantics, covering as much

Bullet points that are not filled are potential tasks

## Pact Syntax

EBNF of Pact, Roughly speaking

### Legend
| Usage | Notation | Meaning |
| ------------- | :--------: | ------- |
| concatenation | | One token immediately follows another
| alternation | \| | One or the order
| optional | \[ ... \] | none or once
| repetition | \{ ... \} | none or many
| grouping | \( ... \) | Groups tokens to match


### Lexical Syntax


```
lower ::= 'a' | ... | 'z' (Ascii only, no unicode lower case)
upper ::= 'A' | ... | 'Z' (Ascii only, no unicode lower case)
special-symbol ::= '%' | '#' | '+' | '-' | '_' | '&' | '$' | '@'
| '<' | '>' | '=' | '^' | '?' | '*' | '!'
| '|' | '/' | '~'
alpha ::= lower | upper
parens ::= '(' | ')'
brackets ::= '[' | ']'
braces ::= '{' | '}'
digit ::= '0' | ... | '9'
comment ::= ';' "any sequence of characters up until newline"
colon ::= ':'
bind-assign ::= ':' '='
dot ::= '.'
comma ::= ','
nl ::= "new line character"
IDENT ::= (alpha | special-symbol) {alpha | special-symbol | digit}
STRING ::= '"' {any character that is not a line break} '"'
TICKSTRING ::= '\'' alpha {alpha | digit | '-' | '_'}
```

### Keywords

| | | |
| :--------: | :--------: | :--------: |
| let | let* | if |
| defun | defcap | defconst |
| defschema | deftable | defpact |
| defproperty | property | invariant |
| interface | module | bless |
| implements | use | true |
| false | lambda | and |
| or | load | @doc |
| @model | @event | @managed |
| step | step-with-rollback | enforce |
| enforce-one | with-capability | create-user-guard |
| try | error | progn |

#### Productions
TODO: fill
```
<program> ::= <toplevel> { <toplevel> }
<toplevel> ::= <module> | <interface> | <use> | <expr>
<module> ::= '(' module IDENT <Governance> <MDocOrModuleModel> <ExtOrDefs> ')'
<interface> ::= '(' interface IDENT <MDocOrModel> <ImportOrIfDef> ')'
```


## Modules

### Module Lexing and Parsing
### Module Lexing and Parsing Implementation
- [x] `module` keyword
- [x] Governance forms: keyed governance (via Keyset name string) or cap governance bare name resolution
- [x] use, bless and implements forms
Expand Down
4 changes: 0 additions & 4 deletions pact-core/Pact/Core/Syntax/LexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ data Token
| TokenTry
| TokenError
| TokenModule
| TokenKeyGov
| TokenCapGov
| TokenInterface
| TokenImport
| TokenStep
Expand Down Expand Up @@ -286,8 +284,6 @@ renderTokenText = \case
TokenTry -> "try"
TokenError -> "error"
TokenModule -> "module"
TokenKeyGov -> "keyGov"
TokenCapGov -> "capGov"
TokenInterface -> "interface"
TokenImport -> "use"
TokenStep -> "step"
Expand Down
3 changes: 0 additions & 3 deletions pact-core/Pact/Core/Syntax/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ tokens :-
defconst { token TokenDefConst }
defschema { token TokenDefSchema }
deftable { token TokenDefTable }
defcap { token TokenDefCap }
defpact { token TokenDefPact }
defproperty { token TokenDefProperty }
property { token TokenProperty }
Expand All @@ -67,8 +66,6 @@ tokens :-
use { token TokenImport }
true { token TokenTrue }
false { token TokenFalse }
keyGov { token TokenKeyGov }
capGov { token TokenCapGov }
lambda { token TokenLambda }

and { token TokenAnd }
Expand Down
2 changes: 0 additions & 2 deletions pact-core/Pact/Core/Syntax/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ import Pact.Core.Syntax.LexUtils
module { PosToken TokenModule _ }
interface { PosToken TokenInterface _ }
import { PosToken TokenImport _ }
keygov { PosToken TokenKeyGov _ }
capgov { PosToken TokenCapGov _ }
defun { PosToken TokenDefun _ }
defcap { PosToken TokenDefCap _ }
defconst { PosToken TokenDefConst _ }
Expand Down

0 comments on commit 757856e

Please sign in to comment.