Commit Graph

112 Commits

Author SHA1 Message Date
rvcas
703fcb451d fix(parser,windows): capture carriage return properly 2023-01-26 10:16:29 -05:00
KtorZ
5d7585cc05 Implement parser for when clause guard
With pretty parse errors on failures. The type-checker was already
  implemented for those, so it now only requires some work in the code
  generation.

  Fixes #297.
2023-01-21 17:43:13 +01:00
KtorZ
333a990249 Fix parsing of subtractions and negations in the absence of space. 2023-01-21 12:43:11 +01:00
KtorZ
2d99c07dd3 Support (and default to) parenthesis for block expressions
This changes allow to use parenthesis `(` `)` to encapsulate
  expressions in addition to braces `{` `}` used to define blocks.

  The main use-case is for arithmetic and boolean expressions for which
  developers are used to using parenthesis. For example:

  ```
  { 14 + 42 } * 1337
  ```

  can now be written as:

  ```
  ( 14 + 42 ) * 1337
  ```

  This may sound straightforward at first but wasn't necessarily trivial
  in Aiken given that (a) everything is an expression, (b) whitespaces
  do not generally matter and (c) there's no symbol indicating the end
  of a 'statement' (because there's no statement).

  Thus, we have to properly disambiguate between:

  ```
  let foo = bar(14 + 42)
  ```

  and

  ```
  let foo = bar
  (14 + 42)
  ```

  Before this commit, the latter would be interpreted as a function call
  and would lead to a somewhat puzzling error. Now, the newline serves
  as a delimiting symbol. The trade-off being that for a function call,
  the left parenthesis has to be on the same line as the function name
  identifier -- which is a fair trade off. So this is still allowed:

  ```
  let foo = bar(
    14 + 42
  )
  ```

  As there's very little ambiguity about it.

  This fixes #236 and would seemingly allow us to get rid of the leading
  `#` in front of tuples.
2023-01-14 11:49:45 -05:00
KtorZ
85a6a711e1 Add more colors to error messages.
And, let 'formatdoc' insert newlines when relevant to
  format the text to the same column length.
2022-12-29 17:38:34 +01:00
KtorZ
3139c85fe8 Support declaring bytearray literals as base16 strings. 2022-12-29 13:08:58 +01:00
Kasey White
083b7fcb5f feat: support negation of int
* add unary op
* parse, typecheck, and code gen it
* express boolean not as unary op as well, previously called negate

Co-authored-by: rvcas <x@rvcas.dev>
2022-12-27 20:39:03 -05:00
rvcas
37196a29ee feat: error keyword 2022-12-23 15:52:44 -05:00
KtorZ
69f060e675 Rework all errors to provide better help text. 2022-12-23 19:27:06 +01:00
KtorZ
5cf9742e5e Move tuple-index hint as diagnostic's help 2022-12-22 18:52:28 +01:00
KtorZ
bf7cdfba73 Implement parser & type-checker for tuple indexes.
```aiken
  fn foo() {
    let tuple = #(1, 2, 3, 4)
    tuple.1st + tuple.2nd + tuple.3rd + tuple.4th
  }
  ```
2022-12-22 09:14:23 +01:00
rvcas
42204d2d71 chore: make folder names match crate name 2022-12-21 18:11:07 -05:00