From 2d05bcf0a8cd559144c4c0fbbc2f9ba91c55abe7 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Tue, 6 Jan 2015 00:47:38 +0000 Subject: [PATCH] changed QtObject macro syntax --- Nim/Docs/NimQml.txt | 2 +- Nim/Examples/QtObjectMacro/Contact.nim | 2 +- Nim/NimQml/NimQmlMacros.nim | 28 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Nim/Docs/NimQml.txt b/Nim/Docs/NimQml.txt index dd7dccf..1655be8 100644 --- a/Nim/Docs/NimQml.txt +++ b/Nim/Docs/NimQml.txt @@ -231,5 +231,5 @@ In details: The ``QtProperty`` macro has the following syntax .. code-block:: nim - QtProperty nameOfProperty of typeOfProperty + QtProperty[typeOfProperty] nameOfProperty diff --git a/Nim/Examples/QtObjectMacro/Contact.nim b/Nim/Examples/QtObjectMacro/Contact.nim index a16d3f2..7b9c79e 100644 --- a/Nim/Examples/QtObjectMacro/Contact.nim +++ b/Nim/Examples/QtObjectMacro/Contact.nim @@ -21,7 +21,7 @@ QtObject: contact.m_name = name contact.nameChanged() - QtProperty name of string: + QtProperty[string] name: read = getName write = setName notify = nameChanged diff --git a/Nim/NimQml/NimQmlMacros.nim b/Nim/NimQml/NimQmlMacros.nim index 8e746e9..40372d7 100644 --- a/Nim/NimQml/NimQmlMacros.nim +++ b/Nim/NimQml/NimQmlMacros.nim @@ -327,7 +327,13 @@ macro QtObject*(qtDecl: stmt): stmt {.immediate.} = elif it.kind == nnkProcDef: userDefined.add it elif it.kind == nnkCommand: - let cmdIdent = it[0] + let bracket = it[0] + if bracket.kind != nnkBracketExpr: + error("do not know how to handle: \n" & repr(it)) + # BracketExpr + # Ident !"QtProperty" + # Ident !"string" + let cmdIdent = bracket[0] if cmdIdent == nil or cmdIdent.kind != nnkIdent or ($cmdIdent).toLower() != "qtproperty": error("do not know how to handle: \n" & repr(it)) @@ -406,19 +412,19 @@ macro QtObject*(qtDecl: stmt): stmt {.immediate.} = let call = newCall(regSigDot, newLit name, argTypesArray) createBody.add call for property in properties: - #echo treeRepr property - let infix = property[1] - expectKind infix, nnkInfix - # Infix - # Ident !"of" - # Ident !"name" - # Ident !"string" - - let nimPropType = infix[2] + let bracket = property[0] + expectKind bracket, nnkBracketExpr + #Command + # BracketExpr + # Ident !"QtProperty" + # Ident !"string" + # Ident !"name" + # StmtList + let nimPropType = bracket[1] let qtPropMeta = nim2QtMeta[$nimPropType] if qtPropMeta == nil: error($nimPropType & " not supported") let metaDot = newDotExpr(ident "QMetaType", ident qtPropMeta) - let propertyName = infix[1] + let propertyName = property[1] var read, write, notify: PNimrodNode let stmtList = property[2] # fields