diff options
author | metagn <metagngn@gmail.com> | 2022-12-06 15:11:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 13:11:56 +0100 |
commit | 4ca2dcb404aa1b92900e838790d5df554fc0cb9a (patch) | |
tree | 13ba43b84b90c24f23b528fe110e15338e35fae6 /tests/parser | |
parent | 1564ae650f8d4d4c30adf4528f74d7707e4cb737 (diff) | |
download | Nim-4ca2dcb404aa1b92900e838790d5df554fc0cb9a.tar.gz |
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
Diffstat (limited to 'tests/parser')
-rw-r--r-- | tests/parser/tcommand_as_expr.nim | 9 | ||||
-rw-r--r-- | tests/parser/tcommandequals.nim | 17 | ||||
-rw-r--r-- | tests/parser/tcommandindent.nim | 16 | ||||
-rw-r--r-- | tests/parser/tdoublenotnil.nim | 3 | ||||
-rw-r--r-- | tests/parser/ttypeexprobject.nim | 10 | ||||
-rw-r--r-- | tests/parser/ttypeexprs.nim | 25 |
6 files changed, 80 insertions, 0 deletions
diff --git a/tests/parser/tcommand_as_expr.nim b/tests/parser/tcommand_as_expr.nim index b25ec4bd8..f37c34f63 100644 --- a/tests/parser/tcommand_as_expr.nim +++ b/tests/parser/tcommand_as_expr.nim @@ -36,3 +36,12 @@ echo f -4 echo int -1 # doesn't compile echo int `-` 1 # compiles + +var num = 1 +num += int 2 +doAssert num == 3 + +import options +var opt = some some none int +opt = some some none int +opt = some none Option[int] diff --git a/tests/parser/tcommandequals.nim b/tests/parser/tcommandequals.nim new file mode 100644 index 000000000..f41b318ac --- /dev/null +++ b/tests/parser/tcommandequals.nim @@ -0,0 +1,17 @@ +discard """ + output: ''' +5 +''' +""" + +proc foo(a, b: int) = + echo a + b + +foo a = 2, b = 3 + +import macros + +macro bar(args: varargs[untyped]): untyped = + doAssert args[0].kind == nnkExprEqExpr + +bar "a" = 1 diff --git a/tests/parser/tcommandindent.nim b/tests/parser/tcommandindent.nim new file mode 100644 index 000000000..449c218db --- /dev/null +++ b/tests/parser/tcommandindent.nim @@ -0,0 +1,16 @@ +when false: # parse the following + let foo = Obj( + field1: proc (src: pointer, srcLen: Natural) + {.nimcall, gcsafe, raises: [IOError, Defect].} = + var file = FileOutputStream(s).file + + implementWrites s.buffers, src, srcLen, "FILE", + writeStartAddr, writeLen, + file.writeBuffer(writeStartAddr, writeLen) + , + field2: proc {.nimcall, gcsafe, raises: [IOError, Defect].} = + flushFile FileOutputStream(s).file + , + field3: proc () {.nimcall, gcsafe, raises: [IOError, Defect].} = + close FileOutputStream(s).file + ) diff --git a/tests/parser/tdoublenotnil.nim b/tests/parser/tdoublenotnil.nim new file mode 100644 index 000000000..c61008c54 --- /dev/null +++ b/tests/parser/tdoublenotnil.nim @@ -0,0 +1,3 @@ +when false: + type Foo = Bar not nil not nil #[tt.Error + ^ invalid indentation]# diff --git a/tests/parser/ttypeexprobject.nim b/tests/parser/ttypeexprobject.nim new file mode 100644 index 000000000..6895f1731 --- /dev/null +++ b/tests/parser/ttypeexprobject.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "invalid indentation" + line: 10 + column: 14 +""" + +type + A = (object | tuple | int) + B = int | object | tuple + C = object | tuple | int # issue #8846 diff --git a/tests/parser/ttypeexprs.nim b/tests/parser/ttypeexprs.nim new file mode 100644 index 000000000..e40efc7d9 --- /dev/null +++ b/tests/parser/ttypeexprs.nim @@ -0,0 +1,25 @@ +proc foo[T: ptr int | ptr string](x: T) = discard +var x = "abc" +foo(addr x) + +let n = 3'u32 +type Double = ( + when n.sizeof == 4: uint64 + elif n.sizeof == 2: uint32 + else: uint16 +) + +type + A = (ref | ptr | pointer) + B = pointer | ptr | ref + C = ref | ptr | pointer + +template `+`(a, b): untyped = (b, a) +template `*`(a, b): untyped = (a, b) + +doAssert (ref int + ref float * ref string + ref bool) is + (ref bool, ((ref float, ref string), ref int)) +type X = ref int + ref float * ref string + ref bool +doAssert X is (ref bool, ((ref float, ref string), ref int)) + +type SomePointer = proc | ref | ptr | pointer |