implemented #133
This commit is contained in:
parent
c9513c2e5a
commit
98fd408adc
3 changed files with 40 additions and 5 deletions
|
|
@ -620,7 +620,7 @@ proc parseIdentColonEquals(p: var TParser, flags: TDeclaredIdentFlags): PNode =
|
||||||
else:
|
else:
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
|
|
||||||
proc parseTuple(p: var TParser): PNode =
|
proc parseTuple(p: var TParser, indentAllowed = false): PNode =
|
||||||
result = newNodeP(nkTupleTy, p)
|
result = newNodeP(nkTupleTy, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
if p.tok.tokType == tkBracketLe:
|
if p.tok.tokType == tkBracketLe:
|
||||||
|
|
@ -634,6 +634,29 @@ proc parseTuple(p: var TParser): PNode =
|
||||||
optInd(p, a)
|
optInd(p, a)
|
||||||
optPar(p)
|
optPar(p)
|
||||||
eat(p, tkBracketRi)
|
eat(p, tkBracketRi)
|
||||||
|
elif indentAllowed:
|
||||||
|
skipComment(p, result)
|
||||||
|
if p.tok.tokType == tkInd:
|
||||||
|
pushInd(p.lex, p.tok.indent)
|
||||||
|
getTok(p)
|
||||||
|
skipComment(p, result)
|
||||||
|
while true:
|
||||||
|
case p.tok.tokType
|
||||||
|
of tkSad:
|
||||||
|
getTok(p)
|
||||||
|
of tkSymbol, tkAccent:
|
||||||
|
var a = parseIdentColonEquals(p, {})
|
||||||
|
skipComment(p, a)
|
||||||
|
addSon(result, a)
|
||||||
|
of tkDed:
|
||||||
|
getTok(p)
|
||||||
|
break
|
||||||
|
of tkEof:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
parMessage(p, errIdentifierExpected, p.tok)
|
||||||
|
break
|
||||||
|
popInd(p.lex)
|
||||||
|
|
||||||
proc parseParamList(p: var TParser, retColon = true): PNode =
|
proc parseParamList(p: var TParser, retColon = true): PNode =
|
||||||
var a: PNode
|
var a: PNode
|
||||||
|
|
@ -1380,6 +1403,7 @@ proc parseTypeDef(p: var TParser): PNode =
|
||||||
of tkObject: a = parseObject(p)
|
of tkObject: a = parseObject(p)
|
||||||
of tkEnum: a = parseEnum(p)
|
of tkEnum: a = parseEnum(p)
|
||||||
of tkDistinct: a = parseDistinct(p)
|
of tkDistinct: a = parseDistinct(p)
|
||||||
|
of tkTuple: a = parseTuple(p, true)
|
||||||
else: a = parseTypeDesc(p)
|
else: a = parseTypeDesc(p)
|
||||||
addSon(result, a)
|
addSon(result, a)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -924,8 +924,8 @@ order.
|
||||||
|
|
||||||
The assignment operator for tuples copies each component.
|
The assignment operator for tuples copies each component.
|
||||||
The default assignment operator for objects copies each component. Overloading
|
The default assignment operator for objects copies each component. Overloading
|
||||||
of the assignment operator for objects is not possible, but this may change in
|
of the assignment operator for objects is not possible, but this will change
|
||||||
future versions of the compiler.
|
in future versions of the compiler.
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
|
|
||||||
|
|
@ -940,7 +940,16 @@ future versions of the compiler.
|
||||||
person = ("Peter", 30)
|
person = ("Peter", 30)
|
||||||
|
|
||||||
The implementation aligns the fields for best access performance. The alignment
|
The implementation aligns the fields for best access performance. The alignment
|
||||||
is compatible with the way the C compiler does it.
|
is compatible with the way the C compiler does it. For consistency
|
||||||
|
with ``object`` declarations, tuples in a ``type`` section can also be defined
|
||||||
|
with indentation instead of ``[]``:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
|
||||||
|
type
|
||||||
|
TPerson = tuple # type representing a person
|
||||||
|
name: string # a person consists of a name
|
||||||
|
age: natural # and an age
|
||||||
|
|
||||||
Objects provide many features that tuples do not. Object provide inheritance
|
Objects provide many features that tuples do not. Object provide inheritance
|
||||||
and information hiding. Objects have access to their type at runtime, so that
|
and information hiding. Objects have access to their type at runtime, so that
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
|
|
||||||
type
|
type
|
||||||
PNode = ref TNode
|
PNode = ref TNode
|
||||||
TNode = tuple[self: PNode]
|
TNode = tuple # comment
|
||||||
|
self: PNode # comment
|
||||||
|
a, b: int # comment
|
||||||
|
|
||||||
var node: PNode
|
var node: PNode
|
||||||
new(node)
|
new(node)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue