Skip to content

Instantly share code, notes, and snippets.

@dgellow
Created July 10, 2015 16:01
Show Gist options
  • Save dgellow/cfaa2106f6ffee46e3a8 to your computer and use it in GitHub Desktop.
Save dgellow/cfaa2106f6ffee46e3a8 to your computer and use it in GitHub Desktop.
Some regexp to find every Nim proc in a file with the given type as first parameter
function nim-procbyfirst {
TYPE_FIRST_ARG=$1
FILE=$2
cat "${FILE}" |
grep -P "^\s*proc\s*(?:\`.+\`|\w+)\*(\[.+\])?\(\w+:\s${TYPE_FIRST_ARG=}" |
grep -oh -P '(?<=proc\s)(?:\`.+\`|\w+).+'
}
# Exemple (system.nim is a local file):
# $ nim-procbyfirst string system.nim
# len*(x: string): int {.magic: "LengthStr", noSideEffect.}
# compileOption*(option: string): bool {.
# copy*(s: string, first = 0): string {.
# copy*(s: string, first, last: int): string {.
# substr*(s: string, first = 0): string {.
# substr*(s: string, first, last: int): string {.
# getRefcount*(x: string): int {.importc: "getRefcount", noSideEffect.}
# isNil*(x: string): bool {.noSideEffect, magic: "IsNil".}
# GC_ref*(x: string) {.magic: "GCref", benign.}
# GC_unref*(x: string) {.magic: "GCunref", benign.}
# open*(filename: string,
# readFile*(filename: string): TaintedString {.tags: [ReadIOEffect], benign.}
# quit*(errormsg: string, errorcode = QuitFailure) {.noReturn.} =
# `[]`*(s: string, x: Slice[int]): string {.inline.} =
# slurp*(filename: string): string {.magic: "Slurp".}
# staticRead*(filename: string): string {.magic: "Slurp".}
# gorge*(command: string, input = ""): string {.
# staticExec*(command: string, input = ""): string {.
# raiseAssert*(msg: string) {.noinline.} =
# failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
# xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment