Created
November 6, 2020 21:29
-
-
Save doccaico/385c1a52e5237a34361cdb53b0d9c62d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import strutils | |
| # Go version: https://github.com/prologic/monkey-lang/blob/master/parser/parser_tracing.go | |
| # | |
| # when defined(trace): import ./parser_tracing | |
| # [...] | |
| # proc parseProgram(p: var Parser): PNode = | |
| # when defined(trace): TRACE("parseProgram") | |
| # | |
| # $ nim r -d:trace src/parser.nim | |
| var traceLevel: int | |
| const traceIdentPlaceholder = " " | |
| proc identLevel(): string = | |
| return traceIdentPlaceholder.repeat(traceLevel-1) | |
| proc tracePrint(msg: string) = | |
| echo identLevel() & msg | |
| proc incIdent() = traceLevel = traceLevel + 1 | |
| proc decIdent() = traceLevel = traceLevel - 1 | |
| proc trace*(msg: string): string = | |
| incIdent() | |
| tracePrint("BEGIN " & msg) | |
| return msg | |
| proc untrace*(msg: string) = | |
| tracePrint("END " & msg) | |
| decIdent() | |
| template TRACE*(msg: string) = | |
| let traceMsg = trace(msg) | |
| defer: untrace(traceMsg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment