361 Commits

Author SHA1 Message Date
Emre Şafak
9c1e3bf8fb Improve error message for keywords as parameters (#25052)
A function with an illegal parameter name like
```nim
proc myproc(type: int) =
  echo type
```
would uninformatively fail like so:
```nim
tkeywordparam.nim(1, 13) Error: expected closing ')'
```

This commit makes it return the following error:
```nim
tkeywordparam.nim(1, 13) Error: 'type' is a keyword and cannot be used as a parameter name
```

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Emre Şafak <esafak@users.noreply.github.com>
Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-07-14 23:15:02 +02:00
metagn
032da90ed1 implement parser for new case objects (#24885)
refs https://github.com/nim-lang/RFCs/issues/559

Parses as an `nkIdentDefs` with an `nkEmpty` name. Pragma is allowed,
can remove this if necessary.

Fine to close and postpone for later
2025-04-18 05:34:21 +02:00
metagn
3d14381473 fix stmtlist expression indent regression (#24883)
follows up #24855

Before #24855, the test would work because the indentation of the `;`
token would be passed to `semiStmtList` and so its indentation of `-1`
would be used. Now the `;` token is skipped and the indentation of the
first `discard` is used which is > -1. However the second discard has an
indentation of -1 because it's on the same line: this fails the
`sameInd(p) or realInd(p)` check since -1 is never >= the indent of the
first discard.

For compatibility with the parser up to this point this indent check is
entirely removed, meaning the indent is ignored. Because the `;` is
basically never on a separate line, this was already the case for
basically every use. `semiStmtList` is wrapped in a `withInd` anyway
which resets the indent after it's done, since the entire statement list
is wrapped in a `()`. To disallow dedents, the above check could be
fixed to use `sameOrNoInd` instead of `sameInd`, which is done in the
commented version of this check.
2025-04-17 00:44:31 +03:00
metagn
918f972369 skip semicolon in stmtlist expr parsing (#24855)
Previously it would try to parse the semicolon as its own statement and
produce an `nkEmpty` node

Also more than 1 semicolon in an expression list i.e. `(a;; b)` gives an
"expression expected" error in `semiStmtList` when multiple semicolons
are allowed in normal statements, this could be fixed by changing the
`if tok.kind == tokSemicolon` check to a `while` but it does not match
the grammar so not done here.
2025-04-11 03:29:20 +02:00
metagn
00ac961ab1 require not nil to be on the same line after a type (#24134)
fixes #23565
2024-09-18 22:45:19 +02:00
Andreas Rumpf
6c4c60eade Adds support for custom ASTs in the Nim parser (#23417) 2024-03-18 20:27:00 +01:00
Nikolay Nikolov
37ed8c8480 * fixed nimsuggest crash with 'Something = concept' put (erroneously) outside of a 'type' block (#23331) 2024-02-24 07:55:23 +01:00
Silly Carbon
243f1e6cd5 Fixes #23085: update grammars for 'concept' (#23256)
Fixes #23085
2024-01-26 08:03:41 +01:00
Jake Leahy
0bd4d80238 Allow parseAll to parse statements separated by semicolons (#23088)
Fixes the second issue listed in #9918.

Fixed by replacing the logic used in `parseAll` with just a continious
loop to `complexOrSimpleStmt` like what the [normal parser
does](https://github.com/nim-lang/Nim/blob/devel/compiler/passes.nim#L143-L146).
`complexOrSimpleStmt` [guarantees
progress](https://github.com/nim-lang/Nim/blob/devel/compiler/parser.nim#L2541)
so we don't need to check progress ourselves.

Also allows `nimpretty` to parse more valid Nim code such as 
```nim
proc foo(); # Would complain about indention here
# ...
proc foo() = 
  # ...
```
2023-12-17 09:01:00 +01:00
ringabout
cca5684a17 fixes yet another strictdefs bug (#23069) 2023-12-15 08:13:25 +01:00
Andreas Rumpf
cd4ecddb30 nimpretty: check the rendered AST for wrong output (#23057) 2023-12-13 10:39:10 +01:00
Jacek Sieka
e1a0ff1b8a lexer cleanups (#23037)
* remove some dead code and leftovers from past features
* fix yaml printing of uint64 literals
2023-12-06 18:17:57 +01:00
ringabout
e17237ce9d prepare for the enforcement of std prefix (#22873)
follow up https://github.com/nim-lang/Nim/pull/22851
2023-10-29 14:48:11 +01:00
metagn
ba158d73dc type annotations for variable tuple unpacking, better error messages (#22611)
* type annotations for variable tuple unpacking, better error messages

closes #17989, closes https://github.com/nim-lang/RFCs/issues/339

* update grammar

* fix test
2023-09-01 06:26:53 +02:00
ringabout
93ced31353 use strictdefs for compiler (#22365)
* wip; use strictdefs for compiler

* checkpoint

* complete the chores

* more fixes

* first phase cleanup

* Update compiler/bitsets.nim

* cleanup
2023-08-06 14:26:21 +02:00
Khaled Hammouda
dce714b259 Fix grammar top rule (#22325)
change stmt to complexOrSimpleStmt in the top grammar rule
2023-07-24 19:48:41 +02:00
metagn
e0ad71a912 make binary not not parse complex expressions on right side (#22078)
* binary `not` only parses simple expressions

fixes #16324

* switch to primary
2023-06-12 06:22:50 +02:00
metagn
2ab948ce53 post expr blocks colon fix + correct grammar (#21983)
* post expr blocks colon fix + correct grammar

fixes #21982

* fix dochelpers

* this is remarkably common

* use head for unchained

* fix atlas

* final grammar fix
2023-06-06 06:53:21 +02:00
metagn
ba698d37c3 some Token refactors (#21762)
* test some Token refactors

* fix CI

* showcase for more reductions, will revert

* Revert "showcase for more reductions, will revert"

This reverts commit 5ba48591f4.

* make line and column int32

* remove int32 change
2023-05-06 21:27:28 +02:00
metagn
2a0d8a9a06 make grammar a bit more honest (#21655)
* test if expr parsing expr

refs #19802

* in any case

* just be honest

* fix symbol/keyword issue too
2023-04-14 12:34:49 +02:00
metagn
1bb117cd7a proc typeclass accounts for iterator, call conventions + nil fix + document typeclass AST (#21629)
* test fix #16546 #16548 + another issue

* please don't tell me other packages do this

* fix CI + test typeclass callconv pragma

* better logic in parser

* docs and changelog
2023-04-11 09:23:41 +02:00
metagn
814d3e6818 fix #19430 (#21603) 2023-04-06 13:36:21 +02:00
metagn
2315b01ae6 tuple unpacking for vars as just sugar, allowing nesting (#21563)
* tuple unpacking for vars as just sugar, allowing nesting

* set temp symbol AST

* hopeful fix some issues, add test for #19364

* always use temp for consts

* document, fix small issue

* fix manual indentation

* actually fix manual

* use helper proc

* don't resem temp tuple assignment
2023-03-28 17:52:23 +02:00
ringabout
406d302131 allow omitting stmts using finally as post expr blocks; make it consistent with else, except etc. (#21361)
allow omitting stmts using `finally` as post expr blocks
2023-02-14 07:29:30 +01:00
Ivan Yonchovski
7031ea65cd Implemented basic macro expand functionality (#20579)
* Implemented level based macro expand functionality

- it can handle single macro call or expand whole function/proc/etc and it

- In addition, I have altered the parser to provide the endInfo for the node.
The usefulness of the `endInfo` is not limited to the `expandMacro`
functionality but also it is useful for `ideOutline` functionality and I have
altered the ideOutline functionality to use `endInfo`. Note `endInfo` most of
the time is lost during the AST transformation thus in `nimsuggest.nim` I am
using freshly parsed tree to get the location information.

* Make sure we stop expanding correctly

* Test CI

* Fix tv3_outline.nim
2023-01-27 07:11:30 +01:00
rockcavera
9b4516fbcb fix in msg doAssert() to update grammar.txt (#21179) 2022-12-27 12:13:05 +08:00
ringabout
d0721eadf8 fixes #21144; try expression will not match the less indentation except (#21152)
fixes #21144; try expression will not match the less indent except
2022-12-21 21:46:14 +01:00
Vindaar
0a1d4ba842 fix issue #20922 by handling missing expr in exprList for tkOf (#20930)
* fix issue #20922 by handling missing expr in `exprList` for `tkOf`

* fix line numbers in test case

* rewrite exprList requiring expr, add optionalExprList for except

As suggested by @metagn.

* update test case to reflect new code

* update grammar.txt

* update line numbers in test case taking into account nimout

Given the number of errors that are produced it seems easier to do it
this way instead of using `tt.Error`.
2022-12-08 10:59:13 +01:00
metagn
4ca2dcb404 Named arguments in commands + many grammar fixes (#20994)
* Breaking parser changes, implement https://github.com/nim-lang/RFCs/issues/442

Types are separated from expressions and better reflected in the grammar.

* add test

* more accurate grammar

* fix keyword typedescs

* accept expressions in proc argument lists

* CI "fixes"

* fixes

* allow full ref expressions again, adapt old tests

* cleanup, fix some tests

* improve grammar, try and revert semtypes change

* restrict sigil binding to identOrLiteral

* fix, should have caught this immediately

* add changelog entry, fix double not nil bug

* correct grammar

* change section

* fix

* real fix hopefully

* fix test

* support LL(1) for tuples

* make grammar.txt too
2022-12-06 13:11:56 +01:00
metagn
15d00ca0e1 allow proc expressions in place of statements (#20935)
properly fixes #18714
2022-11-29 06:37:00 +01:00
ringabout
a15872ba9e refactor strongSpaceB with an enum (#20809)
refactor strongSpaceB
2022-11-10 16:21:52 +01:00
ringabout
0b1d1b7886 fixes #15688; handle strongSpace overflow issues (#20724)
* fixes #15688; handle `strongSpace` overflow issues

* stop at 1

* change the type of strongSpaceA to bool
2022-11-03 09:18:09 +01:00
Andreas Rumpf
0d23419e68 DAA and 'out' parameters (#20506)
* DAA and 'out' parameters

* progress

* documented strictDefs and out parameters

* docs, tests and a bugfix

* fixes silly regression
2022-10-06 17:08:41 +02:00
ringabout
e323b91a32 correct grammar (ref #20199) and add check for grammar.txt (#20494)
* correct grammar; ref #20199

* add check for keeping grammar.txt up-to-date

* add nimTestGrammar
2022-10-06 16:36:32 +02:00
ringabout
f89ba2c951 add default field support for object in ARC/ORC (#20480)
* fresh start

* add cpp target

* add result support

* add nimPreviewRangeDefault

* reduce

* use orc

* refactor common parts

* add tuple support

* add testcase for tuple

* cleanup; fixes nimsuggest tests

* there is something wrong with cpp

* remove

* add support for seqs

* fixes style

* addd initial distinct support

* remove links

* typo

* fixes tuple defaults

* add rangedefault

* add cpp support

* fixes one more bugs

* add more hasDefaults

* fixes ordinal types

* add testcase for #16744

* add testcase for #3608

* fixes docgen

* small fix

* recursive

* fixes

* cleanup and remove tuple support

* fixes nimsuggest

* fixes generics procs

* refactor

* increases timeout

* refactor hasDefault

* zero default; disable i386

* add tuples back

* fixes bugs

* fixes tuple

* add more tests

* fix one more bug regarding tuples

* more tests and cleanup

* remove messy distinct types which must be initialized by original types

* add tests

* fixes zero default

* fixes grammar

* fixes tests

* fixes tests

* fixes tests

* fixes comments

* fixes and add testcase

* undo default values for results

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
2022-10-04 12:45:10 +02:00
metagn
86f7f4ffa5 remove deprecated type pragma syntax, fix bugs that required it (#20199)
* remove deprecated pragma syntax from 0.20.0

closes #4651, closes #16653 with a cheap fix for now due to
how early `tfFinal` is set

* remove type pragma between name and generics

* undo removal, try removing bind expression (0.8.14)

* fix test, unremove bind expr

* remove again

* Update changelog.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* dependencies @ HEAD & weave test dependencies

* try fix package ci

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-09-03 09:52:13 +02:00
flywind
42ac50e988 fixes #19662; Indent level errored for first line (#19718) 2022-04-25 12:00:23 +02:00
flywind
7f6e800caf move assertions out of system (#19599) 2022-03-23 20:34:53 +01:00
hlaaftana
61d682e733 Allow full commands and blocks in type sections (#19181)
* allow full commands and blocks in type sections
* update grammar
* fix changelog [skip ci]
* more tests
* even more tests
2022-01-02 07:29:55 +01:00
Andreas Rumpf
a61bbf7d8d fixes grammar typos [backport] (#19289) 2021-12-27 17:28:19 +01:00
hlaaftana
1ef945668d treat do with pragmas but no parens as proc (#19191)
fixes #19188
2021-12-05 06:44:22 +01:00
hlaaftana
2859069dbe fix #12274 (#19180) 2021-11-24 07:08:07 +01:00
Andreas Rumpf
6ff61766da fixes #19011 [backport:1.6] (#19114) 2021-11-09 18:59:59 +01:00
Andreas Rumpf
c56ba3f06a fixes #18847 [backport] (#18870) 2021-09-20 09:09:53 +02:00
Andreas Rumpf
2e2d928846 formal grammar updates [backport:1.2] (#18803) 2021-09-04 19:52:57 +02:00
Timothee Cour
fa7c1aa864 move PNode.comment to a side channel, reducing memory usage during compilation by a factor 1.25x (#18760)
* move PNode.comment so a side channel, reducing memory usage

* fix a bug

* fixup

* use sfHasComment to speedup comment lookups

* fix for IC

* Update compiler/parser.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-08-29 15:54:07 +02:00
Timothee Cour
3aa16c1de0 fix RFC #341: dot-like operators are now parsed with same precedence as . (#18711)
* fix RFC #341: dot-like operators are now parsed with same precedence as `.`

* fixup

* [skip ci] address comment in changelog

* address comment

* update grammmar

* add manual entry

* fixup

* -d:nimPreviewDotLikeOps

* address comment to unblock PR: move nimPreviewDotLikeOps out of config/config.nims
2021-08-25 06:50:40 +02:00
Timothee Cour
8d2f6bba3a support same-line doc comments in routines (#18595)
* support same-line comments in routines
* remove assert as per review comment
2021-07-27 19:50:59 +02:00
konsumlamm
ac5435ecd0 Make error message for empty new-styled concept more descriptive (#18506)
* Allow empty new-styled concept

Slightly improve error messages

* Make empty new-styled concepts an error
2021-07-18 10:49:03 +02:00
Clyybber
72d6a9c885 Fix #16426 (#18377) 2021-06-28 17:41:37 +02:00