fixes #310
This commit is contained in:
parent
3cb3813eed
commit
18fbaab216
4 changed files with 45 additions and 22 deletions
|
|
@ -675,6 +675,8 @@ proc scanComment(L: var TLexer, tok: var TToken) =
|
||||||
# a comment ends if the next line does not start with the # on the same
|
# a comment ends if the next line does not start with the # on the same
|
||||||
# column after only whitespace
|
# column after only whitespace
|
||||||
tok.tokType = tkComment
|
tok.tokType = tkComment
|
||||||
|
# iNumber contains the number of '\n' in the token
|
||||||
|
tok.iNumber = 0
|
||||||
var col = getColNumber(L, pos)
|
var col = getColNumber(L, pos)
|
||||||
while true:
|
while true:
|
||||||
var lastBackslash = -1
|
var lastBackslash = -1
|
||||||
|
|
@ -699,6 +701,7 @@ proc scanComment(L: var TLexer, tok: var TToken) =
|
||||||
if buf[pos] == '#' and (col == indent or lastBackslash > 0):
|
if buf[pos] == '#' and (col == indent or lastBackslash > 0):
|
||||||
tok.literal.add "\n"
|
tok.literal.add "\n"
|
||||||
col = indent
|
col = indent
|
||||||
|
inc tok.iNumber
|
||||||
else:
|
else:
|
||||||
if buf[pos] > ' ':
|
if buf[pos] > ' ':
|
||||||
L.indentAhead = indent
|
L.indentAhead = indent
|
||||||
|
|
|
||||||
|
|
@ -1207,9 +1207,9 @@ proc parseRoutine(p: var TParser, kind: TNodeKind): PNode =
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
indAndComment(p, result) # XXX: document this in the grammar!
|
indAndComment(p, result) # XXX: document this in the grammar!
|
||||||
|
|
||||||
proc newCommentStmt(p: var TParser): PNode =
|
proc newCommentStmt(p: var TParser): PNode =
|
||||||
result = newNodeP(nkCommentStmt, p)
|
result = newNodeP(nkCommentStmt, p)
|
||||||
result.info.line = result.info.line - int16(1)
|
result.info.line = result.info.line - int16(1) - int16(p.tok.iNumber)
|
||||||
|
|
||||||
type
|
type
|
||||||
TDefParser = proc (p: var TParser): PNode {.nimcall.}
|
TDefParser = proc (p: var TParser): PNode {.nimcall.}
|
||||||
|
|
|
||||||
|
|
@ -180,11 +180,11 @@ proc getIndentAux(L: var TLexer, start: int): int =
|
||||||
L.bufpos = pos # no need to set back buf
|
L.bufpos = pos # no need to set back buf
|
||||||
|
|
||||||
proc getIndent(L: var TLexer, tok: var TToken) =
|
proc getIndent(L: var TLexer, tok: var TToken) =
|
||||||
inc(L.line)
|
|
||||||
tok.line = L.line
|
|
||||||
tok.col = 0
|
tok.col = 0
|
||||||
tok.kind = tkIndent # skip the newline (but include it in the token!)
|
tok.kind = tkIndent # skip the newline (but include it in the token!)
|
||||||
tok.ival = getIndentAux(L, L.bufpos)
|
tok.ival = getIndentAux(L, L.bufpos)
|
||||||
|
inc L.line
|
||||||
|
tok.line = L.line
|
||||||
L.col = tok.ival
|
L.col = tok.ival
|
||||||
tok.ival = max(tok.ival - L.baseIndent, 0)
|
tok.ival = max(tok.ival - L.baseIndent, 0)
|
||||||
tok.symbol = "\n" & repeatChar(tok.ival)
|
tok.symbol = "\n" & repeatChar(tok.ival)
|
||||||
|
|
@ -220,21 +220,26 @@ proc rawGetTok(L: var TLexer, tok: var TToken) =
|
||||||
inc(L.col)
|
inc(L.col)
|
||||||
tok.col = max(tok.col - L.baseIndent, 0)
|
tok.col = max(tok.col - L.baseIndent, 0)
|
||||||
|
|
||||||
proc getTokens(buffer: string, skipPounds: bool, tokens: var TTokenSeq) =
|
proc getTokens(buffer: string, skipPounds: bool, tokens: var TTokenSeq): int =
|
||||||
var L: TLexer
|
var L: TLexer
|
||||||
var length = len(tokens)
|
var length = len(tokens)
|
||||||
L.buf = cstring(buffer)
|
L.buf = cstring(buffer)
|
||||||
L.line = 1 # skip UTF-8 BOM
|
L.line = 0 # skip UTF-8 BOM
|
||||||
if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'):
|
if (L.buf[0] == '\xEF') and (L.buf[1] == '\xBB') and (L.buf[2] == '\xBF'):
|
||||||
inc(L.bufpos, 3)
|
inc(L.bufpos, 3)
|
||||||
L.skipPounds = skipPounds
|
L.skipPounds = skipPounds
|
||||||
if skipPounds:
|
if skipPounds:
|
||||||
if L.buf[L.bufpos] == '#': inc(L.bufpos)
|
if L.buf[L.bufpos] == '#':
|
||||||
if L.buf[L.bufpos] == '#': inc(L.bufpos)
|
inc(L.bufpos)
|
||||||
|
inc(result)
|
||||||
|
if L.buf[L.bufpos] == '#':
|
||||||
|
inc(L.bufpos)
|
||||||
|
inc(result)
|
||||||
L.baseIndent = 0
|
L.baseIndent = 0
|
||||||
while L.buf[L.bufpos] == ' ':
|
while L.buf[L.bufpos] == ' ':
|
||||||
inc(L.bufpos)
|
inc(L.bufpos)
|
||||||
inc(L.baseIndent)
|
inc(L.baseIndent)
|
||||||
|
inc(result)
|
||||||
while true:
|
while true:
|
||||||
inc(length)
|
inc(length)
|
||||||
setlen(tokens, length)
|
setlen(tokens, length)
|
||||||
|
|
@ -314,7 +319,7 @@ proc rstMessage(p: TRstParser, msgKind: TMsgKind, arg: string) =
|
||||||
p.col + p.tok[p.idx].col, msgKind, arg)
|
p.col + p.tok[p.idx].col, msgKind, arg)
|
||||||
|
|
||||||
proc rstMessage(p: TRstParser, msgKind: TMsgKind, arg: string, line, col: int) =
|
proc rstMessage(p: TRstParser, msgKind: TMsgKind, arg: string, line, col: int) =
|
||||||
p.s.msgHandler(p.filename, p.line + line,
|
p.s.msgHandler(p.filename, p.line + line,
|
||||||
p.col + col, msgKind, arg)
|
p.col + col, msgKind, arg)
|
||||||
|
|
||||||
proc rstMessage(p: TRstParser, msgKind: TMsgKind) =
|
proc rstMessage(p: TRstParser, msgKind: TMsgKind) =
|
||||||
|
|
@ -692,6 +697,7 @@ proc parseUntil(p: var TRstParser, father: PRstNode, postfix: string,
|
||||||
let
|
let
|
||||||
line = p.tok[p.idx].line
|
line = p.tok[p.idx].line
|
||||||
col = p.tok[p.idx].col
|
col = p.tok[p.idx].col
|
||||||
|
inc p.idx
|
||||||
while true:
|
while true:
|
||||||
case p.tok[p.idx].kind
|
case p.tok[p.idx].kind
|
||||||
of tkPunct:
|
of tkPunct:
|
||||||
|
|
@ -710,7 +716,7 @@ proc parseUntil(p: var TRstParser, father: PRstNode, postfix: string,
|
||||||
add(father, newRstNode(rnLeaf, " "))
|
add(father, newRstNode(rnLeaf, " "))
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
if p.tok[p.idx].kind == tkIndent:
|
if p.tok[p.idx].kind == tkIndent:
|
||||||
rstMessage(p, meExpected, postfix)
|
rstMessage(p, meExpected, postfix, line, col)
|
||||||
break
|
break
|
||||||
of tkWhite:
|
of tkWhite:
|
||||||
add(father, newRstNode(rnLeaf, " "))
|
add(father, newRstNode(rnLeaf, " "))
|
||||||
|
|
@ -751,17 +757,14 @@ proc parseInline(p: var TRstParser, father: PRstNode) =
|
||||||
case p.tok[p.idx].kind
|
case p.tok[p.idx].kind
|
||||||
of tkPunct:
|
of tkPunct:
|
||||||
if isInlineMarkupStart(p, "***"):
|
if isInlineMarkupStart(p, "***"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnTripleEmphasis)
|
var n = newRstNode(rnTripleEmphasis)
|
||||||
parseUntil(p, n, "***", true)
|
parseUntil(p, n, "***", true)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
elif isInlineMarkupStart(p, "**"):
|
elif isInlineMarkupStart(p, "**"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnStrongEmphasis)
|
var n = newRstNode(rnStrongEmphasis)
|
||||||
parseUntil(p, n, "**", true)
|
parseUntil(p, n, "**", true)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
elif isInlineMarkupStart(p, "*"):
|
elif isInlineMarkupStart(p, "*"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnEmphasis)
|
var n = newRstNode(rnEmphasis)
|
||||||
parseUntil(p, n, "*", true)
|
parseUntil(p, n, "*", true)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
|
|
@ -769,18 +772,15 @@ proc parseInline(p: var TRstParser, father: PRstNode) =
|
||||||
inc(p.idx)
|
inc(p.idx)
|
||||||
add(father, parseMarkdownCodeblock(p))
|
add(father, parseMarkdownCodeblock(p))
|
||||||
elif isInlineMarkupStart(p, "``"):
|
elif isInlineMarkupStart(p, "``"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnInlineLiteral)
|
var n = newRstNode(rnInlineLiteral)
|
||||||
parseUntil(p, n, "``", false)
|
parseUntil(p, n, "``", false)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
elif isInlineMarkupStart(p, "`"):
|
elif isInlineMarkupStart(p, "`"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnInterpretedText)
|
var n = newRstNode(rnInterpretedText)
|
||||||
parseUntil(p, n, "`", true)
|
parseUntil(p, n, "`", true)
|
||||||
n = parsePostfix(p, n)
|
n = parsePostfix(p, n)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
elif isInlineMarkupStart(p, "|"):
|
elif isInlineMarkupStart(p, "|"):
|
||||||
inc(p.idx)
|
|
||||||
var n = newRstNode(rnSubstitutionReferences)
|
var n = newRstNode(rnSubstitutionReferences)
|
||||||
parseUntil(p, n, "|", false)
|
parseUntil(p, n, "|", false)
|
||||||
add(father, n)
|
add(father, n)
|
||||||
|
|
@ -873,7 +873,6 @@ proc parseSection(p: var TRstParser, result: PRstNode)
|
||||||
proc parseField(p: var TRstParser): PRstNode =
|
proc parseField(p: var TRstParser): PRstNode =
|
||||||
result = newRstNode(rnField)
|
result = newRstNode(rnField)
|
||||||
var col = p.tok[p.idx].col
|
var col = p.tok[p.idx].col
|
||||||
inc(p.idx) # skip :
|
|
||||||
var fieldname = newRstNode(rnFieldname)
|
var fieldname = newRstNode(rnFieldname)
|
||||||
parseUntil(p, fieldname, ":", false)
|
parseUntil(p, fieldname, ":", false)
|
||||||
var fieldbody = newRstNode(rnFieldbody)
|
var fieldbody = newRstNode(rnFieldbody)
|
||||||
|
|
@ -1156,7 +1155,7 @@ proc parseSimpleTable(p: var TRstParser): PRstNode =
|
||||||
q.col = cols[j]
|
q.col = cols[j]
|
||||||
q.line = line - 1
|
q.line = line - 1
|
||||||
q.filename = p.filename
|
q.filename = p.filename
|
||||||
getTokens(row[j], false, q.tok)
|
q.col += getTokens(row[j], false, q.tok)
|
||||||
b = newRstNode(rnTableDataCell)
|
b = newRstNode(rnTableDataCell)
|
||||||
add(b, parseDoc(q))
|
add(b, parseDoc(q))
|
||||||
add(a, b)
|
add(a, b)
|
||||||
|
|
@ -1459,11 +1458,11 @@ proc dirInclude(p: var TRstParser): PRstNode =
|
||||||
if getFieldValue(n, "literal") != "":
|
if getFieldValue(n, "literal") != "":
|
||||||
result = newRstNode(rnLiteralBlock)
|
result = newRstNode(rnLiteralBlock)
|
||||||
add(result, newRstNode(rnLeaf, readFile(path)))
|
add(result, newRstNode(rnLeaf, readFile(path)))
|
||||||
else:
|
else:
|
||||||
var q: TRstParser
|
var q: TRstParser
|
||||||
initParser(q, p.s)
|
initParser(q, p.s)
|
||||||
q.filename = filename
|
q.filename = filename
|
||||||
getTokens(readFile(path), false, q.tok)
|
q.col += getTokens(readFile(path), false, q.tok)
|
||||||
# workaround a GCC bug; more like the interior pointer bug?
|
# workaround a GCC bug; more like the interior pointer bug?
|
||||||
#if find(q.tok[high(q.tok)].symbol, "\0\x01\x02") > 0:
|
#if find(q.tok[high(q.tok)].symbol, "\0\x01\x02") > 0:
|
||||||
# InternalError("Too many binary zeros in include file")
|
# InternalError("Too many binary zeros in include file")
|
||||||
|
|
@ -1634,7 +1633,6 @@ proc rstParse*(text, filename: string,
|
||||||
initParser(p, newSharedState(options, findFile, msgHandler))
|
initParser(p, newSharedState(options, findFile, msgHandler))
|
||||||
p.filename = filename
|
p.filename = filename
|
||||||
p.line = line
|
p.line = line
|
||||||
p.col = column
|
p.col = column + getTokens(text, roSkipPounds in options, p.tok)
|
||||||
getTokens(text, roSkipPounds in options, p.tok)
|
|
||||||
result = resolveSubs(p, parseDoc(p))
|
result = resolveSubs(p, parseDoc(p))
|
||||||
hasToc = p.hasToc
|
hasToc = p.hasToc
|
||||||
|
|
|
||||||
22
tests/compile/tmatrix2.nim
Normal file
22
tests/compile/tmatrix2.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
discard """
|
||||||
|
output: "5.0000000000000000e+00"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
TMatrixNM*[M, N, T] = object
|
||||||
|
aij*: T
|
||||||
|
TVectorN*[N, T] = TMatrixNM[range[0..0], N, T]
|
||||||
|
TVector3*[T] = TVectorN[range[0..2], T]
|
||||||
|
|
||||||
|
proc coeffRef*[M, N, T] (matrix: var TMatrixNM[M, N, T], a: M, b: N): var T =
|
||||||
|
return matrix.aij
|
||||||
|
|
||||||
|
proc coeffRef*[N, T] (vector: var TVectorN[N, T], i: N): var T = vector.aij
|
||||||
|
|
||||||
|
var
|
||||||
|
testVar: TVector3[float]
|
||||||
|
|
||||||
|
testVar.aij = 2.0
|
||||||
|
testVar.coeffRef(1) = 5.0
|
||||||
|
|
||||||
|
echo testVar.aij
|
||||||
Loading…
Add table
Add a link
Reference in a new issue