Skip to content

Instantly share code, notes, and snippets.

@bmeck
Last active April 25, 2023 03:56
Show Gist options
  • Save bmeck/59cf8c16959eccffd8b7e9828826a842 to your computer and use it in GitHub Desktop.
Save bmeck/59cf8c16959eccffd8b7e9828826a842 to your computer and use it in GitHub Desktop.

Various command line applications use an Interpreter Directive to define how they should be run.

#! js -m foo
#! node foo
#! eshost foo

I propose we add this as a top level syntax to ECMA262 as a comment that can occur before a DirectivePrologue.

Early Errors

None

Evaluation

None

Grammar

Module := HashBang (opt) ...
Script := HashBang (opt) ...
HashBang := "#!" SingleLineCommentChars (opt)

DirectivePrologue Change

DirectivePrologue text should be changed to explicitly allow HashBang to occur in front of it.

Stage 1?

@michaelficarra
Copy link

@bmeck I would call this Shebang instead of InterpreterDirective (to avoid the word "directive") and it should just be the first non-terminal in Script and Module. Something like

Shebang :: #! SingleLineCommentChars(opt)
Script : Shebang(opt) ScriptBody(opt)
Module : Shebang(opt) ModuleBody(opt)

@michaelficarra
Copy link

@bmeck Directive prologues are unrelated to this proposal. You should remove the mention. Remember, directive prologues may be present in function bodies, a location where we definitely don't want to allow shebangs.

@bmeck
Copy link
Author

bmeck commented Nov 13, 2017

@michaelficarra DirectivePrologue is affected by the initial statement list, we need to be sure that HashBang doesn't prevent the DirectivePrologue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment