Remove regex. Bump version
This commit is contained in:
parent
944f13a883
commit
de10044993
2 changed files with 40 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
author = "Joey Yakimowich-Payne"
|
author = "Joey Yakimowich-Payne"
|
||||||
description = "SDL2 Autogenerated wrapper"
|
description = "SDL2 Autogenerated wrapper"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
@ -8,7 +8,7 @@ srcDir = "src"
|
||||||
skipDirs = @["build"]
|
skipDirs = @["build"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
requires "nim >= 1.0.6", "https://github.com/jyapayne/nimterop#367ec05", "regex >= 0.14.1"
|
requires "nim >= 1.0.6", "https://github.com/jyapayne/nimterop#367ec05"
|
||||||
|
|
||||||
when gorgeEx("nimble path nimterop").exitCode == 0:
|
when gorgeEx("nimble path nimterop").exitCode == 0:
|
||||||
import nimterop/docs
|
import nimterop/docs
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,41 @@
|
||||||
import macros, nimterop / plugin
|
import macros, nimterop / plugin
|
||||||
import strutils, regex
|
import strutils
|
||||||
import sets
|
import sets
|
||||||
|
|
||||||
proc firstLetterLower(m: RegexMatch, s: string): string =
|
template camelCase(str: string): string =
|
||||||
if m.groupsCount > 0 and m.group(0).len > 0:
|
var res = newStringOfCap(str.len)
|
||||||
return s[m.group(0)[0]].toLowerAscii
|
var i = 0
|
||||||
|
while i < str.len:
|
||||||
|
if str[i] == '_' and i < str.len - 1:
|
||||||
|
res.add(str[i+1].toUpperAscii)
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
res.add(str[i])
|
||||||
|
i += 1
|
||||||
|
res
|
||||||
|
|
||||||
proc camelCase(m: RegexMatch, s: string): string =
|
template lowerFirstLetter(str, rep: string): string =
|
||||||
if m.groupsCount > 0 and m.group(0).len > 0:
|
if str.startsWith(rep):
|
||||||
return s[m.group(0)[0]].toUpperAscii
|
var res = str[rep.len .. ^1]
|
||||||
|
res[0] = res[0].toLowerAscii
|
||||||
|
res
|
||||||
|
else:
|
||||||
|
str
|
||||||
|
|
||||||
proc nothing(m: RegexMatch, s: string): string =
|
template removeBeginning(str, rep: string): string =
|
||||||
if m.groupsCount > 0 and m.group(0).len > 0:
|
if str.startsWith(rep):
|
||||||
return s[m.group(0)[0]]
|
str[rep.len .. ^1]
|
||||||
|
else:
|
||||||
|
str
|
||||||
|
|
||||||
const replacements = [
|
const replacements = [
|
||||||
re"^GPU_(.)",
|
"GPU_",
|
||||||
re"^SDL_(.)",
|
"SDL_",
|
||||||
re"^TTF_(.)",
|
"TTF_",
|
||||||
re"^SDLNet_(.)",
|
"SDLNet_",
|
||||||
re"^Mix_(.)",
|
"Mix_",
|
||||||
re"^IMG_(.)"
|
"IMG_"
|
||||||
]
|
]
|
||||||
const underscoreReg = re"_(.)"
|
|
||||||
|
|
||||||
const EVENT_TYPES = toHashSet([
|
const EVENT_TYPES = toHashSet([
|
||||||
"FIRSTEVENT",
|
"FIRSTEVENT",
|
||||||
|
|
@ -109,15 +122,13 @@ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||||
|
|
||||||
for rep in replacements:
|
for rep in replacements:
|
||||||
if sym.kind == nskProc:
|
if sym.kind == nskProc:
|
||||||
try:
|
sym.name = lowerFirstLetter(sym.name, rep)
|
||||||
sym.name = sym.name.replace(rep, firstLetterLower)
|
# elif sym.kind == nskType:
|
||||||
except:
|
# if sym.name.startsWith(rep):
|
||||||
discard
|
# sym.name = camelCase(removeBeginning(sym.name, rep))
|
||||||
else:
|
else:
|
||||||
try:
|
sym.name = removeBeginning(sym.name, rep)
|
||||||
sym.name = sym.name.replace(rep, nothing)
|
|
||||||
except:
|
|
||||||
discard
|
|
||||||
|
|
||||||
if sym.name.startsWith("SDLK_"):
|
if sym.name.startsWith("SDLK_"):
|
||||||
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
sym.name = sym.name.replace("SDLK_", "KEYCODE_")
|
||||||
|
|
@ -139,7 +150,7 @@ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||||
sym.name = "SDLPRIX64"
|
sym.name = "SDLPRIX64"
|
||||||
|
|
||||||
if sym.kind == nskField:
|
if sym.kind == nskField:
|
||||||
sym.name = sym.name.replace(underscoreReg, camelCase)
|
sym.name = camelCase(sym.name)
|
||||||
if sym.name == "type":
|
if sym.name == "type":
|
||||||
sym.name = "kind"
|
sym.name = "kind"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue