summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2019-04-17 10:55:41 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-04-17 11:55:41 +0200
commit7d8af25d5828e67f10c0f5a75abf9ee8fc02a9bb (patch)
treedd25210549bc8c64b17db2776fa75bde463ab58b
parent43832f8e575b472907579b74dca0797f8130baa8 (diff)
downloadNim-7d8af25d5828e67f10c0f5a75abf9ee8fc02a9bb.tar.gz
revert parser stmtListExpr (#11007)
* Revert "Support for stmtListExpr in parser after major keywords. Scaled down version. (#10852)"

This reverts commit 862897dc0f122e374c0e4d44770ffcd8825e51e3.

* redo fix for #4035

* render stmtlistExpr using semicolon

* Revert "render stmtlistExpr using semicolon"

This reverts commit cafb78b8d5b125b5f6ba94248377a1433b3138cb.

* revert test

-rw-r--r--changelog.md10
-rw-r--r--compiler/parser.nim28
-rw-r--r--tests/macros/ttryparseexpr.nim5
-rw-r--r--tests/parser/tstmtlist_expr.nim20
4 files changed, 11 insertions, 52 deletions
diff --git a/changelog.md b/changelog.md
index 191ddb761..f31d57541 100644
--- a/changelog.md
+++ b/changelog.md
@@ -31,16 +31,6 @@
 
 - `getImpl` on a `var` or `let` symbol will now return the full `IdentDefs`
   tree from the symbol declaration instead of just the initializer portion.
-- it is now possible to use statement list expressions after keywords with
-  indentation: raise, return, discard, yield. This helps parsing code produced
-  by Nim template expansion where stmtListExpr can appear in place of any expression.
-  Example:
-```nim
-  raise
-    var e = new(Exception)
-    e.msg = "My Exception msg"
-    e
-```
 
 - To use multi-methods, explicit `--multimethods:on` is now needed.
 
diff --git a/compiler/parser.nim b/compiler/parser.nim
index ec62dbf54..c154e5eb0 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -238,7 +238,6 @@ proc newIdentNodeP(ident: PIdent, p: TParser): PNode =
 
 proc parseExpr(p: var TParser): PNode
 proc parseStmt(p: var TParser): PNode
-proc parseStmtListExpr(p: var TParser): PNode
 proc parseTypeDesc(p: var TParser): PNode
 proc parseParamList(p: var TParser, retColon = true): PNode
 
@@ -1482,12 +1481,12 @@ proc parseFromStmt(p: var TParser): PNode =
   #expectNl(p)
 
 proc parseReturnOrRaise(p: var TParser, kind: TNodeKind): PNode =
-  #| returnStmt = 'return' stmtListExpr?
-  #| raiseStmt = 'raise' stmtListExpr?
-  #| yieldStmt = 'yield' stmtListExpr?
-  #| discardStmt = 'discard' stmtListExpr?
-  #| breakStmt = 'break' stmtListExpr?
-  #| continueStmt = 'break' stmtListExpr?
+  #| returnStmt = 'return' optInd expr?
+  #| raiseStmt = 'raise' optInd expr?
+  #| yieldStmt = 'yield' optInd expr?
+  #| discardStmt = 'discard' optInd expr?
+  #| breakStmt = 'break' optInd expr?
+  #| continueStmt = 'break' optInd expr?
   result = newNodeP(kind, p)
   getTok(p)
   if p.tok.tokType == tkComment:
@@ -1497,7 +1496,9 @@ proc parseReturnOrRaise(p: var TParser, kind: TNodeKind): PNode =
     # NL terminates:
     addSon(result, p.emptyNode)
   else:
-    addSon(result, parseStmtListExpr(p))
+    var e = parseExpr(p)
+    e = postExprBlocks(p, e)
+    addSon(result, e)
 
 proc parseIfOrWhen(p: var TParser, kind: TNodeKind): PNode =
   #| condStmt = expr colcom stmt COMMENT?
@@ -2252,17 +2253,6 @@ proc parseStmt(p: var TParser): PNode =
           getTok(p)
           if err and p.tok.tokType == tkEof: break
 
-proc parseStmtListExpr(p: var TParser): PNode =
-  #| stmtListExpr = (IND{>} stmt) / expr
-  if p.tok.indent > p.currInd:
-    result = parseStmt(p)
-    result.kind = nkStmtListExpr
-    if result.len == 1:
-      result = result[0]
-  else:
-    result = parseExpr(p)
-    result = postExprBlocks(p, result)
-
 proc parseAll(p: var TParser): PNode =
   ## Parses the rest of the input stream held by the parser into a PNode.
   result = newNodeP(nkStmtList, p)
diff --git a/tests/macros/ttryparseexpr.nim b/tests/macros/ttryparseexpr.nim
index d1084937b..fc0ee61d0 100644
--- a/tests/macros/ttryparseexpr.nim
+++ b/tests/macros/ttryparseexpr.nim
@@ -1,5 +1,5 @@
 discard """
-  outputsub: '''Error: expression expected, but found '[EOF]' -- 45'''
+  outputsub: '''Error: expression expected, but found '[EOF]' 45'''
 """
 
 # feature request #1473
@@ -9,7 +9,6 @@ macro test(text: string): untyped =
   try:
     result = parseExpr(text.strVal)
   except ValueError:
-    echo text
     result = newLit getCurrentExceptionMsg()
 
 const
@@ -18,4 +17,4 @@ const
   b = test("valid")
   c = test("\"") # bug #2504
 
-echo a, " -- ", b
+echo a, " ", b
diff --git a/tests/parser/tstmtlist_expr.nim b/tests/parser/tstmtlist_expr.nim
deleted file mode 100644
index 8b4bb8505..000000000
--- a/tests/parser/tstmtlist_expr.nim
+++ /dev/null
@@ -1,20 +0,0 @@
-discard """
-  output: '''10'''
-"""
-
-proc xx(a: int): int =
-  let y = 0
-  return
-    var x = 0
-    x + y
-
-proc b(x: int): int = 
-  raise 
-    var e: ref Exception
-    new(e)
-    e.msg = "My Exception msg"
-    e
-
-##issue 4035
-echo(5 +
-5)
\ No newline at end of file