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 =
|
||||
doAssert name.len != 0, "Blank identifier error"
|
||||
|
||||
let
|
||||
parentStr = if parent.nBl: parent & ":" else: ""
|
||||
|
||||
if name notin gStateRT.symOverride or parent.nBl:
|
||||
if gStateRT.onSymbol != nil:
|
||||
var
|
||||
|
|
@ -101,12 +104,13 @@ proc getIdentifier*(name: string, kind: NimSymKind, parent=""): string =
|
|||
gStateRT.onSymbol(sym)
|
||||
|
||||
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:
|
||||
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:
|
||||
result = &"`{result}`"
|
||||
|
|
|
|||
|
|
@ -65,15 +65,13 @@ macro gitCheckout*(file, outdir: static string): untyped =
|
|||
sleep(500)
|
||||
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
|
||||
outdir = if outdirN.strVal().isAbsolute(): outdirN.strVal() else: getProjectPath()/outdirN.strVal()
|
||||
plist = plistN.strVal()
|
||||
checkout = checkoutN.strVal()
|
||||
outdir = if outdirN.isAbsolute(): outdirN else: getProjectPath()/outdirN
|
||||
|
||||
if dirExists(outdir/".git"):
|
||||
discard quote do:
|
||||
gitReset(`outdirN`)
|
||||
gitReset(`outdir`)
|
||||
return
|
||||
else:
|
||||
let
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ type
|
|||
tonim*: proc (ast: ref Ast, node: TSNode, nimState: NimState)
|
||||
regex*: Regex
|
||||
|
||||
AstTable = TableRef[string, seq[ref Ast]]
|
||||
AstTable {.used.} = TableRef[string, seq[ref Ast]]
|
||||
|
||||
State = object
|
||||
compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string]
|
||||
|
|
@ -58,7 +58,7 @@ type
|
|||
|
||||
onSymbol*: OnSymbol
|
||||
|
||||
NimState = ref object
|
||||
NimState {.used.} = ref object
|
||||
identifiers*: TableRef[string, string]
|
||||
|
||||
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
|
||||
|
|
|
|||
|
|
@ -17,11 +17,14 @@ proc initGrammar(): Grammar =
|
|||
""",
|
||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||
let
|
||||
name = nimState.data[0].val.getIdentifier(nskConst)
|
||||
val = nimState.data[1].val.getLit()
|
||||
|
||||
if name.nBl and val.nBl and nimState.identifiers.addNewIdentifer(name):
|
||||
nimState.constStr &= &" {name}* = {val}\n"
|
||||
if val.nBl:
|
||||
let
|
||||
name = nimState.data[0].val.getIdentifier(nskConst)
|
||||
|
||||
if name.nBl and nimState.identifiers.addNewIdentifer(name):
|
||||
nimState.constStr &= &" {name}* = {val}\n"
|
||||
))
|
||||
|
||||
let
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue