small bugfixes to make more tests green

This commit is contained in:
Araq
2011-11-02 02:28:18 +01:00
parent 84c473a890
commit 1f6725e59e
11 changed files with 40 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ type
errTabulatorsAreNotAllowed, errInvalidToken, errLineTooLong,
errInvalidNumber, errNumberOutOfRange, errNnotAllowedInCharacter,
errClosingBracketExpected, errMissingFinalQuote, errIdentifierExpected,
errNewlineExpected,
errInvalidModuleName,
errOperatorExpected, errTokenExpected, errStringAfterIncludeExpected,
errRecursiveDependencyX, errOnOrOffExpected, errNoneSpeedOrSizeExpected,
@@ -128,6 +129,7 @@ const
errClosingBracketExpected: "closing ']' expected, but end of file reached",
errMissingFinalQuote: "missing final \'",
errIdentifierExpected: "identifier expected, but found \'$1\'",
errNewlineExpected: "newline expected, but found \'$1\'",
errInvalidModuleName: "invalid module name: '$1'",
errOperatorExpected: "operator expected, but found \'$1\'",
errTokenExpected: "\'$1\' expected",

View File

@@ -95,6 +95,10 @@ proc optInd(p: var TParser, n: PNode) =
skipComment(p, n)
skipInd(p)
proc ExpectNl(p: TParser) =
if p.tok.tokType notin {tkEof, tkSad, tkInd, tkDed}:
lexMessage(p.lex, errNewlineExpected, prettyTok(p.tok))
proc expectIdentOrKeyw(p: TParser) =
if p.tok.tokType != tkSymbol and not isKeyword(p.tok.tokType):
lexMessage(p.lex, errIdentifierExpected, prettyTok(p.tok))
@@ -761,6 +765,7 @@ proc parseImportOrIncludeStmt(p: var TParser, kind: TNodeKind): PNode =
if p.tok.tokType != tkComma: break
getTok(p)
optInd(p, a)
expectNl(p)
proc parseFromStmt(p: var TParser): PNode =
var a: PNode
@@ -798,6 +803,7 @@ proc parseFromStmt(p: var TParser): PNode =
if p.tok.tokType != tkComma: break
getTok(p)
optInd(p, a)
expectNl(p)
proc parseReturnOrRaise(p: var TParser, kind: TNodeKind): PNode =
result = newNodeP(kind, p)
@@ -1299,6 +1305,7 @@ proc parseBind(p: var TParser): PNode =
if p.tok.tokType != tkComma: break
getTok(p)
optInd(p, a)
expectNl(p)
proc simpleStmt(p: var TParser): PNode =
case p.tok.tokType

View File

@@ -253,8 +253,10 @@ proc semGenericStmt(c: PContext, n: PNode,
addDecl(c, newSym(skUnknown, getIdent("result"), nil))
n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, toBind)
n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, toBind)
var s = n.sons[namePos].sym
n.sons[bodyPos] = semGenericStmtScope(c, s.getBody, flags, toBind)
var body: PNode
if n.sons[namePos].kind == nkSym: body = n.sons[namePos].sym.getBody
else: body = n.sons[bodyPos]
n.sons[bodyPos] = semGenericStmtScope(c, body, flags, toBind)
closeScope(c.tab)
else:
for i in countup(0, sonsLen(n) - 1):

View File

@@ -735,7 +735,8 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
result = sameObjectStructures(a, b, c)
of tyDistinct:
CycleCheck()
result = sameTypeAux(a.sons[0], b.sons[0], c)
if c.cmp == dcEq: result = sameDistinctTypes(a, b)
else: result = sameTypeAux(a.sons[0], b.sons[0], c)
of tyEnum, tyForward, tyProxy:
# XXX generic enums do not make much sense, but require structural checking
result = a.id == b.id

View File

@@ -56,7 +56,8 @@ proc unidecode*(s: string): string =
## Example:
##
## ..code-block:: nimrod
## unidecode("\\x53\\x17\\x4E\\xB0")
##
## unidecode("\x53\x17\x4E\xB0")
##
## Results in: "Bei Jing"
##

View File

@@ -50,8 +50,9 @@ proc printStatus*(s: TestStatus, name: string) =
styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
template test*(name: expr, body: stmt): stmt =
if bind shouldRun(name):
bind checkpoints = @[]
bind shouldRun, checkPoints
if shouldRun(name):
checkpoints = @[]
var TestStatusIMPL = OK
try:
@@ -67,7 +68,8 @@ proc checkpoint*(msg: string) =
# TODO: add support for something like SCOPED_TRACE from Google Test
template fail* =
for msg in items(bind checkpoints):
bind checkpoints
for msg in items(checkpoints):
echo msg
if AbortOnError: quit(1)

View File

@@ -3,7 +3,8 @@ var
lastId = 0
template genId*: expr =
inc(bind lastId)
bind lastId
inc(lastId)
lastId

View File

@@ -7,7 +7,8 @@ discard """
proc p1(x: int8, y: int): int = return x + y
template tempBind(x, y: expr): expr =
bind p1(x, y)
bind p1
p1(x, y)
proc p1(x: int, y: int8): int = return x - y

View File

@@ -5,6 +5,8 @@ discard """
import unidecode
assert unidecode("\\x53\\x17\\x4E\\xB0") == "Bei Jing"
loadUnidecodeTable("lib/pure/unidecode/unidecode.dat")
assert unidecode("\x53\x17\x4E\xB0") == "Bei Jing"
echo unidecode("Äußerst")

View File

@@ -9,7 +9,7 @@ proc p1(x: int8, y: int): int = return x + y
proc p1(x: int, y: int8): int = return x - y
template tempBind(x, y: expr): expr =
bind p1(x, y) #ERROR_MSG ambiguous call
(bind p1(x, y)) #ERROR_MSG ambiguous call
echo tempBind(1'i8, 2'i8)

View File

@@ -0,0 +1,10 @@
discard """
file: "tmissingnl.nim"
line: 7
errormsg: "newline expected, but found 'keyword var'"
"""
import strutils var s: seq[int] = @[0, 1, 2, 3, 4, 5, 6]
#s[1..3] = @[]