Skip to content

Commit

Permalink
fix: Grammar
Browse files Browse the repository at this point in the history
A bunch of small fixes combined in a single commit:
1) Variable idenfiers live inside a different namespace than type names,
   so we don't need to check for clashes.
2) Witness names should begin with a letter. This ensures that
   witness::NAME is valid Rust.
3) Jet names include the trailing `::`, so they cannot clash with
   function names.
4) Type aliases must not redefine a builtin type such as `bool`.
  • Loading branch information
uncomputable committed Dec 12, 2024
1 parent 03c1425 commit 436f610
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/minimal.pest
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ statement = { assignment | expression }
expression = { block_expression | single_expression }
block_expression = { "{" ~ (statement ~ ";")* ~ expression? ~ "}" }

identifier = @{ !builtin_type ~ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
identifier = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
jet = @{ "jet::" ~ (ASCII_ALPHANUMERIC | "_")+ }
witness_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
witness_name = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
builtin_type = @{ ("Either" | "Option" | "bool" | "List" | unsigned_type) ~ !ASCII_ALPHANUMERIC }

builtin_function = @{ (jet | "unwrap_left" | "unwrap_right" | "for_while" | "is_none" | "unwrap" | "assert" | "panic" | "match" | "into" | "fold" | "dbg") ~ !ASCII_ALPHANUMERIC }
builtin_function = @{ ("unwrap_left" | "unwrap_right" | "for_while" | "is_none" | "unwrap" | "assert" | "panic" | "match" | "into" | "fold" | "dbg") ~ !ASCII_ALPHANUMERIC }
function_name = { !builtin_function ~ identifier }
typed_identifier = { identifier ~ ":" ~ ty }
function_params = { "(" ~ (typed_identifier ~ ("," ~ typed_identifier)*)? ~ ")" }
Expand Down Expand Up @@ -47,7 +47,7 @@ list_bound = @{ ASCII_DIGIT+ }
list_type = { "List<" ~ ty ~ "," ~ list_bound ~ ">" }
ty = { alias_name | builtin_alias | sum_type | option_type | boolean_type | unsigned_type | tuple_type | array_type | list_type }
builtin_alias = @{ "Ctx8" | "Pubkey" | "Message64" | "Message" | "Signature" | "Scalar" | "Fe" | "Gej" | "Ge" | "Point" | "Height" | "Time" | "Distance" | "Duration" | "Lock" | "Outpoint" | "Confidential1" | "ExplicitAsset" | "Asset1" | "ExplicitAmount" | "Amount1" | "ExplicitNonce" | "Nonce" | "TokenAmount1" }
alias_name = { !builtin_alias ~ identifier }
alias_name = { !builtin_type ~ !builtin_alias ~ identifier }
type_keyword = @{ "type" ~ !ASCII_ALPHANUMERIC }
type_alias = { type_keyword ~ alias_name ~ "=" ~ ty ~ ";" }

Expand Down

0 comments on commit 436f610

Please sign in to comment.