Better context in _ error msg, gitPull fix for path, allow suppress of #define _X
This commit is contained in:
parent
62b44fc1e2
commit
31ec7987db
4 changed files with 18 additions and 13 deletions
|
|
@ -94,6 +94,9 @@ template checkUnderscores(name, errmsg: string): untyped =
|
||||||
proc getIdentifier*(name: string, kind: NimSymKind, parent=""): string =
|
proc getIdentifier*(name: string, kind: NimSymKind, parent=""): string =
|
||||||
doAssert name.len != 0, "Blank identifier error"
|
doAssert name.len != 0, "Blank identifier error"
|
||||||
|
|
||||||
|
let
|
||||||
|
parentStr = if parent.nBl: parent & ":" else: ""
|
||||||
|
|
||||||
if name notin gStateRT.symOverride or parent.nBl:
|
if name notin gStateRT.symOverride or parent.nBl:
|
||||||
if gStateRT.onSymbol != nil:
|
if gStateRT.onSymbol != nil:
|
||||||
var
|
var
|
||||||
|
|
@ -101,12 +104,13 @@ proc getIdentifier*(name: string, kind: NimSymKind, parent=""): string =
|
||||||
gStateRT.onSymbol(sym)
|
gStateRT.onSymbol(sym)
|
||||||
|
|
||||||
result = sym.name
|
result = sym.name
|
||||||
checkUnderscores(result, &"Identifier '{name}' still contains leading/trailing underscores '_' after 'cPlugin:onSymbol()': result '{result}'")
|
checkUnderscores(result, &"Identifier '{parentStr}{name}' ({kind}) still contains leading/trailing underscores '_' after 'cPlugin:onSymbol()': result '{result}'")
|
||||||
|
|
||||||
doAssert result.nBl, &"Blank {kind} '{result}', originally '{name}', child of '{parent}' so cannot be empty"
|
if parent.nBl:
|
||||||
|
doAssert result.nBl, &"Blank identifier, originally '{parentStr}{name}' ({kind}), cannot be empty"
|
||||||
else:
|
else:
|
||||||
result = name
|
result = name
|
||||||
checkUnderscores(result, &"Identifier '{result}' contains unsupported leading/trailing underscores '_': use 'cPlugin:onSymbol()' to remove")
|
checkUnderscores(result, &"Identifier '{parentStr}{result}' ({kind}) contains unsupported leading/trailing underscores '_': use 'cPlugin:onSymbol()' to remove")
|
||||||
|
|
||||||
if result in gReserved:
|
if result in gReserved:
|
||||||
result = &"`{result}`"
|
result = &"`{result}`"
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,13 @@ macro gitCheckout*(file, outdir: static string): untyped =
|
||||||
sleep(500)
|
sleep(500)
|
||||||
echo " Retrying ..."
|
echo " Retrying ..."
|
||||||
|
|
||||||
macro gitPull*(url: static string, outdirN = "", plistN = "", checkoutN = ""): untyped =
|
macro gitPull*(url: static string, outdirN: static string = "", plist: static string = "", checkout: static string = ""): untyped =
|
||||||
let
|
let
|
||||||
outdir = if outdirN.strVal().isAbsolute(): outdirN.strVal() else: getProjectPath()/outdirN.strVal()
|
outdir = if outdirN.isAbsolute(): outdirN else: getProjectPath()/outdirN
|
||||||
plist = plistN.strVal()
|
|
||||||
checkout = checkoutN.strVal()
|
|
||||||
|
|
||||||
if dirExists(outdir/".git"):
|
if dirExists(outdir/".git"):
|
||||||
discard quote do:
|
discard quote do:
|
||||||
gitReset(`outdirN`)
|
gitReset(`outdir`)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ type
|
||||||
tonim*: proc (ast: ref Ast, node: TSNode, nimState: NimState)
|
tonim*: proc (ast: ref Ast, node: TSNode, nimState: NimState)
|
||||||
regex*: Regex
|
regex*: Regex
|
||||||
|
|
||||||
AstTable = TableRef[string, seq[ref Ast]]
|
AstTable {.used.} = TableRef[string, seq[ref Ast]]
|
||||||
|
|
||||||
State = object
|
State = object
|
||||||
compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string]
|
compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string]
|
||||||
|
|
@ -58,7 +58,7 @@ type
|
||||||
|
|
||||||
onSymbol*: OnSymbol
|
onSymbol*: OnSymbol
|
||||||
|
|
||||||
NimState = ref object
|
NimState {.used.} = ref object
|
||||||
identifiers*: TableRef[string, string]
|
identifiers*: TableRef[string, string]
|
||||||
|
|
||||||
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,13 @@ proc initGrammar(): Grammar =
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
let
|
let
|
||||||
name = nimState.data[0].val.getIdentifier(nskConst)
|
|
||||||
val = nimState.data[1].val.getLit()
|
val = nimState.data[1].val.getLit()
|
||||||
|
|
||||||
if name.nBl and val.nBl and nimState.identifiers.addNewIdentifer(name):
|
if val.nBl:
|
||||||
|
let
|
||||||
|
name = nimState.data[0].val.getIdentifier(nskConst)
|
||||||
|
|
||||||
|
if name.nBl and nimState.identifiers.addNewIdentifer(name):
|
||||||
nimState.constStr &= &" {name}* = {val}\n"
|
nimState.constStr &= &" {name}* = {val}\n"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue