Merge pull request #1245 from flaviut/fix1217

Allow anything to go inside accents
This commit is contained in:
Andreas Rumpf
2014-06-08 22:00:26 +02:00
4 changed files with 34 additions and 30 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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&*$**()&*@`, `.}`, `(}`, `[`, `]`