summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-06-08 22:00:26 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-06-08 22:00:26 +0200
commitee1bb2d5629f02b67b62934371ef29655868a69d (patch)
tree8c63f15e286c17208d2b9e774838d98a595f470f
parent69a595480790d985f2d2f79d5d74bb6adb8568a7 (diff)
parent145cb3ae8ccf58495a3e38f6646041661de2affb (diff)
downloadNim-ee1bb2d5629f02b67b62934371ef29655868a69d.tar.gz
Merge pull request #1245 from flaviut/fix1217
Allow anything to go inside accents
-rw-r--r--compiler/parser.nim41
-rw-r--r--compiler/semtypes.nim5
-rw-r--r--doc/grammar.txt4
-rw-r--r--tests/misc/tbug1217bracketquotes.nim14
4 files changed, 34 insertions, 30 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim
index 2f9deb6b3..0f52750c9 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -147,8 +147,10 @@ proc expectIdent(p: TParser) =
 proc eat(p: var TParser, tokType: TTokType) =
   ## Move the parser to the next token if the current token is of type
   ## `tokType`, otherwise error.
-  if p.tok.tokType == tokType: getTok(p)
-  else: lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType])
+  if p.tok.tokType == tokType:
+    getTok(p)
+  else:
+    lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType])
   
 proc parLineInfo(p: TParser): TLineInfo =
   ## Retrieve the line information associated with the parser's current state.
@@ -285,7 +287,7 @@ proc colcom(p: var TParser, n: PNode) =
   skipComment(p, n)
 
 proc parseSymbol(p: var TParser, allowNil = false): PNode =
-  #| symbol = '`' (KEYW|IDENT|operator|'(' ')'|'[' ']'|'{' '}'|'='|literal)+ '`'
+  #| symbol = '`' (KEYW|IDENT|operator|'('|')'|'['|']'|'{'|'}'|'='|literal)+ '`'
   #|        | IDENT
   case p.tok.tokType
   of tkSymbol: 
@@ -294,33 +296,19 @@ proc parseSymbol(p: var TParser, allowNil = false): PNode =
   of tkAccent: 
     result = newNodeP(nkAccQuoted, p)
     getTok(p)
+    var accm = ""
     while true:
       case p.tok.tokType
-      of tkBracketLe: 
-        add(result, newIdentNodeP(getIdent"[]", p))
-        getTok(p)
-        eat(p, tkBracketRi)
-      of tkEquals:
-        add(result, newIdentNodeP(getIdent"=", p))
-        getTok(p)
-      of tkParLe:
-        add(result, newIdentNodeP(getIdent"()", p))
-        getTok(p)
-        eat(p, tkParRi)
-      of tkCurlyLe:
-        add(result, newIdentNodeP(getIdent"{}", p))
-        getTok(p)
-        eat(p, tkCurlyRi)
-      of tokKeywordLow..tokKeywordHigh, tkSymbol, tkOpr, tkDot, tkDotDot:
-        add(result, newIdentNodeP(p.tok.ident, p))
-        getTok(p)
-      of tkIntLit..tkCharLit:
-        add(result, newIdentNodeP(getIdent(tokToStr(p.tok)), p))
-        getTok(p)
-      else:
-        if result.len == 0: 
+      of tkAccent:
+        if accm == "": 
           parMessage(p, errIdentifierExpected, p.tok)
         break
+      of tkEof, tkInvalid, tkComment:
+          parMessage(p, errIdentifierExpected, p.tok)
+      else:
+        accm.add(tokToStr(p.tok))
+        getTok(p)
+    result.add(newIdentNodeP(getIdent(accm), p))
     eat(p, tkAccent)
   else:
     if allowNil and p.tok.tokType == tkNil:
@@ -993,6 +981,7 @@ proc parseSymbolList(p: var TParser, result: PNode, allowNil = false) =
 
 proc parseTypeDescKAux(p: var TParser, kind: TNodeKind,
                        mode: TPrimaryMode): PNode =
+  #| distinct = 'distinct' optInd typeDesc
   result = newNodeP(kind, p)
   getTok(p)
   optInd(p, result)
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index d88a95603..2dcca8f1e 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -70,9 +70,10 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
       counter = x
     of nkSym: 
       e = n.sons[i].sym
-    of nkIdent: 
+    of nkIdent, nkAccQuoted: 
       e = newSymS(skEnumField, n.sons[i], c)
-    else: illFormedAst(n)
+    else:
+      illFormedAst(n[i])
     e.typ = result
     e.position = int(counter)
     if e.position == 0: hasNull = true
diff --git a/doc/grammar.txt b/doc/grammar.txt
index 63e898e11..fe5341840 100644
--- a/doc/grammar.txt
+++ b/doc/grammar.txt
@@ -24,7 +24,7 @@ ampExpr = plusExpr (OP6 optInd plusExpr)*
 plusExpr = mulExpr (OP7 optInd mulExpr)*
 mulExpr = dollarExpr (OP8 optInd dollarExpr)*
 dollarExpr = primary (OP9 optInd primary)*
-symbol = '`' (KEYW|IDENT|operator|'(' ')'|'[' ']'|'{' '}'|'='|literal)+ '`'
+symbol = '`' (KEYW|IDENT|operator|'('|')'|'['|']'|'{'|'}'|'='|literal)+ '`'
        | IDENT
 indexExpr = expr
 indexExprList = indexExpr ^+ comma
@@ -82,6 +82,7 @@ paramListColon = paramList? (':' optInd typeDesc)?
 doBlock = 'do' paramListArrow pragmas? colcom stmt
 doBlocks = doBlock ^* IND{=}
 procExpr = 'proc' paramListColon pragmas? ('=' COMMENT? stmt)?
+distinct = 'distinct' optInd typeDesc
 expr = (ifExpr
       | whenExpr
       | caseExpr
@@ -166,7 +167,6 @@ object = 'object' pragma? ('of' typeDesc)? COMMENT? objectPart
 typeClassParam = ('var')? symbol
 typeClass = typeClassParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
               &IND{>} stmt
-distinct = 'distinct' optInd typeDesc
 typeDef = identWithPragma genericParamList? '=' optInd typeDefAux
             indAndComment?
 varTuple = '(' optInd identWithPragma ^+ comma optPar ')' '=' optInd expr
diff --git a/tests/misc/tbug1217bracketquotes.nim b/tests/misc/tbug1217bracketquotes.nim
new file mode 100644
index 000000000..90e67d45b
--- /dev/null
+++ b/tests/misc/tbug1217bracketquotes.nim
@@ -0,0 +1,14 @@
+discard """
+  output: "13{(.{}}{*4&*$**()&*@1235"
+"""
+
+type
+  Test = enum
+    `1`, `3`, `{`, `(.`, `{}}{`, `*4&*$**()&*@`
+
+let `.}` = 1
+let `(}` = 2
+let `[` = 3
+let `]` = 5
+
+echo `1`, `3`, `{`, `(.`, `{}}{`, `*4&*$**()&*@`, `.}`, `(}`, `[`, `]`