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
version = "0.1.0"
version = "0.2.0"
author = "Joey Yakimowich-Payne"
description = "GLFW Bindings"
license = "MIT"
@ -10,4 +10,4 @@ srcDir = "src"
# 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 strutils, regex
import strutils
proc firstLetterLower(m: RegexMatch, s: string): string =
if m.groupsCount > 0 and m.group(0).len > 0:
return s[m.group(0)[0]].toLowerAscii
template camelCase(str: string): string =
var res = newStringOfCap(str.len)
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 =
if m.groupsCount > 0 and m.group(0).len > 0:
return s[m.group(0)[0]].toUpperAscii
template lowerFirstLetter(str, rep: string): string =
if str.startsWith(rep):
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 = [
re"^GLFW_(.)",
re"^GLFW(.)",
re"^glfw(.)",
"GLFW_",
"GLFW",
"glfw",
]
const underscoreReg = re"_(.)"
# Symbol renaming examples
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
if sym.name == "GLFW_CURSOR":
@ -31,22 +44,14 @@ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
for rep in replacements:
if sym.kind == nskProc:
try:
sym.name = sym.name.replace(rep, firstLetterLower)
except:
discard
sym.name = lowerFirstLetter(sym.name, rep)
elif sym.kind == nskType:
try:
sym.name = sym.name.replace(rep, camelCase)
except:
discard
if sym.name.startsWith(rep):
sym.name = camelCase(removeBeginning(sym.name, rep))
else:
try:
sym.name = sym.name.replace(rep, nothing)
except:
discard
sym.name = removeBeginning(sym.name, rep)
if sym.kind == nskField:
sym.name = sym.name.replace(underscoreReg, camelCase)
sym.name = camelCase(sym.name)
if sym.name == "type":
sym.name = "kind"