Global command `#` for commenting

I am somewhat ashamed to admit that I repeatedly used the # character to comment out lines of my buspirate scripts. Ok, technically, these are just text files on the host that I copy/paste from… I’m not using the scripting functionality yet). Of course, that doesn’t comment out the line like I hope…

since the # character is the command to reset the buspirate :rofl:.

This began my search for way to enable scripts (and other command-line input) to have inline comments. I think this could also help with the documentation screencasts, such as having the chapter headers also shown as typed-in comments, as the chapter headings are not always clearly visible in the documentation playback.

Review of common programming language options:

Generally, it should avoid conflicting with the first character of any existing valid commands. This excludes the following characters:

  • aAbcdfFgGhilLmopPrstvVwW0-9@#$^(-_.:=~[]{}"/\
  • zZ if added as global command to transition to HiZ mode
Not available

  • Ada style -- … bus syntax conflict (data high)
  • AppleScript (* … script selection conflict
  • C++ // … bus syntax conflict (clock high)
  • C /* .... */ … bus syntax conflict (clock high)
  • Haskell {- ... -} … bus syntax conflict (start 2)
  • Java /** .... */ … bus syntax conflict (clock high)
  • Java // … bus syntax conflict (clock high)
  • LUA --[[ ... ]]-- … bus syntax conflict (data high)
  • Nim # … resets the buspirate
  • Objective-C // … bus syntax conflict (clock high)
  • OCaml (* … script selection conflict (and nesting)
  • Pascal (* … script selection conflict (and nesting)
  • Perl # … resets the buspirate
  • PHP # … resets the buspirate
  • Python # … resets the buspirate
  • R # … resets the buspirate
  • Ruby # … resets the buspirate
  • Ruby =begin … numeric conversion conflict
  • SQL -- … bus syntax conflict (data high)
  • Swift // … bus syntax conflict (clock high)
Available

  • ColdFusion, XML, HTML each use <!--- ... --!>
    • but > is already used
    • might imply multi-line comment support (non-goal)
  • Fortran C
    • but lowercase c conflicts, so undesirable because it would mean case-sensitive commenting
    • also, Fortran knowledge is less common
  • MATLAB %
    • While % is not currently used, may want to keep this for future expansion of bus syntax?
  • BASIC and Windows command scripts rem
    • Conflicts with r bus syntax
    • But already have rm (storage) command … so possible?
    • Broadly understood to comment a single line

Recommendation

I thus propose that rem be added as a global command.

UPDATE: Ian approved changing # to be named reboot, which will allow # to comment out the remaining line of input.

The rem new # command might log the line (e.g., to log files and/or debugger), and is generally for documentation purposes only … no functional effects should rely on this command.

Thoughts?

1 Like

How about we change the command to reset? The single character command is a legacy of Bus Pirate v3.x, which wasn’t really capable of parsing multiple character commands.

Are you suggesting to change # to be a the comment command?

That is a very common way to mark a line as a comment.

If so, I fully support changing # to be a line comment, and adding reset as a new command. :tada:

3 Likes

I think it’s a fair change, but I refuse to do it before the docs update is done :wink:

3 Likes

I seem to recall that one of the BP3 firmware builds included a BASIC interpreter as part of the language/

Crazy talk here… Or future idea…

If the syntax was modified so that each line would start with a number (or to be more precise, no existing command starts with a number and a space) , then it would be possible in the future to have the “number space” prefix tell the BP to store the instruction in memory without execution.

Add a few more commands, ala the BASIC interpreter, the LIST, LOAD and SAVE commands,and the REM command and bingo - you have the ability to edit and document scripts directly on the BP.

The REM command would fit nicely with this idea.

2 Likes

Neat idea but conflicts already with buspirate scripts, which allow numbers.

1 Like

Excuse my memory, but which command starts with a number and a space?

1 Like

I stand corrected. I didn’t see any requirement for there to be something that prevents this, but … I suppose it does:

I2C> [ 0x6C ]

I2C START
TX: 0x6C ACK
I2C STOP
I2C> [ 108 ]

I2C START
TX: 108 ACK
I2C STOP
I2C> 108
Invalid command: 108. Type ? for help.

I had thought this would send the byte across via I2C without requiring a start / stop bit. Hm…

1 Like

The first half of this change is now PR 242:

Rename # to be reboot

1 Like

Thank you for the pull request. It is now in main. Docs have been updated to match.

2 Likes

It seems that - works as a comment prefix at the command line

and # does not yet.

1 Like

Good observation. It seems like we discussed it but didn’t complete that part.

How should the functionality work?

  • # is a command that does nothing
  • # is a command that prints the comment to terminal. This would require updates to the handling of scripts and macros. It would be redundant on the command line though, the comment would print twice. I think the new parser has a “consume all trailing text” function.
  • # does something else (log to file mentioned above)

The most basic functionality to be very useful would be to simply ignore console input lines that begin with #, next sophistication would be to ignore the first unquoted # on a line and the rest of the line.

KISS?

Thanks Ian,

Owen.

1 Like

Yep… my bad for not following up.
I recommend “#” is the first non-whitespace char → Ignore line

1 Like

Added but not tested due to an array of sudden vscode issues. (Aside from losing all the toolchains, it decided to look like a vape shop while doing so).

Thanks for that… Owen.

1 Like