Commit Graph

112 Commits

Author SHA1 Message Date
KtorZ
4f6defcf3e rename: 'r' → 'expression' & 'seq_r' → 'sequence'
Better readability.
2023-07-05 14:42:14 +02:00
KtorZ
66296df9c3 Move parsing of literals under new 'literal' parser module group
Also moved the logic for 'int' and 'string' there though it is trivial. Yet, for bytearray, it tidies things nicely by removing them from the 'utils' module.
2023-07-05 14:37:29 +02:00
KtorZ
e15cdaf248 Move 'utils::bytearray' to 'expr/bytearray' 2023-07-05 14:10:47 +02:00
KtorZ
44eb501d78 Favor pattern-match over if-else when parsing assignment kinds
Equality on a union-type is potentially dangerous as the compiler won't
complain if we add a new case that we don't cover. Reversing the
assignment by yielding a `Token` for a given `AssignmentKind`. This way
we can use a pattern-match that got us covered for future cases.
2023-07-05 14:01:13 +02:00
KtorZ
93e010b345 Replace 'public' utils with a more generic 'optional_flag'
The 'public' util was arguably not really adding much except a layer of indirection.
  In the end, one useful parsing behavior to abstract is the idea of 'optional flag' that we use for both 'pub' and 'opaque' keywords.
2023-07-05 13:57:34 +02:00
rvcas
5e8edcb340 test(parser): finish moving tests to their correct modules 2023-07-04 17:48:48 -04:00
rvcas
47567c5e6f test(parser): some adjustments after rebase with @ktorz fix 2023-07-04 17:19:30 -04:00
rvcas
b25db429be test(parser): anon binop and ambiguous sequence 2023-07-04 17:19:30 -04:00
rvcas
8a6c81493c test(parser): record create 2023-07-04 17:19:30 -04:00
rvcas
a75bcff5c8 test(parser): type alias, anon fn, record update and more 2023-07-04 17:19:30 -04:00
rvcas
bd8c13c372 test(parser): move over the validator tests and some misc tests to parser 2023-07-04 17:19:29 -04:00
rvcas
6b05d6a91e test(parser): rename definitions to definition and more tests 2023-07-04 17:19:29 -04:00
rvcas
baf807ca2d test(parser): list spread 2023-07-04 17:19:29 -04:00
rvcas
44d0432560 test(parser): int list 2023-07-04 17:19:29 -04:00
rvcas
f9c099a923 test: add indoc to assert_expr macro 2023-07-04 17:19:29 -04:00
rvcas
715752718d test: assert_module 2023-07-04 17:19:29 -04:00
rvcas
8a7df7f66b test: add empty list test 2023-07-04 17:19:29 -04:00
rvcas
f878ef7cef feat: move some token processing to the lexer 2023-07-04 17:19:28 -04:00
rvcas
2226747dc1 feat: finish splitting up parsers 2023-07-04 17:19:28 -04:00
rvcas
eea94fc9a4 feat: move anon fn, let, and expect 2023-07-04 17:19:28 -04:00
rvcas
9c98fc8026 feat: start splitting apart expr_parser 2023-07-04 17:19:28 -04:00
rvcas
e3ed5d3b00 feat: move expr_parser and remove module.rs to definitions 2023-07-04 17:19:28 -04:00
rvcas
3339d41fdd feat: finish moving definitions and start exprs 2023-07-04 17:19:27 -04:00
rvcas
fc580d4fa0 feat(parser): move definitions to their own modules 2023-07-04 17:19:27 -04:00
KtorZ
5a6cc855e6 Use byte count for token span in the lexer.
Somehow, miette doesn't play well with spans when using chars indices.
  So we have to count the number of bytes in strings / chars, so that
  spans align accordingly.
2023-07-04 16:51:59 -04:00
KtorZ
6bd8e94e17 Preserve numeric underscore and hexadecimal notation through formatting. 2023-06-08 16:37:20 +02:00
KtorZ
79a2174f0a Extend parser to support int as hexadecimal and numeric underscore.
We only allow numeric underscore for decimal numbers as I am not sure how we can define it for non-decimal numbers?
2023-06-08 15:33:50 +02:00
rvcas
1747090931 fix: fmt crashing with comment at end of file
closes #568
2023-06-07 15:59:54 -04:00
rvcas
26a607eb00 fix: bad parsing of comments at end of file closes #551 2023-05-30 11:07:39 -04:00
rvcas
7b3e1c6952 feat: adjust failing test syntax
* also add a formatter test
2023-05-25 18:21:12 -04:00
rvcas
a124a16a61 feat(tests): implement a way to express that tests can fail 2023-05-25 16:54:53 -04:00
rvcas
baa2cef6c4 feat(playground): impl clone for some errors 2023-04-24 17:13:20 -04:00
rvcas
1444c9328d fix some typos 2023-04-07 16:51:18 -04:00
KtorZ
8a2af4cd2e Fix lexer throwing errors when parsing a too large tuple index. 2023-03-18 16:13:50 +01:00
KtorZ
1311d9bd27 Support flexible pipe operator formatting
Rules are now as follows:

  - If a pipeline contains a newline, then the entire pipeline is formatted over multiple lines.
  - If it doesn't, then it's formatted as a single-line UNLESS it cannot fit; in which case, we fallback to multiline again.
2023-03-14 16:47:43 -04:00
KtorZ
a46a9fca41 Only use colors & text decorations on ANSI-capable terminals.
Fixes #404.
2023-02-26 13:19:03 +01:00
KtorZ
539ed2dea4 Fix unicode char parsing in comments. 2023-02-22 17:33:13 +01:00
KtorZ
f307e214c3 Remove parse error on bytearray literals for trace, todo & error, parse as String instead.
This has been bothering me and the more I thought of it the more I
  disliked the idea of a warning. The rationale being that in this very
  context, there's absolutely no ambiguity. So it is only frustrating
  that the parser is even able to make the exact suggestion of what
  should be fixed, but still fails.

  I can imagine it is going to be very common for people to type:

  ```
  trace "foo"
  ```

  ...yet terribly frustrating if they have to remember each time that
  this should actually be a string. Because of the `trace`, `todo` and
  `error` keywords, we know exactly the surrounding context and what to
  expect here. So we can work it nicely.

  However, the formatter will re-format it to:

  ```
  trace @"foo"
  ```

  Just for the sake of remaining consistent with the type-system. This
  way, we still only manipulate `String` in the AST, but we conveniently
  parse a double-quote utf-8 literal when coupled with one of the
  specific keywords.

  I believe that's the best of both worlds.
2023-02-19 10:10:42 +01:00
KtorZ
d72e13c7c8 Emit parse error when finding a ByteArray literal instead of String literal. 2023-02-19 10:10:42 +01:00
KtorZ
53fb821b62 Use double-quotes for utf-8 bytearrays, and @"..." for string literals
The core observation is that **in the context of Aiken** (i.e. on-chain logic)
  people do not generally want to use String. Instead, they want
  bytearrays.

  So, it should be easy to produce bytearrays when needed and it should
  be the default. Before this commit, `"foo"` would parse as a `String`.
  Now, it parses as a `ByteArray`, whose bytes are the UTF-8 bytes
  encoding of "foo".

  Now, to make this change really "fool-proof", we now want to:

  - [ ] Emit a parse error if we parse a UTF-8 bytearray literal in
    place where we would expect a `String`. For example, `trace`,
    `error` and `todo` can only be followed by a `String`.

    So when we see something like:

    ```
    trace "foo"
    ```

    we know it's a mistake and we can suggest users to use:

    ```
    trace @"foo"
    ```

    instead.

  - [ ] Emit a warning if we ever see a bytearray literals UTF-8, which
    is either 56 or 64 character long and is a valid hexadecimal string.
    For example:

    ```
    let policy_id = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6"
    ```

    This is _most certainly_ a mistake, as this generates a ByteArray of
    56 bytes, which is effectively the hex-encoding of the provided string.

    In this scenario, we want to warn the user and inform them they probably meant to use:

    ```
    let policy_id = #"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6"
    ```
2023-02-19 10:09:22 +01:00
KtorZ
4a22e5f656 Fix module comment parsing / formatting after bumping chumsky to 0.9.0 2023-02-17 14:07:24 +01:00
KtorZ
6a50bde666 Implement parser & formater for 'TraceIfFalse'
Interestingly enough, chumsky seems to fail when given a 'choice' with
  more than 25 elements. That's why this commit groups together some of
  the choices as another nested 'choice'.
2023-02-16 20:29:41 -05:00
rvcas
a88a193383 fix: properly lex new token and adjust parsed spans 2023-02-16 00:05:55 -05:00
rvcas
2e7fe191db feat(definitions):
* add parsing for new validator defs
* start adding typechecking
* add a unit test for parsing
2023-02-16 00:05:55 -05:00
rvcas
dbd162e985 feat: handle expect in parser
* map both assert/expect to Token::Expect
* use the new token in the parser
* new unit test to expect
2023-02-09 00:43:29 -05:00
rvcas
5a4a8df727 feat(token): add Token::Expect 2023-02-09 00:25:54 -05:00
rvcas
88ce8ba8b9 feat: remove check assignment 2023-02-01 23:03:35 -05:00
rvcas
21251d6499 fix: remove check from lexer 2023-02-01 20:44:58 -05:00
rvcas
a365649360 chore: clippy autofix 2023-02-01 18:53:11 -05:00
Lucas
b653714c0c Merge branch 'main' into when-clause-guards 2023-01-30 11:40:29 -05:00