Merge pull request #1245 from flaviut/fix1217
Allow anything to go inside accents
This commit is contained in:
commit
ee1bb2d562
4 changed files with 34 additions and 30 deletions
|
|
@ -147,8 +147,10 @@ proc expectIdent(p: TParser) =
|
||||||
proc eat(p: var TParser, tokType: TTokType) =
|
proc eat(p: var TParser, tokType: TTokType) =
|
||||||
## Move the parser to the next token if the current token is of type
|
## Move the parser to the next token if the current token is of type
|
||||||
## `tokType`, otherwise error.
|
## `tokType`, otherwise error.
|
||||||
if p.tok.tokType == tokType: getTok(p)
|
if p.tok.tokType == tokType:
|
||||||
else: lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType])
|
getTok(p)
|
||||||
|
else:
|
||||||
|
lexMessage(p.lex, errTokenExpected, TokTypeToStr[tokType])
|
||||||
|
|
||||||
proc parLineInfo(p: TParser): TLineInfo =
|
proc parLineInfo(p: TParser): TLineInfo =
|
||||||
## Retrieve the line information associated with the parser's current state.
|
## 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)
|
skipComment(p, n)
|
||||||
|
|
||||||
proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
||||||
#| symbol = '`' (KEYW|IDENT|operator|'(' ')'|'[' ']'|'{' '}'|'='|literal)+ '`'
|
#| symbol = '`' (KEYW|IDENT|operator|'('|')'|'['|']'|'{'|'}'|'='|literal)+ '`'
|
||||||
#| | IDENT
|
#| | IDENT
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkSymbol:
|
of tkSymbol:
|
||||||
|
|
@ -294,33 +296,19 @@ proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
||||||
of tkAccent:
|
of tkAccent:
|
||||||
result = newNodeP(nkAccQuoted, p)
|
result = newNodeP(nkAccQuoted, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
var accm = ""
|
||||||
while true:
|
while true:
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkBracketLe:
|
of tkAccent:
|
||||||
add(result, newIdentNodeP(getIdent"[]", p))
|
if accm == "":
|
||||||
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:
|
|
||||||
parMessage(p, errIdentifierExpected, p.tok)
|
parMessage(p, errIdentifierExpected, p.tok)
|
||||||
break
|
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)
|
eat(p, tkAccent)
|
||||||
else:
|
else:
|
||||||
if allowNil and p.tok.tokType == tkNil:
|
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,
|
proc parseTypeDescKAux(p: var TParser, kind: TNodeKind,
|
||||||
mode: TPrimaryMode): PNode =
|
mode: TPrimaryMode): PNode =
|
||||||
|
#| distinct = 'distinct' optInd typeDesc
|
||||||
result = newNodeP(kind, p)
|
result = newNodeP(kind, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,10 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
counter = x
|
counter = x
|
||||||
of nkSym:
|
of nkSym:
|
||||||
e = n.sons[i].sym
|
e = n.sons[i].sym
|
||||||
of nkIdent:
|
of nkIdent, nkAccQuoted:
|
||||||
e = newSymS(skEnumField, n.sons[i], c)
|
e = newSymS(skEnumField, n.sons[i], c)
|
||||||
else: illFormedAst(n)
|
else:
|
||||||
|
illFormedAst(n[i])
|
||||||
e.typ = result
|
e.typ = result
|
||||||
e.position = int(counter)
|
e.position = int(counter)
|
||||||
if e.position == 0: hasNull = true
|
if e.position == 0: hasNull = true
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ ampExpr = plusExpr (OP6 optInd plusExpr)*
|
||||||
plusExpr = mulExpr (OP7 optInd mulExpr)*
|
plusExpr = mulExpr (OP7 optInd mulExpr)*
|
||||||
mulExpr = dollarExpr (OP8 optInd dollarExpr)*
|
mulExpr = dollarExpr (OP8 optInd dollarExpr)*
|
||||||
dollarExpr = primary (OP9 optInd primary)*
|
dollarExpr = primary (OP9 optInd primary)*
|
||||||
symbol = '`' (KEYW|IDENT|operator|'(' ')'|'[' ']'|'{' '}'|'='|literal)+ '`'
|
symbol = '`' (KEYW|IDENT|operator|'('|')'|'['|']'|'{'|'}'|'='|literal)+ '`'
|
||||||
| IDENT
|
| IDENT
|
||||||
indexExpr = expr
|
indexExpr = expr
|
||||||
indexExprList = indexExpr ^+ comma
|
indexExprList = indexExpr ^+ comma
|
||||||
|
|
@ -82,6 +82,7 @@ paramListColon = paramList? (':' optInd typeDesc)?
|
||||||
doBlock = 'do' paramListArrow pragmas? colcom stmt
|
doBlock = 'do' paramListArrow pragmas? colcom stmt
|
||||||
doBlocks = doBlock ^* IND{=}
|
doBlocks = doBlock ^* IND{=}
|
||||||
procExpr = 'proc' paramListColon pragmas? ('=' COMMENT? stmt)?
|
procExpr = 'proc' paramListColon pragmas? ('=' COMMENT? stmt)?
|
||||||
|
distinct = 'distinct' optInd typeDesc
|
||||||
expr = (ifExpr
|
expr = (ifExpr
|
||||||
| whenExpr
|
| whenExpr
|
||||||
| caseExpr
|
| caseExpr
|
||||||
|
|
@ -166,7 +167,6 @@ object = 'object' pragma? ('of' typeDesc)? COMMENT? objectPart
|
||||||
typeClassParam = ('var')? symbol
|
typeClassParam = ('var')? symbol
|
||||||
typeClass = typeClassParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
|
typeClass = typeClassParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
|
||||||
&IND{>} stmt
|
&IND{>} stmt
|
||||||
distinct = 'distinct' optInd typeDesc
|
|
||||||
typeDef = identWithPragma genericParamList? '=' optInd typeDefAux
|
typeDef = identWithPragma genericParamList? '=' optInd typeDefAux
|
||||||
indAndComment?
|
indAndComment?
|
||||||
varTuple = '(' optInd identWithPragma ^+ comma optPar ')' '=' optInd expr
|
varTuple = '(' optInd identWithPragma ^+ comma optPar ')' '=' optInd expr
|
||||||
|
|
|
||||||
14
tests/misc/tbug1217bracketquotes.nim
Normal file
14
tests/misc/tbug1217bracketquotes.nim
Normal 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&*$**()&*@`, `.}`, `(}`, `[`, `]`
|
||||||
Loading…
Add table
Add a link
Reference in a new issue