This repository has been archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
spec.html
48 lines (38 loc) · 3.08 KB
/
spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!doctype html>
<meta charset="utf8">
<pre class=metadata>
title: Hashbang Grammar for JS
stage: 4
contributors: Bradley Farias
</pre>
<emu-intro id=sec-intro>
<h1>Introduction</h1>
<p>This document attempts to introduce a grammar production for the common interpreter directive syntax that occurs in command-line application usage.</p>
</emu-intro>
<emu-clause id=sec-syntax>
<h1>Syntax</h1>
<emu-clause id=sec-updated-syntax>
<h1>ECMAScript Language: Lexical Grammar</h1>
<p>The source text of an ECMAScript |Script| or |Module| is first converted into a sequence of input elements, which are tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible sequence of code points as the next input element.</p>
<p>There are several situations where the identification of lexical input elements is sensitive to the syntactic grammar context that is consuming the input elements. This requires multiple goal symbols for the lexical grammar. <ins>The |InputElementHashbangOrRegExp| goal is used at the start of a |Script| or |Module|.</ins> The |InputElementRegExpOrTemplateTail| goal is used in syntactic grammar contexts where a |RegularExpressionLiteral|, a |TemplateMiddle|, or a |TemplateTail| is permitted. The |InputElementRegExp| goal symbol is used in all syntactic grammar contexts (other than the start of a |Script| or |Module|) where a |RegularExpressionLiteral| is permitted but neither a |TemplateMiddle|, nor a |TemplateTail| is permitted. The |InputElementTemplateTail| goal is used in all syntactic grammar contexts where a |TemplateMiddle| or a |TemplateTail| is permitted but a |RegularExpressionLiteral| is not permitted. In all other contexts, |InputElementDiv| is used as the lexical goal symbol.</p>
</emu-grammar>
<emu-grammar type="definition"><ins>
InputElementHashbangOrRegExp ::
WhiteSpace
LineTerminator
Comment
CommonToken
HashbangComment
RegularExpressionLiteral
</ins></emu-grammar>
<h1>Hashbang Comments</h1>
<p>Hashbang Comments are location-sensitive and like other types of comments are discarded from the stream of input elements for the syntactic grammar.</p>
<emu-grammar type="definition">HashbangComment ::
`#!` SingleLineCommentChars?
</emu-grammar>
</emu-clause>
<emu-clause id="sec-lexical-and-regexp-grammars">
<h1>The Lexical and RegExp Grammars</h1>
<p>A <em>lexical grammar</em> for ECMAScript is given in clause <emu-xref href="#sec-ecmascript-language-lexical-grammar"></emu-xref>. This grammar has as its terminal symbols Unicode code points that conform to the rules for |SourceCharacter| defined in <emu-xref href="#sec-source-text"></emu-xref>. It defines a set of productions, starting from the goal symbol |InputElementDiv|, |InputElementTemplateTail|, |InputElementRegExp|, |InputElementRegExpOrTemplateTail|, <ins>or |InputElementHashbangOrRegExp|</ins> that describe how sequences of such code points are translated into a sequence of input elements.</p>
</emu-clause>
</emu-clause>