Remove regex. Version bump

This commit is contained in:
Joey Yakimowich-Payne 2020-09-09 04:02:11 -06:00
commit d172421c73
2 changed files with 35 additions and 30 deletions

View file

@ -1,6 +1,6 @@
# Package # Package
version = "0.1.0" version = "0.2.0"
author = "Joey Yakimowich-Payne" author = "Joey Yakimowich-Payne"
description = "GLFW Bindings" description = "GLFW Bindings"
license = "MIT" license = "MIT"
@ -10,4 +10,4 @@ srcDir = "src"
# Dependencies # Dependencies
requires "nim >= 1.0.6", "https://github.com/jyapayne/nimterop#367ec05", "regex" requires "nim >= 1.0.6", "https://github.com/jyapayne/nimterop#367ec05"

View file

@ -1,26 +1,39 @@
import macros, nimterop / plugin import macros, nimterop / plugin
import strutils, regex import strutils
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
template removeBeginning(str, rep: string): string =
if str.startsWith(rep):
str[rep.len .. ^1]
else:
str
proc nothing(m: RegexMatch, s: string): string =
if m.groupsCount > 0 and m.group(0).len > 0:
return s[m.group(0)[0]]
const replacements = [ const replacements = [
re"^GLFW_(.)", "GLFW_",
re"^GLFW(.)", "GLFW",
re"^glfw(.)", "glfw",
] ]
const underscoreReg = re"_(.)"
# Symbol renaming examples # Symbol renaming examples
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} = proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
if sym.name == "GLFW_CURSOR": if sym.name == "GLFW_CURSOR":
@ -31,22 +44,14 @@ 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)
except:
discard
elif sym.kind == nskType: elif sym.kind == nskType:
try: if sym.name.startsWith(rep):
sym.name = sym.name.replace(rep, camelCase) sym.name = camelCase(removeBeginning(sym.name, rep))
except:
discard
else: else:
try: sym.name = removeBeginning(sym.name, rep)
sym.name = sym.name.replace(rep, nothing)
except:
discard
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"