diff options
author | Araq <rumpf_a@web.de> | 2016-05-10 21:58:50 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2016-05-10 22:03:07 +0200 |
commit | 97129ebd8af6083ba3ae656226833d026a80a416 (patch) | |
tree | 5137af794005077846dc1f414774d02cbf672dff /lib/core/macros.nim | |
parent | e101773d8b9720a87db022030cc057b91c9e2db4 (diff) | |
download | Nim-97129ebd8af6083ba3ae656226833d026a80a416.tar.gz |
added another version of eqIdent
Diffstat (limited to 'lib/core/macros.nim')
-rw-r--r-- | lib/core/macros.nim | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 678982a52..2e3596d0f 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -818,6 +818,8 @@ proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} = else: result = c var i = 0 var j = 0 + # first char is case sensitive + if a[0] != b[0]: return 1 while true: while a[i] == '_': inc(i) while b[j] == '_': inc(j) # BUGFIX: typo @@ -828,9 +830,23 @@ proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} = inc(i) inc(j) -proc eqIdent* (a, b: string): bool = cmpIgnoreStyle(a, b) == 0 +proc eqIdent*(a, b: string): bool = cmpIgnoreStyle(a, b) == 0 ## Check if two idents are identical. +proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} = + ## Check if node is some identifier node (``nnkIdent``, ``nnkSym``, etc.) + ## is the same as ``s``. Note that this is the preferred way to check! Most + ## other ways like ``node.ident`` are much more error-prone, unfortunately. + case node.kind + of nnkIdent: + result = node.ident == !s + of nnkSym: + result = eqIdent($node.symbol, s) + of nnkOpenSymChoice, nnkClosedSymChoice: + result = eqIdent($node[0], s) + else: + result = false + proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}= ## Search nnkFormalParams for an argument. assert params.kind == nnkFormalParams |