Skip to content

NEP26 DEBUG Label Options

Greg Hewgill edited this page Mar 8, 2024 · 3 revisions

This proposal is to extend the DEBUG statement to accept additional options.

Current Situation

The DEBUG statement takes a sequence of expressions and prints to standard output. The output is printed only if the "debug switch" is turned on, which is a single flag for everything. You either get no debug output, or you get all the debug output.

Proposed Enhancement

Add the ability to attach a tag (textual value) or level (numeric value) to DEBUG statements. Also add the ability to enable or disable debug output by tag and debug level.

The DEBUG statement accepts an optional identifier with a special syntax:

DEBUG <tag:level> expr

where tag is an identifier, and level is a literal integer greater than or equal to 1. (The angle brackets are chosen because an expression cannot start with a <.) For example:

DEBUG <proc:2> width

The above would have the tag proc and the level 2.

When enabling debug messages, the level can be set differently for different tags. The DEBUG statement runs if the requested level is greater than or equal to the declared level in the statement. For example, the command line option for the usual neon executor is -d:

neon -d test.neon

Specifying a debug level might look like:

neon -d=proc:2 test.neon

More than one debug level may be specified:

neon -d=proc:2 -d=bar:1 test.neon

For runtime modification of debug flags, a new function in the debugger module is added:

FUNCTION setLevel(tag: String, level: Number)