Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?

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?

@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)

@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.

Owner

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