From dbe5766914a6bcb272379a1e5423e2ecf35aaee2 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 19:59:25 +0100 Subject: Start with tex-based syntax description --- docs/docs/internals/syntax.md | 327 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 327 insertions(+) create mode 100644 docs/docs/internals/syntax.md (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md new file mode 100644 index 000000000..cbf2b0ce4 --- /dev/null +++ b/docs/docs/internals/syntax.md @@ -0,0 +1,327 @@ +% $Id: SyntaxSummary.tex 21104 2010-03-08 13:49:27Z odersky $ + +\chapter{Scala Syntax Summary}\label{sec:syntax} +\todo{introduce SeqPattern syntax} + +The lexical syntax of Scala is given by the following grammar in EBNF +form. + +{\small +\begin{lstlisting} + upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ + lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ + letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ + digit ::= `0' | $\cdots$ | `9' + opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ + $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ + + op ::= opchar {opchar} + varid ::= lower idrest + alphaid ::= upper idrest + | varid + plainid ::= alphaid + | op + id ::= plainid + | `\`' stringLit `\`' + | INT // interpolation id, only for quasi-quotes + idrest ::= {letter | digit} [`_' op] + + integerLiteral ::= (decimalNumeral | hexNumera) [`L' | `l'] + decimalNumeral ::= `0' | nonZeroDigit {digit} + hexNumeral ::= `0' `x' hexDigit {hexDigit} + digit ::= `0' | nonZeroDigit + nonZeroDigit ::= `1' | $\cdots$ | `9' + octalDigit ::= `0' | $\cdots$ | `7' + + floatingPointLiteral + ::= digit {digit} `.' {digit} [exponentPart] [floatType] + | `.' digit {digit} [exponentPart] [floatType] + | digit {digit} exponentPart [floatType] + | digit {digit} [exponentPart] floatType + exponentPart ::= (`E' | `e') [`+' | `-'] digit {digit} + floatType ::= `F' | `f' | `D' | `d' + + booleanLiteral ::= `true' | `false' + + characterLiteral ::= `\'' printableChar `\'' + | `\'' charEscapeSeq `\'' + + stringLiteral ::= `"' {stringElement} `"' + | `"""' {[`"'] [`"'] char \ `"'} {`"'} `"""' + stringElement ::= printableChar \ (`"' | `\') + | charEscapeSeq + charEscapeSeq ::= `\b' | `\n' | `\t' | `\f' | `\r' | `"' | `'' | `\\' + + processedStringLiteral + ::= alphaid`"' {printableChar \ (`"' | `$') | escape} `"' + | alphaid `"""' {[`"'] [`"'] char \ (`"' | `$') | escape} {`"'} `"""' + escape ::= `$$' \comment{$} + | `$' letter { letter | digit } + | `{' Block [`;' whiteSpace stringFormat whiteSpace] `}' + stringFormat ::= {printableChar \ (`"' | `}' | ` ' | `\t' | `\n')} + whiteSpace ::= {` ' | `\t'} + + symbolLiteral ::= `'' plainid + + comment ::= `/*' $\mbox{\rm\em ``any sequence of characters''}$ `*/' + | `//' $\mbox{\rm\em ``any sequence of characters up to end of line''}$ + + nl ::= $\mbox{\rm\em ``new line character''}$ + semi ::= `;' | nl {nl} +\end{lstlisting}} + +The context-free syntax of Scala is given by the following EBNF +grammar. + +{\small +\begin{lstlisting} + SimpleLiteral ::= [`-'] integerLiteral + | [`-'] floatingPointLiteral + | booleanLiteral + | characterLiteral + | stringLiteral + Literal ::= SimpleLiteral + | processedStringLiteral + | symbolLiteral + | `null' + + QualId ::= id {`.' id} + ids ::= id {`,' id} + + Path ::= StableId + | [id `.'] `this' + StableId ::= id + | Path `.' id + | [id '.'] `super' [ClassQualifier] `.' id + ClassQualifier ::= `[' id `]' + + Type ::= [`implicit'] FunArgTypes `=>' Type Function(ts, t) + | HkTypeParamClause `=>' Type TypeLambda(ps, t) + | InfixType + FunArgTypes ::= InfixType + | `(' [ FunArgType {`,' FunArgType } ] `)' + InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) + RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) + WithType ::= AnnotType {`with' AnnotType} (deprecated) + AnnotType ::= SimpleType {Annotation} Annotated(t, annot) + SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) + | SimpleType `#' id Select(t, name) + | StableId + | Path `.' `type' SingletonTypeTree(p) + | `(' ArgTypes ')' Tuple(ts) + | `_' TypeBounds + | Refinement RefinedTypeTree(EmptyTree, refinement) + | SimpleLiteral SingletonTypeTree(l) + ArgTypes ::= Type {`,' Type} + | NamedTypeArg {`,' NamedTypeArg } + FunArgType ::= Type + | `=>' Type PrefixOp(=>, t) + ParamType ::= [`=>'] ParamValueType + ParamValueType ::= Type [`*'] PostfixOp(t, "*") + TypeArgs ::= `[' ArgTypes `]' ts + NamedTypeArg ::= id `=' Type NamedArg(id, t) + NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' nts + Refinement ::= `{' [Dcl] {semi [Dcl]} `}' ds + TypeBounds ::= [`>:' Type] [`<: Type] | INT TypeBoundsTree(lo, hi) + TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} ContextBounds(typeBounds, tps) + + Expr ::= [`implicit'] FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) + FunParams ::= Bindings + | id + | `_' + ExprInParens ::= PostfixExpr `:' Type + | Expr + BlockResult ::= [`implicit'] FunParams `=>' Block + | Expr1 + Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) + | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) + | `while' `(' Expr `)' {nl} Expr WhileDo(Parens(cond), body) + | `while' Expr `do' Expr WhileDo(cond, body) + | `do' Expr [semi] `while' Expr DoWhile(expr, cond) + | `try' Expr Catches [`finally' Expr] Try(expr, catches, expr?) + | `try' Expr [`finally' Expr] Try(expr, Nil, expr?) + | `throw' Expr Throw(expr) + | `return' [Expr] Return(expr?) + | ForExpr + | [SimpleExpr `.'] id `=' Expr Assign(expr, expr) + | SimpleExpr1 ArgumentExprs `=' Expr Assign(expr, expr) + | PostfixExpr [Ascription] + | PostfixExpr `match' `{' CaseClauses `}' Match(expr, cases) -- point on match + Ascription ::= `:' InfixType Typed(expr, tp) + | `:' Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) + Catches ::= `catch' Expr + PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) + InfixExpr ::= PrefixExpr + | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) + PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr PrefixOp(expr, op) + SimpleExpr ::= `new' Template New(templ) + | BlockExpr + | SimpleExpr1 [`_'] PostfixOp(expr, _) + SimpleExpr1 ::= Literal + | Path + | `_' + | `(' ExprsInParens2 `)' Parens(exprs) + | SimpleExpr `.' id Select(expr, id) + | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) + | SimpleExpr1 ArgumentExprs Apply(expr, args) + | XmlExpr + ExprsInParens ::= ExprInParens {`,' ExprInParens} + ParArgumentExprs ::= `(' [ExprsInParens] `)' exprs + | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' exprs :+ Typed(expr, Ident(wildcardStar)) + ArgumentExprs ::= ParArgumentExprs + | [nl] BlockExpr + BlockExpr ::= `{' CaseClauses `}' Match(EmptyTree, cases) + | `{' Block `}' block // starts at { + Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) + BlockStat ::= Import + | {Annotation} [`implicit' | `lazy'] Def + | {Annotation} {LocalModifier} TmplDef + | Expr1 + | + + ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') ForYield(enums, expr) + {nl} [`yield'] Expr ForDo(enums, expr) + | `for' Enumerators (`do' Expr | `yield' Expr) + + Enumerators ::= Generator {semi Enumerator | Guard} + Enumerator ::= Generator + | Guard + | Pattern1 `=' Expr GenAlias(pat, expr) + Generator ::= Pattern1 `<-' Expr GenFrom(pat, expr) + Guard ::= `if' PostfixExpr + + CaseClauses ::= CaseClause { CaseClause } + CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at => + + Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats) + Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe)) + | Pattern2 + Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat) + InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) + SimplePattern ::= PatVar Ident(wildcard) + | Literal Bind(name, Ident(wildcard)) + | `(' [Patterns] `)' Parens(pats) Tuple(pats) + | XmlPattern + | SimplePattern1 [TypeArgs] [ArgumentPatterns] + SimplePattern1 ::= Path + | `{' Block `}' + | SimplePattern1 `.' id + PatVar ::= varid + | `_' + Patterns ::= Pattern {`,' Pattern} + ArgumentPatterns ::= `(' [Patterns] `)' Apply(fn, pats) + | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') + + ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' + ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] TypeDef(Modifiers, name, tparams, bounds) + id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) + + DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' + DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds + + TypTypeParamCaluse::= `[' TypTypeParam {`,' TypTypeParam} `]' + TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds + + HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]' + HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_') + TypeBounds + + ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] + ClsParamClause ::= [nl] `(' [ClsParams] ')' + ClsParams ::= ClsParam {`' ClsParam} + ClsParam ::= {Annotation} + [{Modifier} (`val' | `var') | `inline'] Param ValDef(mods, id, tpe, expr) -- point of mods on val/var + Param ::= id `:' ParamType [`=' Expr] + | INT + + DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] + DefParamClause ::= [nl] `(' [DefParams] ')' + DefParams ::= DefParam {`,' DefParam} + DefParam ::= {Annotation} [`inline'] Param ValDef(mods, id, tpe, expr) -- point of mods at id. + + Bindings ::= `(' Binding {`,' Binding}] `)' + Binding ::= (id | `_') [`:' Type] ValDef(_, id, tpe, EmptyTree) + + Modifier ::= LocalModifier + | AccessModifier + | `override' + LocalModifier ::= `abstract' + | `final' + | `sealed' + | `implicit' + | `lazy' + AccessModifier ::= (`private' | `protected') [AccessQualifier] + AccessQualifier ::= `[' (id | `this') `]' + + Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args) + + TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats) + TemplateStat ::= Import + | {Annotation [nl]} {Modifier} Def + | {Annotation [nl]} {Modifier} Dcl + | Expr1 + | + SelfType ::= id [`:' InfixType] `=>' ValDef(_, name, tpt, _) + | `this' `:' InfixType `=> + + Import ::= `import' ImportExpr {`,' ImportExpr} + ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) Import(expr, sels) + ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' + ImportSelector ::= id [`=>' id | `=>' `_'] Ident(name), Pair(id, id) + + Dcl ::= `val' ValDcl + | `var' VarDcl + | `def' DefDcl + | `type' {nl} TypeDcl + | INT + + ValDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) + VarDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) + DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) + DefSig ::= id [DefTypeParamClause] DefParamClauses + TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt) + | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) + + Def ::= `val' PatDef + | `var' VarDef + | `def' DefDef + | `type' {nl} TypeDcl + | TmplDef + | INT + PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr PatDef(_, pats, tpe?, expr) + VarDef ::= PatDef + | ids `:' Type `=' `_' + DefDef ::= DefSig [`:' Type] `=' Expr DefDef(_, name, tparams, vparamss, tpe, expr) + | DefSig [nl] `{' Block `}' DefDef(_, name, tparams, vparamss, tpe, Block) + | `this' DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) + (`=' ConstrExpr | [nl] ConstrBlock) + + TmplDef ::= ([`case'] `class' | `trait') ClassDef + | [`case'] `object' ObjectDef + ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) // + [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat + ConstrMods ::= AccessModifier + | Annotation {Annotation} (AccessModifier | `this') + ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor + TemplateOpt ::= [`extends' Template | [nl] TemplateBody] + Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) + ConstrApps ::= ConstrApp {`with' ConstrApp} + ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) + + ConstrExpr ::= SelfInvocation + | ConstrBlock + ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}' + SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs} + + TopStatSeq ::= TopStat {semi TopStat} + TopStat ::= {Annotation [nl]} {Modifier} TmplDef + | Import + | Packaging + | PackageObject + | + Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' Package(qid, stats) + PackageObject ::= `package' `object' ObjectDef object with package in mods. + + CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) +\end{lstlisting} +} -- cgit v1.2.3 From 669ab6521134340dfa3cdc24afa13b9130aebd4d Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 19:59:54 +0100 Subject: Add markdown header --- docs/docs/internals/syntax.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index cbf2b0ce4..13faa195e 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -1,10 +1,20 @@ -% $Id: SyntaxSummary.tex 21104 2010-03-08 13:49:27Z odersky $ +--- +layout: default +title: "Scala Syntax Summary" +--- -\chapter{Scala Syntax Summary}\label{sec:syntax} -\todo{introduce SeqPattern syntax} +The following descriptions of Scala tokens uses literal characters `‘c’` when +referring to the ASCII fragment `\u0000` – `\u007F`. -The lexical syntax of Scala is given by the following grammar in EBNF -form. +_Unicode escapes_ are used to represent the Unicode character with the given +hexadecimal code: + +```ebnf +UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit +hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | … | ‘f’ +``` + +Informal descriptions are typeset as `“some comment”`. {\small \begin{lstlisting} -- cgit v1.2.3 From 5953a8ef5fa0b4c4477044ac3225da43e9678d50 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 20:01:10 +0100 Subject: Replace tex headers by markdown headers --- docs/docs/internals/syntax.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 13faa195e..5bdc3add2 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -16,8 +16,10 @@ hexDigit ::= ‘0’ | … | ‘9’ | ‘A’ | … | ‘F’ | ‘a’ | Informal descriptions are typeset as `“some comment”`. -{\small -\begin{lstlisting} +### Lexical Syntax +The lexical syntax of Scala is given by the following grammar in EBNF +form. +```ebnf upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ @@ -78,13 +80,14 @@ Informal descriptions are typeset as `“some comment”`. nl ::= $\mbox{\rm\em ``new line character''}$ semi ::= `;' | nl {nl} -\end{lstlisting}} +``` + +## Context-free Syntax The context-free syntax of Scala is given by the following EBNF -grammar. +grammar: -{\small -\begin{lstlisting} +```ebnf SimpleLiteral ::= [`-'] integerLiteral | [`-'] floatingPointLiteral | booleanLiteral @@ -333,5 +336,4 @@ grammar. PackageObject ::= `package' `object' ObjectDef object with package in mods. CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) -\end{lstlisting} -} +``` -- cgit v1.2.3 From 742c794b0c14debb7d953966ce78b0fac24e8bbe Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 20:01:36 +0100 Subject: dedent --- docs/docs/internals/syntax.md | 616 +++++++++++++++++++++--------------------- 1 file changed, 308 insertions(+), 308 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 5bdc3add2..205de4d19 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -20,66 +20,66 @@ Informal descriptions are typeset as `“some comment”`. The lexical syntax of Scala is given by the following grammar in EBNF form. ```ebnf - upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ - lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ - letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ - digit ::= `0' | $\cdots$ | `9' - opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ - $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ - - op ::= opchar {opchar} - varid ::= lower idrest - alphaid ::= upper idrest - | varid - plainid ::= alphaid - | op - id ::= plainid - | `\`' stringLit `\`' - | INT // interpolation id, only for quasi-quotes - idrest ::= {letter | digit} [`_' op] - - integerLiteral ::= (decimalNumeral | hexNumera) [`L' | `l'] - decimalNumeral ::= `0' | nonZeroDigit {digit} - hexNumeral ::= `0' `x' hexDigit {hexDigit} - digit ::= `0' | nonZeroDigit - nonZeroDigit ::= `1' | $\cdots$ | `9' - octalDigit ::= `0' | $\cdots$ | `7' - - floatingPointLiteral - ::= digit {digit} `.' {digit} [exponentPart] [floatType] - | `.' digit {digit} [exponentPart] [floatType] - | digit {digit} exponentPart [floatType] - | digit {digit} [exponentPart] floatType - exponentPart ::= (`E' | `e') [`+' | `-'] digit {digit} - floatType ::= `F' | `f' | `D' | `d' - - booleanLiteral ::= `true' | `false' - - characterLiteral ::= `\'' printableChar `\'' - | `\'' charEscapeSeq `\'' - - stringLiteral ::= `"' {stringElement} `"' - | `"""' {[`"'] [`"'] char \ `"'} {`"'} `"""' - stringElement ::= printableChar \ (`"' | `\') - | charEscapeSeq - charEscapeSeq ::= `\b' | `\n' | `\t' | `\f' | `\r' | `"' | `'' | `\\' - - processedStringLiteral - ::= alphaid`"' {printableChar \ (`"' | `$') | escape} `"' - | alphaid `"""' {[`"'] [`"'] char \ (`"' | `$') | escape} {`"'} `"""' - escape ::= `$$' \comment{$} - | `$' letter { letter | digit } - | `{' Block [`;' whiteSpace stringFormat whiteSpace] `}' - stringFormat ::= {printableChar \ (`"' | `}' | ` ' | `\t' | `\n')} - whiteSpace ::= {` ' | `\t'} - - symbolLiteral ::= `'' plainid - - comment ::= `/*' $\mbox{\rm\em ``any sequence of characters''}$ `*/' - | `//' $\mbox{\rm\em ``any sequence of characters up to end of line''}$ - - nl ::= $\mbox{\rm\em ``new line character''}$ - semi ::= `;' | nl {nl} +upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ +lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ +letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ +digit ::= `0' | $\cdots$ | `9' +opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ + $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ + +op ::= opchar {opchar} +varid ::= lower idrest +alphaid ::= upper idrest + | varid +plainid ::= alphaid + | op +id ::= plainid + | `\`' stringLit `\`' + | INT // interpolation id, only for quasi-quotes +idrest ::= {letter | digit} [`_' op] + +integerLiteral ::= (decimalNumeral | hexNumera) [`L' | `l'] +decimalNumeral ::= `0' | nonZeroDigit {digit} +hexNumeral ::= `0' `x' hexDigit {hexDigit} +digit ::= `0' | nonZeroDigit +nonZeroDigit ::= `1' | $\cdots$ | `9' +octalDigit ::= `0' | $\cdots$ | `7' + +floatingPointLiteral + ::= digit {digit} `.' {digit} [exponentPart] [floatType] + | `.' digit {digit} [exponentPart] [floatType] + | digit {digit} exponentPart [floatType] + | digit {digit} [exponentPart] floatType +exponentPart ::= (`E' | `e') [`+' | `-'] digit {digit} +floatType ::= `F' | `f' | `D' | `d' + +booleanLiteral ::= `true' | `false' + +characterLiteral ::= `\'' printableChar `\'' + | `\'' charEscapeSeq `\'' + +stringLiteral ::= `"' {stringElement} `"' + | `"""' {[`"'] [`"'] char \ `"'} {`"'} `"""' +stringElement ::= printableChar \ (`"' | `\') + | charEscapeSeq +charEscapeSeq ::= `\b' | `\n' | `\t' | `\f' | `\r' | `"' | `'' | `\\' + +processedStringLiteral + ::= alphaid`"' {printableChar \ (`"' | `$') | escape} `"' + | alphaid `"""' {[`"'] [`"'] char \ (`"' | `$') | escape} {`"'} `"""' +escape ::= `$$' \comment{$} + | `$' letter { letter | digit } + | `{' Block [`;' whiteSpace stringFormat whiteSpace] `}' +stringFormat ::= {printableChar \ (`"' | `}' | ` ' | `\t' | `\n')} +whiteSpace ::= {` ' | `\t'} + +symbolLiteral ::= `'' plainid + +comment ::= `/*' $\mbox{\rm\em ``any sequence of characters''}$ `*/' + | `//' $\mbox{\rm\em ``any sequence of characters up to end of line''}$ + +nl ::= $\mbox{\rm\em ``new line character''}$ +semi ::= `;' | nl {nl} ``` ## Context-free Syntax @@ -88,252 +88,252 @@ The context-free syntax of Scala is given by the following EBNF grammar: ```ebnf - SimpleLiteral ::= [`-'] integerLiteral - | [`-'] floatingPointLiteral - | booleanLiteral - | characterLiteral - | stringLiteral - Literal ::= SimpleLiteral - | processedStringLiteral - | symbolLiteral - | `null' - - QualId ::= id {`.' id} - ids ::= id {`,' id} - - Path ::= StableId - | [id `.'] `this' - StableId ::= id - | Path `.' id - | [id '.'] `super' [ClassQualifier] `.' id - ClassQualifier ::= `[' id `]' - - Type ::= [`implicit'] FunArgTypes `=>' Type Function(ts, t) - | HkTypeParamClause `=>' Type TypeLambda(ps, t) - | InfixType - FunArgTypes ::= InfixType - | `(' [ FunArgType {`,' FunArgType } ] `)' - InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) - RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) - WithType ::= AnnotType {`with' AnnotType} (deprecated) - AnnotType ::= SimpleType {Annotation} Annotated(t, annot) - SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) - | SimpleType `#' id Select(t, name) - | StableId - | Path `.' `type' SingletonTypeTree(p) - | `(' ArgTypes ')' Tuple(ts) - | `_' TypeBounds - | Refinement RefinedTypeTree(EmptyTree, refinement) - | SimpleLiteral SingletonTypeTree(l) - ArgTypes ::= Type {`,' Type} - | NamedTypeArg {`,' NamedTypeArg } - FunArgType ::= Type - | `=>' Type PrefixOp(=>, t) - ParamType ::= [`=>'] ParamValueType - ParamValueType ::= Type [`*'] PostfixOp(t, "*") - TypeArgs ::= `[' ArgTypes `]' ts - NamedTypeArg ::= id `=' Type NamedArg(id, t) - NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' nts - Refinement ::= `{' [Dcl] {semi [Dcl]} `}' ds - TypeBounds ::= [`>:' Type] [`<: Type] | INT TypeBoundsTree(lo, hi) - TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} ContextBounds(typeBounds, tps) - - Expr ::= [`implicit'] FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) - FunParams ::= Bindings - | id - | `_' - ExprInParens ::= PostfixExpr `:' Type - | Expr - BlockResult ::= [`implicit'] FunParams `=>' Block - | Expr1 - Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) - | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) - | `while' `(' Expr `)' {nl} Expr WhileDo(Parens(cond), body) - | `while' Expr `do' Expr WhileDo(cond, body) - | `do' Expr [semi] `while' Expr DoWhile(expr, cond) - | `try' Expr Catches [`finally' Expr] Try(expr, catches, expr?) - | `try' Expr [`finally' Expr] Try(expr, Nil, expr?) - | `throw' Expr Throw(expr) - | `return' [Expr] Return(expr?) - | ForExpr - | [SimpleExpr `.'] id `=' Expr Assign(expr, expr) - | SimpleExpr1 ArgumentExprs `=' Expr Assign(expr, expr) - | PostfixExpr [Ascription] - | PostfixExpr `match' `{' CaseClauses `}' Match(expr, cases) -- point on match - Ascription ::= `:' InfixType Typed(expr, tp) - | `:' Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) - Catches ::= `catch' Expr - PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) - InfixExpr ::= PrefixExpr - | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) - PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr PrefixOp(expr, op) - SimpleExpr ::= `new' Template New(templ) - | BlockExpr - | SimpleExpr1 [`_'] PostfixOp(expr, _) - SimpleExpr1 ::= Literal - | Path - | `_' - | `(' ExprsInParens2 `)' Parens(exprs) - | SimpleExpr `.' id Select(expr, id) - | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) - | SimpleExpr1 ArgumentExprs Apply(expr, args) - | XmlExpr - ExprsInParens ::= ExprInParens {`,' ExprInParens} - ParArgumentExprs ::= `(' [ExprsInParens] `)' exprs - | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' exprs :+ Typed(expr, Ident(wildcardStar)) - ArgumentExprs ::= ParArgumentExprs - | [nl] BlockExpr - BlockExpr ::= `{' CaseClauses `}' Match(EmptyTree, cases) - | `{' Block `}' block // starts at { - Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) - BlockStat ::= Import - | {Annotation} [`implicit' | `lazy'] Def - | {Annotation} {LocalModifier} TmplDef - | Expr1 - | - - ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') ForYield(enums, expr) - {nl} [`yield'] Expr ForDo(enums, expr) - | `for' Enumerators (`do' Expr | `yield' Expr) - - Enumerators ::= Generator {semi Enumerator | Guard} - Enumerator ::= Generator - | Guard - | Pattern1 `=' Expr GenAlias(pat, expr) - Generator ::= Pattern1 `<-' Expr GenFrom(pat, expr) - Guard ::= `if' PostfixExpr - - CaseClauses ::= CaseClause { CaseClause } - CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at => - - Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats) - Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe)) - | Pattern2 - Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat) - InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) - SimplePattern ::= PatVar Ident(wildcard) - | Literal Bind(name, Ident(wildcard)) - | `(' [Patterns] `)' Parens(pats) Tuple(pats) - | XmlPattern - | SimplePattern1 [TypeArgs] [ArgumentPatterns] - SimplePattern1 ::= Path - | `{' Block `}' - | SimplePattern1 `.' id - PatVar ::= varid - | `_' - Patterns ::= Pattern {`,' Pattern} - ArgumentPatterns ::= `(' [Patterns] `)' Apply(fn, pats) - | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') - - ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' - ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] TypeDef(Modifiers, name, tparams, bounds) - id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) - - DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' - DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds - - TypTypeParamCaluse::= `[' TypTypeParam {`,' TypTypeParam} `]' - TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds - - HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]' - HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_') - TypeBounds - - ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] - ClsParamClause ::= [nl] `(' [ClsParams] ')' - ClsParams ::= ClsParam {`' ClsParam} - ClsParam ::= {Annotation} - [{Modifier} (`val' | `var') | `inline'] Param ValDef(mods, id, tpe, expr) -- point of mods on val/var - Param ::= id `:' ParamType [`=' Expr] - | INT - - DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] - DefParamClause ::= [nl] `(' [DefParams] ')' - DefParams ::= DefParam {`,' DefParam} - DefParam ::= {Annotation} [`inline'] Param ValDef(mods, id, tpe, expr) -- point of mods at id. - - Bindings ::= `(' Binding {`,' Binding}] `)' - Binding ::= (id | `_') [`:' Type] ValDef(_, id, tpe, EmptyTree) - - Modifier ::= LocalModifier - | AccessModifier - | `override' - LocalModifier ::= `abstract' - | `final' - | `sealed' - | `implicit' - | `lazy' - AccessModifier ::= (`private' | `protected') [AccessQualifier] - AccessQualifier ::= `[' (id | `this') `]' - - Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args) - - TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats) - TemplateStat ::= Import - | {Annotation [nl]} {Modifier} Def - | {Annotation [nl]} {Modifier} Dcl - | Expr1 - | - SelfType ::= id [`:' InfixType] `=>' ValDef(_, name, tpt, _) - | `this' `:' InfixType `=> - - Import ::= `import' ImportExpr {`,' ImportExpr} - ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) Import(expr, sels) - ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' - ImportSelector ::= id [`=>' id | `=>' `_'] Ident(name), Pair(id, id) - - Dcl ::= `val' ValDcl - | `var' VarDcl - | `def' DefDcl - | `type' {nl} TypeDcl - | INT - - ValDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) - VarDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) - DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) - DefSig ::= id [DefTypeParamClause] DefParamClauses - TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt) - | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) - - Def ::= `val' PatDef - | `var' VarDef - | `def' DefDef - | `type' {nl} TypeDcl - | TmplDef - | INT - PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr PatDef(_, pats, tpe?, expr) - VarDef ::= PatDef - | ids `:' Type `=' `_' - DefDef ::= DefSig [`:' Type] `=' Expr DefDef(_, name, tparams, vparamss, tpe, expr) - | DefSig [nl] `{' Block `}' DefDef(_, name, tparams, vparamss, tpe, Block) - | `this' DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) - (`=' ConstrExpr | [nl] ConstrBlock) - - TmplDef ::= ([`case'] `class' | `trait') ClassDef - | [`case'] `object' ObjectDef - ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) // - [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat - ConstrMods ::= AccessModifier - | Annotation {Annotation} (AccessModifier | `this') - ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor - TemplateOpt ::= [`extends' Template | [nl] TemplateBody] - Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) - ConstrApps ::= ConstrApp {`with' ConstrApp} - ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) - - ConstrExpr ::= SelfInvocation - | ConstrBlock - ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}' - SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs} - - TopStatSeq ::= TopStat {semi TopStat} - TopStat ::= {Annotation [nl]} {Modifier} TmplDef - | Import - | Packaging - | PackageObject - | - Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' Package(qid, stats) - PackageObject ::= `package' `object' ObjectDef object with package in mods. - - CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) +SimpleLiteral ::= [`-'] integerLiteral + | [`-'] floatingPointLiteral + | booleanLiteral + | characterLiteral + | stringLiteral +Literal ::= SimpleLiteral + | processedStringLiteral + | symbolLiteral + | `null' + +QualId ::= id {`.' id} +ids ::= id {`,' id} + +Path ::= StableId + | [id `.'] `this' +StableId ::= id + | Path `.' id + | [id '.'] `super' [ClassQualifier] `.' id +ClassQualifier ::= `[' id `]' + +Type ::= [`implicit'] FunArgTypes `=>' Type Function(ts, t) + | HkTypeParamClause `=>' Type TypeLambda(ps, t) + | InfixType +FunArgTypes ::= InfixType + | `(' [ FunArgType {`,' FunArgType } ] `)' +InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) +RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) +WithType ::= AnnotType {`with' AnnotType} (deprecated) +AnnotType ::= SimpleType {Annotation} Annotated(t, annot) +SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) + | SimpleType `#' id Select(t, name) + | StableId + | Path `.' `type' SingletonTypeTree(p) + | `(' ArgTypes ')' Tuple(ts) + | `_' TypeBounds + | Refinement RefinedTypeTree(EmptyTree, refinement) + | SimpleLiteral SingletonTypeTree(l) +ArgTypes ::= Type {`,' Type} + | NamedTypeArg {`,' NamedTypeArg } +FunArgType ::= Type + | `=>' Type PrefixOp(=>, t) +ParamType ::= [`=>'] ParamValueType +ParamValueType ::= Type [`*'] PostfixOp(t, "*") +TypeArgs ::= `[' ArgTypes `]' ts +NamedTypeArg ::= id `=' Type NamedArg(id, t) +NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' nts +Refinement ::= `{' [Dcl] {semi [Dcl]} `}' ds +TypeBounds ::= [`>:' Type] [`<: Type] | INT TypeBoundsTree(lo, hi) +TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} ContextBounds(typeBounds, tps) + +Expr ::= [`implicit'] FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) +FunParams ::= Bindings + | id + | `_' +ExprInParens ::= PostfixExpr `:' Type + | Expr +BlockResult ::= [`implicit'] FunParams `=>' Block + | Expr1 +Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) + | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) + | `while' `(' Expr `)' {nl} Expr WhileDo(Parens(cond), body) + | `while' Expr `do' Expr WhileDo(cond, body) + | `do' Expr [semi] `while' Expr DoWhile(expr, cond) + | `try' Expr Catches [`finally' Expr] Try(expr, catches, expr?) + | `try' Expr [`finally' Expr] Try(expr, Nil, expr?) + | `throw' Expr Throw(expr) + | `return' [Expr] Return(expr?) + | ForExpr + | [SimpleExpr `.'] id `=' Expr Assign(expr, expr) + | SimpleExpr1 ArgumentExprs `=' Expr Assign(expr, expr) + | PostfixExpr [Ascription] + | PostfixExpr `match' `{' CaseClauses `}' Match(expr, cases) -- point on match +Ascription ::= `:' InfixType Typed(expr, tp) + | `:' Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) +Catches ::= `catch' Expr +PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) +InfixExpr ::= PrefixExpr + | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) +PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr PrefixOp(expr, op) +SimpleExpr ::= `new' Template New(templ) + | BlockExpr + | SimpleExpr1 [`_'] PostfixOp(expr, _) +SimpleExpr1 ::= Literal + | Path + | `_' + | `(' ExprsInParens2 `)' Parens(exprs) + | SimpleExpr `.' id Select(expr, id) + | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) + | SimpleExpr1 ArgumentExprs Apply(expr, args) + | XmlExpr +ExprsInParens ::= ExprInParens {`,' ExprInParens} +ParArgumentExprs ::= `(' [ExprsInParens] `)' exprs + | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' exprs :+ Typed(expr, Ident(wildcardStar)) +ArgumentExprs ::= ParArgumentExprs + | [nl] BlockExpr +BlockExpr ::= `{' CaseClauses `}' Match(EmptyTree, cases) + | `{' Block `}' block // starts at { +Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) +BlockStat ::= Import + | {Annotation} [`implicit' | `lazy'] Def + | {Annotation} {LocalModifier} TmplDef + | Expr1 + | + +ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') ForYield(enums, expr) + {nl} [`yield'] Expr ForDo(enums, expr) + | `for' Enumerators (`do' Expr | `yield' Expr) + +Enumerators ::= Generator {semi Enumerator | Guard} +Enumerator ::= Generator + | Guard + | Pattern1 `=' Expr GenAlias(pat, expr) +Generator ::= Pattern1 `<-' Expr GenFrom(pat, expr) +Guard ::= `if' PostfixExpr + +CaseClauses ::= CaseClause { CaseClause } +CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at => + +Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats) +Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe)) + | Pattern2 +Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat) +InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) +SimplePattern ::= PatVar Ident(wildcard) + | Literal Bind(name, Ident(wildcard)) + | `(' [Patterns] `)' Parens(pats) Tuple(pats) + | XmlPattern + | SimplePattern1 [TypeArgs] [ArgumentPatterns] +SimplePattern1 ::= Path + | `{' Block `}' + | SimplePattern1 `.' id +PatVar ::= varid + | `_' +Patterns ::= Pattern {`,' Pattern} +ArgumentPatterns ::= `(' [Patterns] `)' Apply(fn, pats) + | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') + +ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' +ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] TypeDef(Modifiers, name, tparams, bounds) + id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) + +DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' +DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds + +TypTypeParamCaluse::= `[' TypTypeParam {`,' TypTypeParam} `]' +TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds + +HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]' +HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_') + TypeBounds + +ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] +ClsParamClause ::= [nl] `(' [ClsParams] ')' +ClsParams ::= ClsParam {`' ClsParam} +ClsParam ::= {Annotation} + [{Modifier} (`val' | `var') | `inline'] Param ValDef(mods, id, tpe, expr) -- point of mods on val/var +Param ::= id `:' ParamType [`=' Expr] + | INT + +DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] +DefParamClause ::= [nl] `(' [DefParams] ')' +DefParams ::= DefParam {`,' DefParam} +DefParam ::= {Annotation} [`inline'] Param ValDef(mods, id, tpe, expr) -- point of mods at id. + +Bindings ::= `(' Binding {`,' Binding}] `)' +Binding ::= (id | `_') [`:' Type] ValDef(_, id, tpe, EmptyTree) + +Modifier ::= LocalModifier + | AccessModifier + | `override' +LocalModifier ::= `abstract' + | `final' + | `sealed' + | `implicit' + | `lazy' +AccessModifier ::= (`private' | `protected') [AccessQualifier] +AccessQualifier ::= `[' (id | `this') `]' + +Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args) + +TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats) +TemplateStat ::= Import + | {Annotation [nl]} {Modifier} Def + | {Annotation [nl]} {Modifier} Dcl + | Expr1 + | +SelfType ::= id [`:' InfixType] `=>' ValDef(_, name, tpt, _) + | `this' `:' InfixType `=> + +Import ::= `import' ImportExpr {`,' ImportExpr} +ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) Import(expr, sels) +ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' +ImportSelector ::= id [`=>' id | `=>' `_'] Ident(name), Pair(id, id) + +Dcl ::= `val' ValDcl + | `var' VarDcl + | `def' DefDcl + | `type' {nl} TypeDcl + | INT + +ValDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) +VarDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) +DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) +DefSig ::= id [DefTypeParamClause] DefParamClauses +TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt) + | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) + +Def ::= `val' PatDef + | `var' VarDef + | `def' DefDef + | `type' {nl} TypeDcl + | TmplDef + | INT +PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr PatDef(_, pats, tpe?, expr) +VarDef ::= PatDef + | ids `:' Type `=' `_' +DefDef ::= DefSig [`:' Type] `=' Expr DefDef(_, name, tparams, vparamss, tpe, expr) + | DefSig [nl] `{' Block `}' DefDef(_, name, tparams, vparamss, tpe, Block) + | `this' DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) + (`=' ConstrExpr | [nl] ConstrBlock) + +TmplDef ::= ([`case'] `class' | `trait') ClassDef + | [`case'] `object' ObjectDef +ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) // + [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat +ConstrMods ::= AccessModifier + | Annotation {Annotation} (AccessModifier | `this') +ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor +TemplateOpt ::= [`extends' Template | [nl] TemplateBody] +Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) +ConstrApps ::= ConstrApp {`with' ConstrApp} +ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) + +ConstrExpr ::= SelfInvocation + | ConstrBlock +ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}' +SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs} + +TopStatSeq ::= TopStat {semi TopStat} +TopStat ::= {Annotation [nl]} {Modifier} TmplDef + | Import + | Packaging + | PackageObject + | +Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' Package(qid, stats) +PackageObject ::= `package' `object' ObjectDef object with package in mods. + +CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) ``` -- cgit v1.2.3 From 9627306473edd281bc26b4e44131ca1507bb68c2 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 20:04:23 +0100 Subject: Remove tree annotations --- docs/docs/internals/syntax.md | 180 +++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 90 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 205de4d19..fb8545ad5 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -108,37 +108,37 @@ StableId ::= id | [id '.'] `super' [ClassQualifier] `.' id ClassQualifier ::= `[' id `]' -Type ::= [`implicit'] FunArgTypes `=>' Type Function(ts, t) - | HkTypeParamClause `=>' Type TypeLambda(ps, t) +Type ::= [`implicit'] FunArgTypes `=>' Type + | HkTypeParamClause `=>' Type | InfixType FunArgTypes ::= InfixType | `(' [ FunArgType {`,' FunArgType } ] `)' -InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) -RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) -WithType ::= AnnotType {`with' AnnotType} (deprecated) -AnnotType ::= SimpleType {Annotation} Annotated(t, annot) -SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) - | SimpleType `#' id Select(t, name) +InfixType ::= RefinedType {id [nl] RefinedType} +RefinedType ::= WithType {[nl] Refinement} +WithType ::= AnnotType {`with' AnnotType} +AnnotType ::= SimpleType {Annotation} +SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) + | SimpleType `#' id | StableId - | Path `.' `type' SingletonTypeTree(p) - | `(' ArgTypes ')' Tuple(ts) + | Path `.' `type' + | `(' ArgTypes ')' | `_' TypeBounds - | Refinement RefinedTypeTree(EmptyTree, refinement) - | SimpleLiteral SingletonTypeTree(l) + | Refinement + | SimpleLiteral ArgTypes ::= Type {`,' Type} | NamedTypeArg {`,' NamedTypeArg } FunArgType ::= Type - | `=>' Type PrefixOp(=>, t) + | `=>' Type ParamType ::= [`=>'] ParamValueType -ParamValueType ::= Type [`*'] PostfixOp(t, "*") -TypeArgs ::= `[' ArgTypes `]' ts -NamedTypeArg ::= id `=' Type NamedArg(id, t) -NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' nts -Refinement ::= `{' [Dcl] {semi [Dcl]} `}' ds -TypeBounds ::= [`>:' Type] [`<: Type] | INT TypeBoundsTree(lo, hi) -TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} ContextBounds(typeBounds, tps) - -Expr ::= [`implicit'] FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) +ParamValueType ::= Type [`*'] +TypeArgs ::= `[' ArgTypes `]' +NamedTypeArg ::= id `=' Type +NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' +Refinement ::= `{' [Dcl] {semi [Dcl]} `}' +TypeBounds ::= [`>:' Type] [`<: Type] | INT +TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} + +Expr ::= [`implicit'] FunParams `=>' Expr FunParams ::= Bindings | id | `_' @@ -146,74 +146,74 @@ ExprInParens ::= PostfixExpr `:' Type | Expr BlockResult ::= [`implicit'] FunParams `=>' Block | Expr1 -Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) - | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) - | `while' `(' Expr `)' {nl} Expr WhileDo(Parens(cond), body) - | `while' Expr `do' Expr WhileDo(cond, body) - | `do' Expr [semi] `while' Expr DoWhile(expr, cond) - | `try' Expr Catches [`finally' Expr] Try(expr, catches, expr?) - | `try' Expr [`finally' Expr] Try(expr, Nil, expr?) - | `throw' Expr Throw(expr) - | `return' [Expr] Return(expr?) +Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] + | `if' Expr `then' Expr [[semi] else Expr] + | `while' `(' Expr `)' {nl} Expr + | `while' Expr `do' Expr + | `do' Expr [semi] `while' Expr + | `try' Expr Catches [`finally' Expr] + | `try' Expr [`finally' Expr] + | `throw' Expr + | `return' [Expr] | ForExpr - | [SimpleExpr `.'] id `=' Expr Assign(expr, expr) - | SimpleExpr1 ArgumentExprs `=' Expr Assign(expr, expr) + | [SimpleExpr `.'] id `=' Expr + | SimpleExpr1 ArgumentExprs `=' Expr | PostfixExpr [Ascription] - | PostfixExpr `match' `{' CaseClauses `}' Match(expr, cases) -- point on match -Ascription ::= `:' InfixType Typed(expr, tp) - | `:' Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) + | PostfixExpr `match' `{' CaseClauses `}' +Ascription ::= `:' InfixType + | `:' Annotation {Annotation} Catches ::= `catch' Expr -PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) +PostfixExpr ::= InfixExpr [id] InfixExpr ::= PrefixExpr - | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) -PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr PrefixOp(expr, op) -SimpleExpr ::= `new' Template New(templ) + | InfixExpr id [nl] InfixExpr +PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr +SimpleExpr ::= `new' Template | BlockExpr - | SimpleExpr1 [`_'] PostfixOp(expr, _) + | SimpleExpr1 [`_'] SimpleExpr1 ::= Literal | Path | `_' - | `(' ExprsInParens2 `)' Parens(exprs) - | SimpleExpr `.' id Select(expr, id) - | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) - | SimpleExpr1 ArgumentExprs Apply(expr, args) + | `(' ExprsInParens2 `)' + | SimpleExpr `.' id + | SimpleExpr (TypeArgs | NamedTypeArgs) + | SimpleExpr1 ArgumentExprs | XmlExpr ExprsInParens ::= ExprInParens {`,' ExprInParens} -ParArgumentExprs ::= `(' [ExprsInParens] `)' exprs - | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' exprs :+ Typed(expr, Ident(wildcardStar)) +ParArgumentExprs ::= `(' [ExprsInParens] `)' + | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' ArgumentExprs ::= ParArgumentExprs | [nl] BlockExpr -BlockExpr ::= `{' CaseClauses `}' Match(EmptyTree, cases) - | `{' Block `}' block // starts at { -Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) +BlockExpr ::= `{' CaseClauses `}' + | `{' Block `}' +Block ::= {BlockStat semi} [BlockResult] BlockStat ::= Import | {Annotation} [`implicit' | `lazy'] Def | {Annotation} {LocalModifier} TmplDef | Expr1 | -ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') ForYield(enums, expr) - {nl} [`yield'] Expr ForDo(enums, expr) +ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') + {nl} [`yield'] Expr | `for' Enumerators (`do' Expr | `yield' Expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard - | Pattern1 `=' Expr GenAlias(pat, expr) -Generator ::= Pattern1 `<-' Expr GenFrom(pat, expr) + | Pattern1 `=' Expr +Generator ::= Pattern1 `<-' Expr Guard ::= `if' PostfixExpr CaseClauses ::= CaseClause { CaseClause } -CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at => +CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) -Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats) -Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe)) +Pattern ::= Pattern1 { `|' Pattern1 } +Pattern1 ::= PatVar `:' RefinedType | Pattern2 -Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat) -InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) -SimplePattern ::= PatVar Ident(wildcard) - | Literal Bind(name, Ident(wildcard)) - | `(' [Patterns] `)' Parens(pats) Tuple(pats) +Pattern2 ::= [varid `@'] InfixPattern +InfixPattern ::= SimplePattern { id [nl] SimplePattern } +SimplePattern ::= PatVar + | Literal + | `(' [Patterns] `)' | XmlPattern | SimplePattern1 [TypeArgs] [ArgumentPatterns] SimplePattern1 ::= Path @@ -222,12 +222,12 @@ SimplePattern1 ::= Path PatVar ::= varid | `_' Patterns ::= Pattern {`,' Pattern} -ArgumentPatterns ::= `(' [Patterns] `)' Apply(fn, pats) +ArgumentPatterns ::= `(' [Patterns] `)' | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' -ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] TypeDef(Modifiers, name, tparams, bounds) - id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) +ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] + id [HkTypeParamClause] TypeParamBounds DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds @@ -243,17 +243,17 @@ ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] ClsParamClause ::= [nl] `(' [ClsParams] ')' ClsParams ::= ClsParam {`' ClsParam} ClsParam ::= {Annotation} - [{Modifier} (`val' | `var') | `inline'] Param ValDef(mods, id, tpe, expr) -- point of mods on val/var + [{Modifier} (`val' | `var') | `inline'] Param Param ::= id `:' ParamType [`=' Expr] | INT DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] DefParamClause ::= [nl] `(' [DefParams] ')' DefParams ::= DefParam {`,' DefParam} -DefParam ::= {Annotation} [`inline'] Param ValDef(mods, id, tpe, expr) -- point of mods at id. +DefParam ::= {Annotation} [`inline'] Param Bindings ::= `(' Binding {`,' Binding}] `)' -Binding ::= (id | `_') [`:' Type] ValDef(_, id, tpe, EmptyTree) +Binding ::= (id | `_') [`:' Type] Modifier ::= LocalModifier | AccessModifier @@ -266,21 +266,21 @@ LocalModifier ::= `abstract' AccessModifier ::= (`private' | `protected') [AccessQualifier] AccessQualifier ::= `[' (id | `this') `]' -Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args) +Annotation ::= `@' SimpleType {ParArgumentExprs} -TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats) +TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} TemplateStat ::= Import | {Annotation [nl]} {Modifier} Def | {Annotation [nl]} {Modifier} Dcl | Expr1 | -SelfType ::= id [`:' InfixType] `=>' ValDef(_, name, tpt, _) +SelfType ::= id [`:' InfixType] `=>' | `this' `:' InfixType `=> Import ::= `import' ImportExpr {`,' ImportExpr} -ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) Import(expr, sels) +ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' -ImportSelector ::= id [`=>' id | `=>' `_'] Ident(name), Pair(id, id) +ImportSelector ::= id [`=>' id | `=>' `_'] Dcl ::= `val' ValDcl | `var' VarDcl @@ -288,12 +288,12 @@ Dcl ::= `val' ValDcl | `type' {nl} TypeDcl | INT -ValDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) -VarDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) -DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) +ValDcl ::= ids `:' Type +VarDcl ::= ids `:' Type +DefDcl ::= DefSig [`:' Type] DefSig ::= id [DefTypeParamClause] DefParamClauses -TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt) - | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) +TypeDcl ::= id [TypTypeParamClause] ['=' Type] + | id [HkTypeParamClause] TypeBounds Def ::= `val' PatDef | `var' VarDef @@ -301,25 +301,25 @@ Def ::= `val' PatDef | `type' {nl} TypeDcl | TmplDef | INT -PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr PatDef(_, pats, tpe?, expr) +PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr VarDef ::= PatDef | ids `:' Type `=' `_' -DefDef ::= DefSig [`:' Type] `=' Expr DefDef(_, name, tparams, vparamss, tpe, expr) - | DefSig [nl] `{' Block `}' DefDef(_, name, tparams, vparamss, tpe, Block) - | `this' DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) +DefDef ::= DefSig [`:' Type] `=' Expr + | DefSig [nl] `{' Block `}' + | `this' DefParamClause DefParamClauses (`=' ConstrExpr | [nl] ConstrBlock) TmplDef ::= ([`case'] `class' | `trait') ClassDef | [`case'] `object' ObjectDef -ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) // - [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat +ClassDef ::= id [ClsTypeParamClause] + [ConstrMods] ClsParamClauses TemplateOpt ConstrMods ::= AccessModifier | Annotation {Annotation} (AccessModifier | `this') -ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor +ObjectDef ::= id TemplateOpt TemplateOpt ::= [`extends' Template | [nl] TemplateBody] -Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) +Template ::= ConstrApps [TemplateBody] | TemplateBody ConstrApps ::= ConstrApp {`with' ConstrApp} -ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) +ConstrApp ::= AnnotType {ArgumentExprs} ConstrExpr ::= SelfInvocation | ConstrBlock @@ -332,8 +332,8 @@ TopStat ::= {Annotation [nl]} {Modifier} TmplDef | Packaging | PackageObject | -Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' Package(qid, stats) -PackageObject ::= `package' `object' ObjectDef object with package in mods. +Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' +PackageObject ::= `package' `object' ObjectDef -CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) +CompilationUnit ::= {`package' QualId semi} TopStatSeq ``` -- cgit v1.2.3 From e0a1f7ebbcf83dae4aea65218da656759c794d62 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 20:12:54 +0100 Subject: Change quoting of terminals --- docs/docs/internals/syntax.md | 353 +++++++++++++++++++++--------------------- 1 file changed, 177 insertions(+), 176 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index fb8545ad5..0d1ed0f9f 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -20,10 +20,10 @@ Informal descriptions are typeset as `“some comment”`. The lexical syntax of Scala is given by the following grammar in EBNF form. ```ebnf -upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ -lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ +upper ::= ‘A’ | $\cdots$ | ‘Z’ | ‘$\Dollar$’ | ‘_’ $\mbox{\rm\em and Unicode category Lu}$ +lower ::= ‘a’ | $\cdots$ | ‘z’ $\mbox{\rm\em and Unicode category Ll}$ letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ -digit ::= `0' | $\cdots$ | `9' +digit ::= ‘0’ | $\cdots$ | ‘9’ opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ @@ -34,52 +34,52 @@ alphaid ::= upper idrest plainid ::= alphaid | op id ::= plainid - | `\`' stringLit `\`' + | ‘\`’ stringLit ‘\`’ | INT // interpolation id, only for quasi-quotes -idrest ::= {letter | digit} [`_' op] +idrest ::= {letter | digit} [‘_’ op] -integerLiteral ::= (decimalNumeral | hexNumera) [`L' | `l'] -decimalNumeral ::= `0' | nonZeroDigit {digit} -hexNumeral ::= `0' `x' hexDigit {hexDigit} -digit ::= `0' | nonZeroDigit -nonZeroDigit ::= `1' | $\cdots$ | `9' -octalDigit ::= `0' | $\cdots$ | `7' +integerLiteral ::= (decimalNumeral | hexNumera) [‘L’ | ‘l’] +decimalNumeral ::= ‘0’ | nonZeroDigit {digit} +hexNumeral ::= ‘0’ ‘x’ hexDigit {hexDigit} +digit ::= ‘0’ | nonZeroDigit +nonZeroDigit ::= ‘1’ | $\cdots$ | ‘9’ +octalDigit ::= ‘0’ | $\cdots$ | ‘7’ floatingPointLiteral - ::= digit {digit} `.' {digit} [exponentPart] [floatType] - | `.' digit {digit} [exponentPart] [floatType] + ::= digit {digit} ‘.’ {digit} [exponentPart] [floatType] + | ‘.’ digit {digit} [exponentPart] [floatType] | digit {digit} exponentPart [floatType] | digit {digit} [exponentPart] floatType -exponentPart ::= (`E' | `e') [`+' | `-'] digit {digit} -floatType ::= `F' | `f' | `D' | `d' -booleanLiteral ::= `true' | `false' +exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit} +floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’ +booleanLiteral ::= ‘true’ | ‘false’ -characterLiteral ::= `\'' printableChar `\'' - | `\'' charEscapeSeq `\'' +characterLiteral ::= ‘\'’ printableChar ‘\'’ + | ‘\'’ charEscapeSeq ‘\'’ -stringLiteral ::= `"' {stringElement} `"' - | `"""' {[`"'] [`"'] char \ `"'} {`"'} `"""' -stringElement ::= printableChar \ (`"' | `\') +stringLiteral ::= ‘"’ {stringElement} ‘"’ + | ‘"""’ {[‘"’] [‘"’] char \ ‘"’} {‘"’} ‘"""’ +stringElement ::= printableChar \ (‘"’ | ‘\’) | charEscapeSeq -charEscapeSeq ::= `\b' | `\n' | `\t' | `\f' | `\r' | `"' | `'' | `\\' +charEscapeSeq ::= ‘\b’ | ‘\n’ | ‘\t’ | ‘\f’ | ‘\r’ | ‘"’ | ‘'’ | ‘\\’ processedStringLiteral - ::= alphaid`"' {printableChar \ (`"' | `$') | escape} `"' - | alphaid `"""' {[`"'] [`"'] char \ (`"' | `$') | escape} {`"'} `"""' -escape ::= `$$' \comment{$} - | `$' letter { letter | digit } - | `{' Block [`;' whiteSpace stringFormat whiteSpace] `}' -stringFormat ::= {printableChar \ (`"' | `}' | ` ' | `\t' | `\n')} -whiteSpace ::= {` ' | `\t'} + ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape} ‘"’ + | alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’ +escape ::= ‘$$’ \comment{$} + | ‘$’ letter { letter | digit } + | ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’ +stringFormat ::= {printableChar \ (‘"’ | ‘}’ | ‘ ’ | ‘\t’ | ‘\n’)} +whiteSpace ::= {‘ ’ | ‘\t’} -symbolLiteral ::= `'' plainid +symbolLiteral ::= ‘'’ plainid -comment ::= `/*' $\mbox{\rm\em ``any sequence of characters''}$ `*/' - | `//' $\mbox{\rm\em ``any sequence of characters up to end of line''}$ +comment ::= ‘/*’ $\mbox{\rm\em ``any sequence of characters''}$ ‘*/’ + | ‘//’ $\mbox{\rm\em ``any sequence of characters up to end of line''}$ nl ::= $\mbox{\rm\em ``new line character''}$ -semi ::= `;' | nl {nl} +semi ::= ‘;’ | nl {nl} ``` ## Context-free Syntax @@ -88,243 +88,244 @@ The context-free syntax of Scala is given by the following EBNF grammar: ```ebnf -SimpleLiteral ::= [`-'] integerLiteral - | [`-'] floatingPointLiteral +SimpleLiteral ::= [‘-’] integerLiteral + | [‘-’] floatingPointLiteral | booleanLiteral | characterLiteral | stringLiteral Literal ::= SimpleLiteral | processedStringLiteral | symbolLiteral - | `null' + | ‘null’ -QualId ::= id {`.' id} -ids ::= id {`,' id} +QualId ::= id {‘.’ id} +ids ::= id {‘,’ id} Path ::= StableId - | [id `.'] `this' + | [id ‘.’] ‘this’ StableId ::= id - | Path `.' id - | [id '.'] `super' [ClassQualifier] `.' id -ClassQualifier ::= `[' id `]' + | Path ‘.’ id + | [id ‘.’] ‘super’ [ClassQualifier] ‘.’ id +ClassQualifier ::= ‘[’ id ‘]’ -Type ::= [`implicit'] FunArgTypes `=>' Type - | HkTypeParamClause `=>' Type +Type ::= [‘implicit’] FunArgTypes ‘=>’ Type + | HkTypeParamClause ‘=>’ Type | InfixType FunArgTypes ::= InfixType - | `(' [ FunArgType {`,' FunArgType } ] `)' + | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ InfixType ::= RefinedType {id [nl] RefinedType} RefinedType ::= WithType {[nl] Refinement} -WithType ::= AnnotType {`with' AnnotType} +WithType ::= AnnotType {‘with’ AnnotType} AnnotType ::= SimpleType {Annotation} SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) - | SimpleType `#' id + | SimpleType ‘#’ id | StableId - | Path `.' `type' - | `(' ArgTypes ')' - | `_' TypeBounds + | Path ‘.’ ‘type’ + | ‘(’ ArgTypes ‘)’ + | ‘_’ TypeBounds | Refinement | SimpleLiteral -ArgTypes ::= Type {`,' Type} - | NamedTypeArg {`,' NamedTypeArg } +ArgTypes ::= Type {‘,’ Type} + | NamedTypeArg {‘,’ NamedTypeArg } FunArgType ::= Type - | `=>' Type -ParamType ::= [`=>'] ParamValueType -ParamValueType ::= Type [`*'] -TypeArgs ::= `[' ArgTypes `]' -NamedTypeArg ::= id `=' Type -NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' -Refinement ::= `{' [Dcl] {semi [Dcl]} `}' -TypeBounds ::= [`>:' Type] [`<: Type] | INT -TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} - -Expr ::= [`implicit'] FunParams `=>' Expr + | ‘=>’ Type +ParamType ::= [‘=>’] ParamValueType +ParamValueType ::= Type [‘*’] +TypeArgs ::= ‘[’ ArgTypes ‘]’ +NamedTypeArg ::= id ‘=’ Type +NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ +Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ +TypeBounds ::= [‘>:’ Type] [`<: Type] | INT +TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} + +Expr ::= [‘implicit’] FunParams ‘=>’ Expr FunParams ::= Bindings | id - | `_' -ExprInParens ::= PostfixExpr `:' Type + | ‘_’ +ExprInParens ::= PostfixExpr ‘:’ Type | Expr -BlockResult ::= [`implicit'] FunParams `=>' Block +BlockResult ::= [‘implicit’] FunParams ‘=>’ Block | Expr1 -Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] - | `if' Expr `then' Expr [[semi] else Expr] - | `while' `(' Expr `)' {nl} Expr - | `while' Expr `do' Expr - | `do' Expr [semi] `while' Expr - | `try' Expr Catches [`finally' Expr] - | `try' Expr [`finally' Expr] - | `throw' Expr - | `return' [Expr] +Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] else Expr] + | ‘if’ Expr ‘then’ Expr [[semi] else Expr] + | ‘while’ ‘(’ Expr ‘)’ {nl} Expr + | ‘while’ Expr ‘do’ Expr + | ‘do’ Expr [semi] ‘while’ Expr + | ‘try’ Expr Catches [‘finally’ Expr] + | ‘try’ Expr [‘finally’ Expr] + | ‘throw’ Expr + | ‘return’ [Expr] | ForExpr - | [SimpleExpr `.'] id `=' Expr - | SimpleExpr1 ArgumentExprs `=' Expr + | [SimpleExpr ‘.’] id ‘=’ Expr + | SimpleExpr1 ArgumentExprs ‘=’ Expr | PostfixExpr [Ascription] - | PostfixExpr `match' `{' CaseClauses `}' -Ascription ::= `:' InfixType - | `:' Annotation {Annotation} -Catches ::= `catch' Expr + | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ +Ascription ::= ‘:’ InfixType + | ‘:’ Annotation {Annotation} +Catches ::= ‘catch’ Expr PostfixExpr ::= InfixExpr [id] InfixExpr ::= PrefixExpr | InfixExpr id [nl] InfixExpr -PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr -SimpleExpr ::= `new' Template +PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr +SimpleExpr ::= ‘new’ Template | BlockExpr - | SimpleExpr1 [`_'] + | SimpleExpr1 [‘_’] SimpleExpr1 ::= Literal | Path - | `_' - | `(' ExprsInParens2 `)' - | SimpleExpr `.' id + | ‘_’ + | ‘(’ ExprsInParens2 ‘)’ + | SimpleExpr ‘.’ id | SimpleExpr (TypeArgs | NamedTypeArgs) | SimpleExpr1 ArgumentExprs | XmlExpr -ExprsInParens ::= ExprInParens {`,' ExprInParens} -ParArgumentExprs ::= `(' [ExprsInParens] `)' - | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' +ExprsInParens ::= ExprInParens {‘,’ ExprInParens} +ParArgumentExprs ::= ‘(’ [ExprsInParens] ‘)’ + | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ ArgumentExprs ::= ParArgumentExprs | [nl] BlockExpr -BlockExpr ::= `{' CaseClauses `}' - | `{' Block `}' +BlockExpr ::= ‘{’ CaseClauses ‘}’ + | ‘{’ Block ‘}’ Block ::= {BlockStat semi} [BlockResult] BlockStat ::= Import - | {Annotation} [`implicit' | `lazy'] Def + | {Annotation} [‘implicit’ | ‘lazy’] Def | {Annotation} {LocalModifier} TmplDef | Expr1 | -ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') - {nl} [`yield'] Expr - | `for' Enumerators (`do' Expr | `yield' Expr) +ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) + {nl} [‘yield’] Expr + | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard - | Pattern1 `=' Expr -Generator ::= Pattern1 `<-' Expr -Guard ::= `if' PostfixExpr + | Pattern1 ‘=’ Expr +Generator ::= Pattern1 ‘<-’ Expr +Guard ::= ‘if’ PostfixExpr CaseClauses ::= CaseClause { CaseClause } -CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) +CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT) -Pattern ::= Pattern1 { `|' Pattern1 } -Pattern1 ::= PatVar `:' RefinedType +Pattern ::= Pattern1 { ‘|’ Pattern1 } +Pattern1 ::= PatVar ‘:’ RefinedType | Pattern2 -Pattern2 ::= [varid `@'] InfixPattern +Pattern2 ::= [varid ‘@’] InfixPattern InfixPattern ::= SimplePattern { id [nl] SimplePattern } SimplePattern ::= PatVar | Literal - | `(' [Patterns] `)' + | ‘(’ [Patterns] ‘)’ | XmlPattern | SimplePattern1 [TypeArgs] [ArgumentPatterns] SimplePattern1 ::= Path - | `{' Block `}' - | SimplePattern1 `.' id + | ‘{’ Block ‘}’ + | SimplePattern1 ‘.’ id PatVar ::= varid - | `_' -Patterns ::= Pattern {`,' Pattern} -ArgumentPatterns ::= `(' [Patterns] `)' - | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') + | ‘_’ +Patterns ::= Pattern {‘,’ Pattern} +ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ + | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ') -ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' -ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] +ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’ +ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds -DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' +DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’ DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds -TypTypeParamCaluse::= `[' TypTypeParam {`,' TypTypeParam} `]' +TypTypeParamCaluse::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’ TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds -HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]' -HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_') +HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’ +HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] | ‘_’) TypeBounds -ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] -ClsParamClause ::= [nl] `(' [ClsParams] ')' -ClsParams ::= ClsParam {`' ClsParam} +ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ ‘implicit’ ClsParams ‘)’] +ClsParamClause ::= [nl] ‘(’ [ClsParams] ‘)’ +ClsParams ::= ClsParam {‘’ ClsParam} ClsParam ::= {Annotation} - [{Modifier} (`val' | `var') | `inline'] Param -Param ::= id `:' ParamType [`=' Expr] + [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param +Param ::= id ‘:’ ParamType [‘=’ Expr] | INT -DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] -DefParamClause ::= [nl] `(' [DefParams] ')' -DefParams ::= DefParam {`,' DefParam} -DefParam ::= {Annotation} [`inline'] Param +DefParamClauses ::= {DefParamClause} [[nl] ‘(’ ‘implicit’ DefParams ‘)’] +DefParamClause ::= [nl] ‘(’ [DefParams] ‘)’ +DefParams ::= DefParam {‘,’ DefParam} +DefParam ::= {Annotation} [‘inline’] Param -Bindings ::= `(' Binding {`,' Binding}] `)' -Binding ::= (id | `_') [`:' Type] +Bindings ::= ‘(’ Binding {‘,’ Binding}] ‘)’ +Binding ::= (id | ‘_’) [‘:’ Type] Modifier ::= LocalModifier | AccessModifier - | `override' -LocalModifier ::= `abstract' - | `final' - | `sealed' - | `implicit' - | `lazy' -AccessModifier ::= (`private' | `protected') [AccessQualifier] -AccessQualifier ::= `[' (id | `this') `]' - -Annotation ::= `@' SimpleType {ParArgumentExprs} - -TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} + | ‘override’ +LocalModifier ::= ‘abstract’ + | ‘final’ + | ‘sealed’ + | ‘implicit’ + | ‘lazy’ +AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier] +AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’ + +Annotation ::= ‘@’ SimpleType {ParArgumentExprs} + +TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} `} TemplateStat ::= Import | {Annotation [nl]} {Modifier} Def | {Annotation [nl]} {Modifier} Dcl | Expr1 | -SelfType ::= id [`:' InfixType] `=>' - | `this' `:' InfixType `=> - -Import ::= `import' ImportExpr {`,' ImportExpr} -ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) -ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' -ImportSelector ::= id [`=>' id | `=>' `_'] - -Dcl ::= `val' ValDcl - | `var' VarDcl - | `def' DefDcl - | `type' {nl} TypeDcl +SelfType ::= id [‘:’ InfixType] ‘=>’ + | ‘this’ ‘:’ InfixType `=> + +Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} +ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) +ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’ +ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] + +Dcl ::= ‘val’ ValDcl + | ‘var’ VarDcl + | ‘def’ DefDcl + | ‘type’ {nl} TypeDcl | INT -ValDcl ::= ids `:' Type -VarDcl ::= ids `:' Type -DefDcl ::= DefSig [`:' Type] + +ValDcl ::= ids ‘:’ Type +VarDcl ::= ids ‘:’ Type +DefDcl ::= DefSig [‘:’ Type] DefSig ::= id [DefTypeParamClause] DefParamClauses -TypeDcl ::= id [TypTypeParamClause] ['=' Type] +TypeDcl ::= id [TypTypeParamClause] [‘=’ Type] | id [HkTypeParamClause] TypeBounds -Def ::= `val' PatDef - | `var' VarDef - | `def' DefDef - | `type' {nl} TypeDcl +Def ::= ‘val’ PatDef + | ‘var’ VarDef + | ‘def’ DefDef + | ‘type’ {nl} TypeDcl | TmplDef | INT -PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr +PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr VarDef ::= PatDef - | ids `:' Type `=' `_' -DefDef ::= DefSig [`:' Type] `=' Expr - | DefSig [nl] `{' Block `}' - | `this' DefParamClause DefParamClauses - (`=' ConstrExpr | [nl] ConstrBlock) - -TmplDef ::= ([`case'] `class' | `trait') ClassDef - | [`case'] `object' ObjectDef + | ids ‘:’ Type ‘=’ ‘_’ +DefDef ::= DefSig [‘:’ Type] ‘=’ Expr + | DefSig [nl] ‘{’ Block ‘}’ + | ‘this’ DefParamClause DefParamClauses + (‘=’ ConstrExpr | [nl] ConstrBlock) + +TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef + | [‘case’] ‘object’ ObjectDef ClassDef ::= id [ClsTypeParamClause] [ConstrMods] ClsParamClauses TemplateOpt ConstrMods ::= AccessModifier - | Annotation {Annotation} (AccessModifier | `this') + | Annotation {Annotation} (AccessModifier | ‘this’) ObjectDef ::= id TemplateOpt -TemplateOpt ::= [`extends' Template | [nl] TemplateBody] +TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody] Template ::= ConstrApps [TemplateBody] | TemplateBody -ConstrApps ::= ConstrApp {`with' ConstrApp} +ConstrApps ::= ConstrApp {‘with’ ConstrApp} ConstrApp ::= AnnotType {ArgumentExprs} ConstrExpr ::= SelfInvocation | ConstrBlock -ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}' -SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs} +ConstrBlock ::= ‘{’ SelfInvocation {semi BlockStat} ‘}’ +SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} TopStatSeq ::= TopStat {semi TopStat} TopStat ::= {Annotation [nl]} {Modifier} TmplDef @@ -332,8 +333,8 @@ TopStat ::= {Annotation [nl]} {Modifier} TmplDef | Packaging | PackageObject | -Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' -PackageObject ::= `package' `object' ObjectDef +Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ +PackageObject ::= ‘package’ ‘object’ ObjectDef -CompilationUnit ::= {`package' QualId semi} TopStatSeq +CompilationUnit ::= {‘package’ QualId semi} TopStatSeq ``` -- cgit v1.2.3 From 08400a03406e240a1545170625502f32d56bf0f5 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 20:14:13 +0100 Subject: Split into sections --- docs/docs/internals/syntax.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 0d1ed0f9f..82ecdddbb 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -87,6 +87,7 @@ semi ::= ‘;’ | nl {nl} The context-free syntax of Scala is given by the following EBNF grammar: +### Literals and Paths ```ebnf SimpleLiteral ::= [‘-’] integerLiteral | [‘-’] floatingPointLiteral @@ -107,7 +108,10 @@ StableId ::= id | Path ‘.’ id | [id ‘.’] ‘super’ [ClassQualifier] ‘.’ id ClassQualifier ::= ‘[’ id ‘]’ +``` +### Types +```ebnf Type ::= [‘implicit’] FunArgTypes ‘=>’ Type | HkTypeParamClause ‘=>’ Type | InfixType @@ -224,7 +228,10 @@ PatVar ::= varid Patterns ::= Pattern {‘,’ Pattern} ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ') +``` +### Type and Value Parameters +```ebnf ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’ ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] id [HkTypeParamClause] TypeParamBounds @@ -251,7 +258,10 @@ DefParamClauses ::= {DefParamClause} [[nl] ‘(’ ‘implicit’ DefParams DefParamClause ::= [nl] ‘(’ [DefParams] ‘)’ DefParams ::= DefParam {‘,’ DefParam} DefParam ::= {Annotation} [‘inline’] Param +``` +### Bindings and Imports +```ebnf Bindings ::= ‘(’ Binding {‘,’ Binding}] ‘)’ Binding ::= (id | ‘_’) [‘:’ Type] @@ -281,7 +291,10 @@ Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’ ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] +``` +### Declarations and Definitions +```ebnf Dcl ::= ‘val’ ValDcl | ‘var’ VarDcl | ‘def’ DefDcl -- cgit v1.2.3 From f9951fa2ad882302f575e47a544e397fe95de53c Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:34:34 +0100 Subject: Replace tex code in the same way as the scala 2.12 syntax doc --- docs/docs/internals/syntax.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 82ecdddbb..8ff9dc8ef 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -19,13 +19,15 @@ Informal descriptions are typeset as `“some comment”`. ### Lexical Syntax The lexical syntax of Scala is given by the following grammar in EBNF form. + ```ebnf -upper ::= ‘A’ | $\cdots$ | ‘Z’ | ‘$\Dollar$’ | ‘_’ $\mbox{\rm\em and Unicode category Lu}$ -lower ::= ‘a’ | $\cdots$ | ‘z’ $\mbox{\rm\em and Unicode category Ll}$ -letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ -digit ::= ‘0’ | $\cdots$ | ‘9’ -opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ - $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ +upper ::= ‘A’ | … | ‘Z’ | ‘\$’ | ‘_’ “… and Unicode category Lu” +lower ::= ‘a’ | … | ‘z’ “… and Unicode category Ll” +letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl” +digit ::= ‘0’ | … | ‘9’ +opchar ::= “printableChar not matched by (whiteSpace | upper | lower | + letter | digit | paren | delim | opchar | Unicode_Sm | + Unicode_So)” op ::= opchar {opchar} varid ::= lower idrest @@ -42,8 +44,8 @@ integerLiteral ::= (decimalNumeral | hexNumera) [‘L’ | ‘l’] decimalNumeral ::= ‘0’ | nonZeroDigit {digit} hexNumeral ::= ‘0’ ‘x’ hexDigit {hexDigit} digit ::= ‘0’ | nonZeroDigit -nonZeroDigit ::= ‘1’ | $\cdots$ | ‘9’ -octalDigit ::= ‘0’ | $\cdots$ | ‘7’ +nonZeroDigit ::= ‘1’ | … | ‘9’ +octalDigit ::= ‘0’ | … | ‘7’ floatingPointLiteral ::= digit {digit} ‘.’ {digit} [exponentPart] [floatType] @@ -75,10 +77,10 @@ whiteSpace ::= {‘ ’ | ‘\t’} symbolLiteral ::= ‘'’ plainid -comment ::= ‘/*’ $\mbox{\rm\em ``any sequence of characters''}$ ‘*/’ - | ‘//’ $\mbox{\rm\em ``any sequence of characters up to end of line''}$ +comment ::= ‘/*’ “any sequence of characters; nested comments are allowed” ‘*/’ + | ‘//’ “any sequence of characters up to end of line” -nl ::= $\mbox{\rm\em ``new line character''}$ +nl ::= “new line character” semi ::= ‘;’ | nl {nl} ``` -- cgit v1.2.3 From bac774d6d67f0916b0a394bd6414bf27026890de Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:35:56 +0100 Subject: Fix typos, remove unused defs, adopt hexNumeral to 2.12 grammar --- docs/docs/internals/syntax.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 8ff9dc8ef..7e249d6a0 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -40,12 +40,11 @@ id ::= plainid | INT // interpolation id, only for quasi-quotes idrest ::= {letter | digit} [‘_’ op] -integerLiteral ::= (decimalNumeral | hexNumera) [‘L’ | ‘l’] +integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’] decimalNumeral ::= ‘0’ | nonZeroDigit {digit} -hexNumeral ::= ‘0’ ‘x’ hexDigit {hexDigit} +hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit {hexDigit} digit ::= ‘0’ | nonZeroDigit nonZeroDigit ::= ‘1’ | … | ‘9’ -octalDigit ::= ‘0’ | … | ‘7’ floatingPointLiteral ::= digit {digit} ‘.’ {digit} [exponentPart] [floatType] -- cgit v1.2.3 From cdc44429a2791b5a3c70cca38aa3aaa6d4e0d889 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:41:03 +0100 Subject: Fill in definitions from 2.12 --- docs/docs/internals/syntax.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 7e249d6a0..34acae2f4 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -21,13 +21,18 @@ The lexical syntax of Scala is given by the following grammar in EBNF form. ```ebnf +whiteSpace ::= ‘\u0020’ | ‘\u0009’ | ‘\u000D’ | ‘\u000A’ upper ::= ‘A’ | … | ‘Z’ | ‘\$’ | ‘_’ “… and Unicode category Lu” lower ::= ‘a’ | … | ‘z’ “… and Unicode category Ll” letter ::= upper | lower “… and Unicode categories Lo, Lt, Nl” digit ::= ‘0’ | … | ‘9’ +paren ::= ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’ +delim ::= ‘`’ | ‘'’ | ‘"’ | ‘.’ | ‘;’ | ‘,’ opchar ::= “printableChar not matched by (whiteSpace | upper | lower | letter | digit | paren | delim | opchar | Unicode_Sm | Unicode_So)” +printableChar ::= “all characters in [\u0020, \u007F] inclusive” +charEscapeSeq ::= ‘\’ (‘b’ | ‘t’ | ‘n’ | ‘f’ | ‘r’ | ‘"’ | ‘'’ | ‘\’) op ::= opchar {opchar} varid ::= lower idrest @@ -36,7 +41,7 @@ alphaid ::= upper idrest plainid ::= alphaid | op id ::= plainid - | ‘\`’ stringLit ‘\`’ + | ‘`’ { charNoBackQuoteOrNewline | UnicodeEscape | charEscapeSeq } ‘`’ | INT // interpolation id, only for quasi-quotes idrest ::= {letter | digit} [‘_’ op] @@ -51,20 +56,19 @@ floatingPointLiteral | ‘.’ digit {digit} [exponentPart] [floatType] | digit {digit} exponentPart [floatType] | digit {digit} [exponentPart] floatType - exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit} floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’ + booleanLiteral ::= ‘true’ | ‘false’ -characterLiteral ::= ‘\'’ printableChar ‘\'’ - | ‘\'’ charEscapeSeq ‘\'’ +characterLiteral ::= ‘'’ (printableChar | charEscapeSeq) ‘'’ stringLiteral ::= ‘"’ {stringElement} ‘"’ - | ‘"""’ {[‘"’] [‘"’] char \ ‘"’} {‘"’} ‘"""’ + | ‘"""’ multiLineChars ‘"""’ stringElement ::= printableChar \ (‘"’ | ‘\’) + | UnicodeEscape | charEscapeSeq -charEscapeSeq ::= ‘\b’ | ‘\n’ | ‘\t’ | ‘\f’ | ‘\r’ | ‘"’ | ‘'’ | ‘\\’ - +multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’} processedStringLiteral ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape} ‘"’ | alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’ @@ -72,7 +76,6 @@ escape ::= ‘$$’ \comment{$} | ‘$’ letter { letter | digit } | ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’ stringFormat ::= {printableChar \ (‘"’ | ‘}’ | ‘ ’ | ‘\t’ | ‘\n’)} -whiteSpace ::= {‘ ’ | ‘\t’} symbolLiteral ::= ‘'’ plainid -- cgit v1.2.3 From 7ff9c9326ef6c66758b3e16e2d655138663ed613 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:42:52 +0100 Subject: Remove tex comment --- docs/docs/internals/syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 34acae2f4..318d1e91f 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -72,7 +72,7 @@ multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’} processedStringLiteral ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape} ‘"’ | alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’ -escape ::= ‘$$’ \comment{$} +escape ::= ‘$$’ | ‘$’ letter { letter | digit } | ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’ stringFormat ::= {printableChar \ (‘"’ | ‘}’ | ‘ ’ | ‘\t’ | ‘\n’)} -- cgit v1.2.3 From d40f9760145401981f50458982915a95bfec8563 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:52:30 +0100 Subject: Cosmetique changes and fix typos --- docs/docs/internals/syntax.md | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 318d1e91f..c42edc389 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -120,7 +120,7 @@ Type ::= [‘implicit’] FunArgTypes ‘=>’ Type | HkTypeParamClause ‘=>’ Type | InfixType FunArgTypes ::= InfixType - | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ + | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ InfixType ::= RefinedType {id [nl] RefinedType} RefinedType ::= WithType {[nl] Refinement} WithType ::= AnnotType {‘with’ AnnotType} @@ -134,7 +134,7 @@ SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) | Refinement | SimpleLiteral ArgTypes ::= Type {‘,’ Type} - | NamedTypeArg {‘,’ NamedTypeArg } + | NamedTypeArg {‘,’ NamedTypeArg} FunArgType ::= Type | ‘=>’ Type ParamType ::= [‘=>’] ParamValueType @@ -143,7 +143,7 @@ TypeArgs ::= ‘[’ ArgTypes ‘]’ NamedTypeArg ::= id ‘=’ Type NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ -TypeBounds ::= [‘>:’ Type] [`<: Type] | INT +TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} Expr ::= [‘implicit’] FunParams ‘=>’ Expr @@ -181,7 +181,7 @@ SimpleExpr ::= ‘new’ Template SimpleExpr1 ::= Literal | Path | ‘_’ - | ‘(’ ExprsInParens2 ‘)’ + | ‘(’ ExprsInParens ‘)’ | SimpleExpr ‘.’ id | SimpleExpr (TypeArgs | NamedTypeArgs) | SimpleExpr1 ArgumentExprs @@ -231,7 +231,7 @@ PatVar ::= varid | ‘_’ Patterns ::= Pattern {‘,’ Pattern} ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ - | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ') + | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ‘)’ ``` ### Type and Value Parameters @@ -243,7 +243,7 @@ ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’ DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds -TypTypeParamCaluse::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’ +TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’ TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’ @@ -252,9 +252,8 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] | ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ ‘implicit’ ClsParams ‘)’] ClsParamClause ::= [nl] ‘(’ [ClsParams] ‘)’ -ClsParams ::= ClsParam {‘’ ClsParam} -ClsParam ::= {Annotation} - [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param +ClsParams ::= ClsParam {‘,’ ClsParam} +ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param Param ::= id ‘:’ ParamType [‘=’ Expr] | INT @@ -266,7 +265,7 @@ DefParam ::= {Annotation} [‘inline’] Param ### Bindings and Imports ```ebnf -Bindings ::= ‘(’ Binding {‘,’ Binding}] ‘)’ +Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’ Binding ::= (id | ‘_’) [‘:’ Type] Modifier ::= LocalModifier @@ -282,14 +281,13 @@ AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’ Annotation ::= ‘@’ SimpleType {ParArgumentExprs} -TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} `} +TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ TemplateStat ::= Import | {Annotation [nl]} {Modifier} Def | {Annotation [nl]} {Modifier} Dcl | Expr1 - | SelfType ::= id [‘:’ InfixType] ‘=>’ - | ‘this’ ‘:’ InfixType `=> + | ‘this’ ‘:’ InfixType ‘=>’ Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) @@ -305,7 +303,6 @@ Dcl ::= ‘val’ ValDcl | ‘type’ {nl} TypeDcl | INT - ValDcl ::= ids ‘:’ Type VarDcl ::= ids ‘:’ Type DefDcl ::= DefSig [‘:’ Type] -- cgit v1.2.3 From 0445ad68936403ca20efc66117524c277081e644 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:55:29 +0100 Subject: Move ExprInParens and BlockResult --- docs/docs/internals/syntax.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index c42edc389..7fc48943e 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -145,17 +145,19 @@ NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} +``` +### Expressions +```ebnf Expr ::= [‘implicit’] FunParams ‘=>’ Expr + | Expr1 +BlockResult ::= [‘implicit’] FunParams ‘=>’ Block + | Expr1 FunParams ::= Bindings | id | ‘_’ -ExprInParens ::= PostfixExpr ‘:’ Type - | Expr -BlockResult ::= [‘implicit’] FunParams ‘=>’ Block - | Expr1 -Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] else Expr] - | ‘if’ Expr ‘then’ Expr [[semi] else Expr] +Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] + | ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] | ‘while’ ‘(’ Expr ‘)’ {nl} Expr | ‘while’ Expr ‘do’ Expr | ‘do’ Expr [semi] ‘while’ Expr @@ -187,8 +189,10 @@ SimpleExpr1 ::= Literal | SimpleExpr1 ArgumentExprs | XmlExpr ExprsInParens ::= ExprInParens {‘,’ ExprInParens} -ParArgumentExprs ::= ‘(’ [ExprsInParens] ‘)’ - | ‘(’ [ExprsInParens ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ +ExprInParens ::= PostfixExpr ‘:’ Type + | Expr +ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ + | ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ ArgumentExprs ::= ParArgumentExprs | [nl] BlockExpr BlockExpr ::= ‘{’ CaseClauses ‘}’ -- cgit v1.2.3 From d12479afb2bf683cdcf0e250e74f8635f4bb87ab Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 21:59:35 +0100 Subject: More cosmetiques --- docs/docs/internals/syntax.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index 7fc48943e..aef862ec0 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -86,6 +86,7 @@ nl ::= “new line character” semi ::= ‘;’ | nl {nl} ``` + ## Context-free Syntax The context-free syntax of Scala is given by the following EBNF @@ -202,12 +203,9 @@ BlockStat ::= Import | {Annotation} [‘implicit’ | ‘lazy’] Def | {Annotation} {LocalModifier} TmplDef | Expr1 - | -ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) - {nl} [‘yield’] Expr +ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) - Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard @@ -217,7 +215,6 @@ Guard ::= ‘if’ PostfixExpr CaseClauses ::= CaseClause { CaseClause } CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT) - Pattern ::= Pattern1 { ‘|’ Pattern1 } Pattern1 ::= PatVar ‘:’ RefinedType | Pattern2 @@ -330,8 +327,7 @@ DefDef ::= DefSig [‘:’ Type] ‘=’ Expr TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef | [‘case’] ‘object’ ObjectDef -ClassDef ::= id [ClsTypeParamClause] - [ConstrMods] ClsParamClauses TemplateOpt +ClassDef ::= id [ClsTypeParamClause] [ConstrMods] ClsParamClauses TemplateOpt ConstrMods ::= AccessModifier | Annotation {Annotation} (AccessModifier | ‘this’) ObjectDef ::= id TemplateOpt @@ -339,18 +335,16 @@ TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody] Template ::= ConstrApps [TemplateBody] | TemplateBody ConstrApps ::= ConstrApp {‘with’ ConstrApp} ConstrApp ::= AnnotType {ArgumentExprs} - ConstrExpr ::= SelfInvocation | ConstrBlock -ConstrBlock ::= ‘{’ SelfInvocation {semi BlockStat} ‘}’ SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} +ConstrBlock ::= ‘{’ SelfInvocation {semi BlockStat} ‘}’ TopStatSeq ::= TopStat {semi TopStat} TopStat ::= {Annotation [nl]} {Modifier} TmplDef | Import | Packaging | PackageObject - | Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ PackageObject ::= ‘package’ ‘object’ ObjectDef -- cgit v1.2.3 From b004e6cdd6a1d1538a63e4d2d40fd935987735e6 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Wed, 21 Dec 2016 22:19:45 +0100 Subject: Remove syntax description in tex to avoid duplication --- docs/syntax-summary.txt | 327 ------------------------------------------------ 1 file changed, 327 deletions(-) delete mode 100644 docs/syntax-summary.txt (limited to 'docs') diff --git a/docs/syntax-summary.txt b/docs/syntax-summary.txt deleted file mode 100644 index d382507d3..000000000 --- a/docs/syntax-summary.txt +++ /dev/null @@ -1,327 +0,0 @@ -% $Id: SyntaxSummary.tex 21104 2010-03-08 13:49:27Z odersky $ - -\chapter{Scala Syntax Summary}\label{sec:syntax} -\todo{introduce SeqPattern syntax} - -The lexical syntax of Scala is given by the following grammar in EBNF -form. - -{\small -\begin{lstlisting} - upper ::= `A' | $\cdots$ | `Z' | `$\Dollar$' | `_' $\mbox{\rm\em and Unicode category Lu}$ - lower ::= `a' | $\cdots$ | `z' $\mbox{\rm\em and Unicode category Ll}$ - letter ::= upper | lower $\mbox{\rm\em and Unicode categories Lo, Lt, Nl}$ - digit ::= `0' | $\cdots$ | `9' - opchar ::= $\mbox{\rm\em ``all other characters in \U{0020-007F} and Unicode}$ - $\mbox{\rm\em categories Sm, So except parentheses ([{}]) and periods''}$ - - op ::= opchar {opchar} - varid ::= lower idrest - alphaid ::= upper idrest - | varid - plainid ::= alphaid - | op - id ::= plainid - | `\`' stringLit `\`' - | INT // interpolation id, only for quasi-quotes - idrest ::= {letter | digit} [`_' op] - - integerLiteral ::= (decimalNumeral | hexNumera) [`L' | `l'] - decimalNumeral ::= `0' | nonZeroDigit {digit} - hexNumeral ::= `0' `x' hexDigit {hexDigit} - digit ::= `0' | nonZeroDigit - nonZeroDigit ::= `1' | $\cdots$ | `9' - octalDigit ::= `0' | $\cdots$ | `7' - - floatingPointLiteral - ::= digit {digit} `.' {digit} [exponentPart] [floatType] - | `.' digit {digit} [exponentPart] [floatType] - | digit {digit} exponentPart [floatType] - | digit {digit} [exponentPart] floatType - exponentPart ::= (`E' | `e') [`+' | `-'] digit {digit} - floatType ::= `F' | `f' | `D' | `d' - - booleanLiteral ::= `true' | `false' - - characterLiteral ::= `\'' printableChar `\'' - | `\'' charEscapeSeq `\'' - - stringLiteral ::= `"' {stringElement} `"' - | `"""' {[`"'] [`"'] char \ `"'} {`"'} `"""' - stringElement ::= printableChar \ (`"' | `\') - | charEscapeSeq - charEscapeSeq ::= `\b' | `\n' | `\t' | `\f' | `\r' | `"' | `'' | `\\' - - processedStringLiteral - ::= alphaid`"' {printableChar \ (`"' | `$') | escape} `"' - | alphaid `"""' {[`"'] [`"'] char \ (`"' | `$') | escape} {`"'} `"""' - escape ::= `$$' \comment{$} - | `$' letter { letter | digit } - | `{' Block [`;' whiteSpace stringFormat whiteSpace] `}' - stringFormat ::= {printableChar \ (`"' | `}' | ` ' | `\t' | `\n')} - whiteSpace ::= {` ' | `\t'} - - symbolLiteral ::= `'' plainid - - comment ::= `/*' $\mbox{\rm\em ``any sequence of characters''}$ `*/' - | `//' $\mbox{\rm\em ``any sequence of characters up to end of line''}$ - - nl ::= $\mbox{\rm\em ``new line character''}$ - semi ::= `;' | nl {nl} -\end{lstlisting}} - -The context-free syntax of Scala is given by the following EBNF -grammar. - -{\small -\begin{lstlisting} - SimpleLiteral ::= [`-'] integerLiteral - | [`-'] floatingPointLiteral - | booleanLiteral - | characterLiteral - | stringLiteral - Literal ::= SimpleLiteral - | processedStringLiteral - | symbolLiteral - | `null' - - QualId ::= id {`.' id} - ids ::= id {`,' id} - - Path ::= StableId - | [id `.'] `this' - StableId ::= id - | Path `.' id - | [id '.'] `super' [ClassQualifier] `.' id - ClassQualifier ::= `[' id `]' - - Type ::= [`implicit'] FunArgTypes `=>' Type Function(ts, t) - | HkTypeParamClause `=>' Type TypeLambda(ps, t) - | InfixType - FunArgTypes ::= InfixType - | `(' [ FunArgType {`,' FunArgType } ] `)' - InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) - RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) - WithType ::= AnnotType {`with' AnnotType} (deprecated) - AnnotType ::= SimpleType {Annotation} Annotated(t, annot) - SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) - | SimpleType `#' id Select(t, name) - | StableId - | Path `.' `type' SingletonTypeTree(p) - | `(' ArgTypes ')' Tuple(ts) - | `_' TypeBounds - | Refinement RefinedTypeTree(EmptyTree, refinement) - | SimpleLiteral SingletonTypeTree(l) - ArgTypes ::= Type {`,' Type} - | NamedTypeArg {`,' NamedTypeArg } - FunArgType ::= Type - | `=>' Type PrefixOp(=>, t) - ParamType ::= [`=>'] ParamValueType - ParamValueType ::= Type [`*'] PostfixOp(t, "*") - TypeArgs ::= `[' ArgTypes `]' ts - NamedTypeArg ::= id `=' Type NamedArg(id, t) - NamedTypeArgs ::= `[' NamedTypeArg {`,' NamedTypeArg} `]' nts - Refinement ::= `{' [Dcl] {semi [Dcl]} `}' ds - TypeBounds ::= [`>:' Type] [`<: Type] | INT TypeBoundsTree(lo, hi) - TypeParamBounds ::= TypeBounds {`<%' Type} {`:' Type} ContextBounds(typeBounds, tps) - - Expr ::= [`implicit'] FunParams `=>' Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) - FunParams ::= Bindings - | id - | `_' - ExprInParens ::= PostfixExpr `:' Type - | Expr - BlockResult ::= [`implicit'] FunParams `=>' Block - | Expr1 - Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?) - | `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?) - | `while' `(' Expr `)' {nl} Expr WhileDo(Parens(cond), body) - | `while' Expr `do' Expr WhileDo(cond, body) - | `do' Expr [semi] `while' Expr DoWhile(expr, cond) - | `try' Expr Catches [`finally' Expr] Try(expr, catches, expr?) - | `try' Expr [`finally' Expr] Try(expr, Nil, expr?) - | `throw' Expr Throw(expr) - | `return' [Expr] Return(expr?) - | ForExpr - | [SimpleExpr `.'] id `=' Expr Assign(expr, expr) - | SimpleExpr1 ArgumentExprs `=' Expr Assign(expr, expr) - | PostfixExpr [Ascription] - | PostfixExpr `match' `{' CaseClauses `}' Match(expr, cases) -- point on match - Ascription ::= `:' InfixType Typed(expr, tp) - | `:' Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) - Catches ::= `catch' Expr - PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) - InfixExpr ::= PrefixExpr - | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) - PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr PrefixOp(expr, op) - SimpleExpr ::= `new' Template New(templ) - | BlockExpr - | SimpleExpr1 [`_'] PostfixOp(expr, _) - SimpleExpr1 ::= Literal - | Path - | `_' - | `(' ExprsInParens2 `)' Parens(exprs) - | SimpleExpr `.' id Select(expr, id) - | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) - | SimpleExpr1 ArgumentExprs Apply(expr, args) - | XmlExpr - ExprsInParens ::= ExprInParens {`,' ExprInParens} - ParArgumentExprs ::= `(' [ExprsInParens] `)' exprs - | `(' [ExprsInParens `,'] PostfixExpr `:' `_' `*' ')' exprs :+ Typed(expr, Ident(wildcardStar)) - ArgumentExprs ::= ParArgumentExprs - | [nl] BlockExpr - BlockExpr ::= `{' CaseClauses `}' Match(EmptyTree, cases) - | `{' Block `}' block // starts at { - Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) - BlockStat ::= Import - | {Annotation} [`implicit' | `lazy'] Def - | {Annotation} {LocalModifier} TmplDef - | Expr1 - | - - ForExpr ::= `for' (`(' Enumerators `)' | `{' Enumerators `}') ForYield(enums, expr) - {nl} [`yield'] Expr ForDo(enums, expr) - | `for' Enumerators (`do' Expr | `yield' Expr) - - Enumerators ::= Generator {semi Enumerator | Guard} - Enumerator ::= Generator - | Guard - | Pattern1 `=' Expr GenAlias(pat, expr) - Generator ::= Pattern1 `<-' Expr GenFrom(pat, expr) - Guard ::= `if' PostfixExpr - - CaseClauses ::= CaseClause { CaseClause } - CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at => - - Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats) - Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe)) - | Pattern2 - Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat) - InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) - SimplePattern ::= PatVar Ident(wildcard) - | Literal Bind(name, Ident(wildcard)) - | `(' [Patterns] `)' Parens(pats) Tuple(pats) - | XmlPattern - | SimplePattern1 [TypeArgs] [ArgumentPatterns] - SimplePattern1 ::= Path - | `{' Block `}' - | SimplePattern1 `.' id - PatVar ::= varid - | `_' - Patterns ::= Pattern {`,' Pattern} - ArgumentPatterns ::= `(' [Patterns] `)' Apply(fn, pats) - | `(' [Patterns `,'] Pattern2 `:' `_' `*' ') - - ClsTypeParamClause::= `[' ClsTypeParam {`,' ClsTypeParam} `]' - ClsTypeParam ::= {Annotation} [{Modifier} type] [`+' | `-'] TypeDef(Modifiers, name, tparams, bounds) - id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) - - DefTypeParamClause::= `[' DefTypeParam {`,' DefTypeParam} `]' - DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds - - TypTypeParamCaluse::= `[' TypTypeParam {`,' TypTypeParam} `]' - TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds - - HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]' - HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_') - TypeBounds - - ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)'] - ClsParamClause ::= [nl] `(' [ClsParams] ')' - ClsParams ::= ClsParam {`' ClsParam} - ClsParam ::= {Annotation} - [{Modifier} (`val' | `var') | `inline'] Param ValDef(mods, id, tpe, expr) -- point of mods on val/var - Param ::= id `:' ParamType [`=' Expr] - | INT - - DefParamClauses ::= {DefParamClause} [[nl] `(' `implicit' DefParams `)'] - DefParamClause ::= [nl] `(' [DefParams] ')' - DefParams ::= DefParam {`,' DefParam} - DefParam ::= {Annotation} [`inline'] Param ValDef(mods, id, tpe, expr) -- point of mods at id. - - Bindings ::= `(' Binding {`,' Binding}] `)' - Binding ::= (id | `_') [`:' Type] ValDef(_, id, tpe, EmptyTree) - - Modifier ::= LocalModifier - | AccessModifier - | `override' - LocalModifier ::= `abstract' - | `final' - | `sealed' - | `implicit' - | `lazy' - AccessModifier ::= (`private' | `protected') [AccessQualifier] - AccessQualifier ::= `[' (id | `this') `]' - - Annotation ::= `@' SimpleType {ParArgumentExprs} Apply(tpe, args) - - TemplateBody ::= [nl] `{' [SelfType] TemplateStat {semi TemplateStat} `} (self, stats) - TemplateStat ::= Import - | {Annotation [nl]} {Modifier} Def - | {Annotation [nl]} {Modifier} Dcl - | Expr1 - | - SelfType ::= id [`:' InfixType] `=>' ValDef(_, name, tpt, _) - | `this' `:' InfixType `=> - - Import ::= `import' ImportExpr {`,' ImportExpr} - ImportExpr ::= StableId `.' (id | `_' | ImportSelectors) Import(expr, sels) - ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' - ImportSelector ::= id [`=>' id | `=>' `_'] Ident(name), Pair(id, id) - - Dcl ::= `val' ValDcl - | `var' VarDcl - | `def' DefDcl - | `type' {nl} TypeDcl - | INT - - ValDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) - VarDcl ::= ids `:' Type PatDef(_, ids, tpe, EmptyTree) - DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) - DefSig ::= id [DefTypeParamClause] DefParamClauses - TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt) - | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) - - Def ::= `val' PatDef - | `var' VarDef - | `def' DefDef - | `type' {nl} TypeDcl - | TmplDef - | INT - PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr PatDef(_, pats, tpe?, expr) - VarDef ::= PatDef - | ids `:' Type `=' `_' - DefDef ::= DefSig [`:' Type] `=' Expr DefDef(_, name, tparams, vparamss, tpe, expr) - | DefSig [nl] `{' Block `}' DefDef(_, name, tparams, vparamss, tpe, Block) - | `this' DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) - (`=' ConstrExpr | [nl] ConstrBlock) - - TmplDef ::= ([`case'] `class' | `trait') ClassDef - | [`case'] `object' ObjectDef - ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) // - [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat - ConstrMods ::= AccessModifier - | Annotation {Annotation} (AccessModifier | `this') - ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor - TemplateOpt ::= [`extends' Template | [nl] TemplateBody] - Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) - ConstrApps ::= ConstrApp {`with' ConstrApp} - ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) - - ConstrExpr ::= SelfInvocation - | ConstrBlock - ConstrBlock ::= `{' SelfInvocation {semi BlockStat} `}' - SelfInvocation ::= `this' ArgumentExprs {ArgumentExprs} - - TopStatSeq ::= TopStat {semi TopStat} - TopStat ::= {Annotation [nl]} {Modifier} TmplDef - | Import - | Packaging - | PackageObject - | - Packaging ::= `package' QualId [nl] `{' TopStatSeq `}' Package(qid, stats) - PackageObject ::= `package' `object' ObjectDef object with package in mods. - - CompilationUnit ::= {`package' QualId semi} TopStatSeq Package(qid, stats) -\end{lstlisting} -} -- cgit v1.2.3 From 403ffc27487db92c9134b172d7422013b65c1098 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Thu, 22 Dec 2016 11:59:16 +0100 Subject: Add tree annotations back in --- docs/docs/internals/syntax.md | 180 +++++++++++++++++++++--------------------- 1 file changed, 92 insertions(+), 88 deletions(-) (limited to 'docs') diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index aef862ec0..7c8cb1ea2 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -117,112 +117,114 @@ ClassQualifier ::= ‘[’ id ‘]’ ### Types ```ebnf -Type ::= [‘implicit’] FunArgTypes ‘=>’ Type - | HkTypeParamClause ‘=>’ Type +Type ::= [‘implicit’] FunArgTypes ‘=>’ Type Function(ts, t) + | HkTypeParamClause ‘=>’ Type TypeLambda(ps, t) | InfixType FunArgTypes ::= InfixType | ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’ -InfixType ::= RefinedType {id [nl] RefinedType} -RefinedType ::= WithType {[nl] Refinement} -WithType ::= AnnotType {‘with’ AnnotType} -AnnotType ::= SimpleType {Annotation} -SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) - | SimpleType ‘#’ id +InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2) +RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds) +WithType ::= AnnotType {‘with’ AnnotType} (deprecated) +AnnotType ::= SimpleType {Annotation} Annotated(t, annot) +SimpleType ::= SimpleType (TypeArgs | NamedTypeArgs) AppliedTypeTree(t, args) + | SimpleType ‘#’ id Select(t, name) | StableId - | Path ‘.’ ‘type’ - | ‘(’ ArgTypes ‘)’ + | Path ‘.’ ‘type’ SingletonTypeTree(p) + | ‘(’ ArgTypes ‘)’ Tuple(ts) | ‘_’ TypeBounds - | Refinement - | SimpleLiteral + | Refinement RefinedTypeTree(EmptyTree, refinement) + | SimpleLiteral SingletonTypeTree(l) ArgTypes ::= Type {‘,’ Type} | NamedTypeArg {‘,’ NamedTypeArg} FunArgType ::= Type - | ‘=>’ Type + | ‘=>’ Type PrefixOp(=>, t) ParamType ::= [‘=>’] ParamValueType -ParamValueType ::= Type [‘*’] -TypeArgs ::= ‘[’ ArgTypes ‘]’ -NamedTypeArg ::= id ‘=’ Type -NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ -Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ -TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT -TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} +ParamValueType ::= Type [‘*’] PostfixOp(t, "*") +TypeArgs ::= ‘[’ ArgTypes ‘]’ ts +NamedTypeArg ::= id ‘=’ Type NamedArg(id, t) +NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts +Refinement ::= ‘{’ [Dcl] {semi [Dcl]} ‘}’ ds +TypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi) +TypeParamBounds ::= TypeBounds {‘<%’ Type} {‘:’ Type} ContextBounds(typeBounds, tps) ``` ### Expressions ```ebnf -Expr ::= [‘implicit’] FunParams ‘=>’ Expr +Expr ::= [‘implicit’] FunParams ‘=>’ Expr Function(args, expr), Function(ValDef([implicit], id, TypeTree(), EmptyTree), expr) | Expr1 BlockResult ::= [‘implicit’] FunParams ‘=>’ Block | Expr1 FunParams ::= Bindings | id | ‘_’ -Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] - | ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] - | ‘while’ ‘(’ Expr ‘)’ {nl} Expr - | ‘while’ Expr ‘do’ Expr - | ‘do’ Expr [semi] ‘while’ Expr - | ‘try’ Expr Catches [‘finally’ Expr] - | ‘try’ Expr [‘finally’ Expr] - | ‘throw’ Expr - | ‘return’ [Expr] +Expr1 ::= ‘if’ ‘(’ Expr ‘)’ {nl} Expr [[semi] ‘else’ Expr] If(Parens(cond), thenp, elsep?) + | ‘if’ Expr ‘then’ Expr [[semi] ‘else’ Expr] If(cond, thenp, elsep?) + | ‘while’ ‘(’ Expr ‘)’ {nl} Expr WhileDo(Parens(cond), body) + | ‘while’ Expr ‘do’ Expr WhileDo(cond, body) + | ‘do’ Expr [semi] ‘while’ Expr DoWhile(expr, cond) + | ‘try’ Expr Catches [‘finally’ Expr] Try(expr, catches, expr?) + | ‘try’ Expr [‘finally’ Expr] Try(expr, Nil, expr?) + | ‘throw’ Expr Throw(expr) + | ‘return’ [Expr] Return(expr?) | ForExpr - | [SimpleExpr ‘.’] id ‘=’ Expr - | SimpleExpr1 ArgumentExprs ‘=’ Expr + | [SimpleExpr ‘.’] id ‘=’ Expr Assign(expr, expr) + | SimpleExpr1 ArgumentExprs ‘=’ Expr Assign(expr, expr) | PostfixExpr [Ascription] - | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ -Ascription ::= ‘:’ InfixType - | ‘:’ Annotation {Annotation} + | PostfixExpr ‘match’ ‘{’ CaseClauses ‘}’ Match(expr, cases) -- point on match +Ascription ::= ‘:’ InfixType Typed(expr, tp) + | ‘:’ Annotation {Annotation} Typed(expr, Annotated(EmptyTree, annot)*) Catches ::= ‘catch’ Expr -PostfixExpr ::= InfixExpr [id] +PostfixExpr ::= InfixExpr [id] PostfixOp(expr, op) InfixExpr ::= PrefixExpr - | InfixExpr id [nl] InfixExpr -PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr -SimpleExpr ::= ‘new’ Template + | InfixExpr id [nl] InfixExpr InfixOp(expr, op, expr) +PrefixExpr ::= [‘-’ | ‘+’ | ‘~’ | ‘!’] SimpleExpr PrefixOp(expr, op) +SimpleExpr ::= ‘new’ Template New(templ) | BlockExpr - | SimpleExpr1 [‘_’] + | SimpleExpr1 [‘_’] PostfixOp(expr, _) SimpleExpr1 ::= Literal | Path | ‘_’ - | ‘(’ ExprsInParens ‘)’ - | SimpleExpr ‘.’ id - | SimpleExpr (TypeArgs | NamedTypeArgs) - | SimpleExpr1 ArgumentExprs + | ‘(’ ExprsInParens ‘)’ Parens(exprs) + | SimpleExpr ‘.’ id Select(expr, id) + | SimpleExpr (TypeArgs | NamedTypeArgs) TypeApply(expr, args) + | SimpleExpr1 ArgumentExprs Apply(expr, args) | XmlExpr ExprsInParens ::= ExprInParens {‘,’ ExprInParens} ExprInParens ::= PostfixExpr ‘:’ Type | Expr -ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ - | ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ +ParArgumentExprs ::= ‘(’ ExprsInParens ‘)’ exprs + | ‘(’ [ExprsInParens] PostfixExpr ‘:’ ‘_’ ‘*’ ‘)’ exprs :+ Typed(expr, Ident(wildcardStar)) ArgumentExprs ::= ParArgumentExprs | [nl] BlockExpr -BlockExpr ::= ‘{’ CaseClauses ‘}’ - | ‘{’ Block ‘}’ -Block ::= {BlockStat semi} [BlockResult] +BlockExpr ::= ‘{’ CaseClauses ‘}’ Match(EmptyTree, cases) + | ‘{’ Block ‘}’ block // starts at { +Block ::= {BlockStat semi} [BlockResult] Block(stats, expr?) BlockStat ::= Import | {Annotation} [‘implicit’ | ‘lazy’] Def | {Annotation} {LocalModifier} TmplDef | Expr1 -ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) {nl} [‘yield’] Expr - | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) +ForExpr ::= ‘for’ (‘(’ Enumerators ‘)’ | ‘{’ Enumerators ‘}’) ForYield(enums, expr) + {nl} [‘yield’] Expr + | ‘for’ Enumerators (‘do’ Expr | ‘yield’ Expr) ForDo(enums, expr) Enumerators ::= Generator {semi Enumerator | Guard} Enumerator ::= Generator | Guard - | Pattern1 ‘=’ Expr -Generator ::= Pattern1 ‘<-’ Expr + | Pattern1 ‘=’ Expr GenAlias(pat, expr) +Generator ::= Pattern1 ‘<-’ Expr GenFrom(pat, expr) Guard ::= ‘if’ PostfixExpr -CaseClauses ::= CaseClause { CaseClause } +CaseClauses ::= CaseClause { CaseClause } CaseDef(pat, guard?, block) // block starts at => CaseClause ::= ‘case’ (Pattern [Guard] ‘=>’ Block | INT) -Pattern ::= Pattern1 { ‘|’ Pattern1 } -Pattern1 ::= PatVar ‘:’ RefinedType + +Pattern ::= Pattern1 { ‘|’ Pattern1 } Alternative(pats) +Pattern1 ::= PatVar ‘:’ RefinedType Bind(name, Typed(Ident(wildcard), tpe)) | Pattern2 -Pattern2 ::= [varid ‘@’] InfixPattern -InfixPattern ::= SimplePattern { id [nl] SimplePattern } -SimplePattern ::= PatVar - | Literal - | ‘(’ [Patterns] ‘)’ +Pattern2 ::= [varid ‘@’] InfixPattern Bind(name, pat) +InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat) +SimplePattern ::= PatVar Ident(wildcard) + | Literal Bind(name, Ident(wildcard)) + | ‘(’ [Patterns] ‘)’ Parens(pats) Tuple(pats) | XmlPattern | SimplePattern1 [TypeArgs] [ArgumentPatterns] SimplePattern1 ::= Path @@ -231,15 +233,15 @@ SimplePattern1 ::= Path PatVar ::= varid | ‘_’ Patterns ::= Pattern {‘,’ Pattern} -ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ +ArgumentPatterns ::= ‘(’ [Patterns] ‘)’ Apply(fn, pats) | ‘(’ [Patterns ‘,’] Pattern2 ‘:’ ‘_’ ‘*’ ‘)’ ``` ### Type and Value Parameters ```ebnf ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’ -ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] - id [HkTypeParamClause] TypeParamBounds +ClsTypeParam ::= {Annotation} [{Modifier} type] [‘+’ | ‘-’] TypeDef(Modifiers, name, tparams, bounds) + id [HkTypeParamClause] TypeParamBounds Bound(below, above, context) DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’ DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds @@ -254,20 +256,21 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (Id[HkTypeParamClause] | ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ ‘implicit’ ClsParams ‘)’] ClsParamClause ::= [nl] ‘(’ [ClsParams] ‘)’ ClsParams ::= ClsParam {‘,’ ClsParam} -ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param +ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var + [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param Param ::= id ‘:’ ParamType [‘=’ Expr] | INT DefParamClauses ::= {DefParamClause} [[nl] ‘(’ ‘implicit’ DefParams ‘)’] DefParamClause ::= [nl] ‘(’ [DefParams] ‘)’ DefParams ::= DefParam {‘,’ DefParam} -DefParam ::= {Annotation} [‘inline’] Param +DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id. ``` ### Bindings and Imports ```ebnf Bindings ::= ‘(’ Binding {‘,’ Binding} ‘)’ -Binding ::= (id | ‘_’) [‘:’ Type] +Binding ::= (id | ‘_’) [‘:’ Type] ValDef(_, id, tpe, EmptyTree) Modifier ::= LocalModifier | AccessModifier @@ -280,20 +283,20 @@ LocalModifier ::= ‘abstract’ AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier] AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’ -Annotation ::= ‘@’ SimpleType {ParArgumentExprs} +Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args) -TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ +TemplateBody ::= [nl] ‘{’ [SelfType] TemplateStat {semi TemplateStat} ‘}’ (self, stats) TemplateStat ::= Import | {Annotation [nl]} {Modifier} Def | {Annotation [nl]} {Modifier} Dcl | Expr1 -SelfType ::= id [‘:’ InfixType] ‘=>’ +SelfType ::= id [‘:’ InfixType] ‘=>’ ValDef(_, name, tpt, _) | ‘this’ ‘:’ InfixType ‘=>’ Import ::= ‘import’ ImportExpr {‘,’ ImportExpr} -ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) +ImportExpr ::= StableId ‘.’ (id | ‘_’ | ImportSelectors) Import(expr, sels) ImportSelectors ::= ‘{’ {ImportSelector ‘,’} (ImportSelector | ‘_’) ‘}’ -ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] +ImportSelector ::= id [‘=>’ id | ‘=>’ ‘_’] Ident(name), Pair(id, id) ``` ### Declarations and Definitions @@ -304,12 +307,12 @@ Dcl ::= ‘val’ ValDcl | ‘type’ {nl} TypeDcl | INT -ValDcl ::= ids ‘:’ Type -VarDcl ::= ids ‘:’ Type -DefDcl ::= DefSig [‘:’ Type] +ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree) +VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree) +DefDcl ::= DefSig [‘:’ Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree) DefSig ::= id [DefTypeParamClause] DefParamClauses -TypeDcl ::= id [TypTypeParamClause] [‘=’ Type] - | id [HkTypeParamClause] TypeBounds +TypeDcl ::= id [TypTypeParamClause] [‘=’ Type] TypeDefTree(_, name, tparams, tpt) + | id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds) Def ::= ‘val’ PatDef | ‘var’ VarDef @@ -317,24 +320,25 @@ Def ::= ‘val’ PatDef | ‘type’ {nl} TypeDcl | TmplDef | INT -PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr +PatDef ::= Pattern2 {‘,’ Pattern2} [‘:’ Type] ‘=’ Expr PatDef(_, pats, tpe?, expr) VarDef ::= PatDef | ids ‘:’ Type ‘=’ ‘_’ -DefDef ::= DefSig [‘:’ Type] ‘=’ Expr - | DefSig [nl] ‘{’ Block ‘}’ - | ‘this’ DefParamClause DefParamClauses +DefDef ::= DefSig [‘:’ Type] ‘=’ Expr DefDef(_, name, tparams, vparamss, tpe, expr) + | DefSig [nl] ‘{’ Block ‘}’ DefDef(_, name, tparams, vparamss, tpe, Block) + | ‘this’ DefParamClause DefParamClauses DefDef(_, , Nil, vparamss, EmptyTree, expr | Block) (‘=’ ConstrExpr | [nl] ConstrBlock) TmplDef ::= ([‘case’] ‘class’ | ‘trait’) ClassDef | [‘case’] ‘object’ ObjectDef -ClassDef ::= id [ClsTypeParamClause] [ConstrMods] ClsParamClauses TemplateOpt +ClassDef ::= id [ClsTypeParamClause] ClassDef(mods, name, tparams, templ) + [ConstrMods] ClsParamClauses TemplateOpt with DefDef(_, , Nil, vparamss, EmptyTree, EmptyTree) as first stat ConstrMods ::= AccessModifier | Annotation {Annotation} (AccessModifier | ‘this’) -ObjectDef ::= id TemplateOpt +ObjectDef ::= id TemplateOpt ModuleDef(mods, name, template) // no constructor TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody] -Template ::= ConstrApps [TemplateBody] | TemplateBody +Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats) ConstrApps ::= ConstrApp {‘with’ ConstrApp} -ConstrApp ::= AnnotType {ArgumentExprs} +ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args) ConstrExpr ::= SelfInvocation | ConstrBlock SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs} @@ -345,8 +349,8 @@ TopStat ::= {Annotation [nl]} {Modifier} TmplDef | Import | Packaging | PackageObject -Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ -PackageObject ::= ‘package’ ‘object’ ObjectDef +Packaging ::= ‘package’ QualId [nl] ‘{’ TopStatSeq ‘}’ Package(qid, stats) +PackageObject ::= ‘package’ ‘object’ ObjectDef object with package in mods. -CompilationUnit ::= {‘package’ QualId semi} TopStatSeq +CompilationUnit ::= {‘package’ QualId semi} TopStatSeq Package(qid, stats) ``` -- cgit v1.2.3 From 32449b6f63bceeeedd59768f2f672ca714267733 Mon Sep 17 00:00:00 2001 From: Jonathan Brachthäuser Date: Thu, 22 Dec 2016 12:04:11 +0100 Subject: Add a link from internals index to syntax summary --- docs/docs/index.md | 1 + 1 file changed, 1 insertion(+) (limited to 'docs') diff --git a/docs/docs/index.md b/docs/docs/index.md index 8fceedbd0..0d9bc6b6f 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -20,6 +20,7 @@ Index - [Eclipse](contributing/eclipse.md) setting up dev environment - [Intellij-IDEA](contributing/intellij-idea.md) setting up dev environment * Internals document the compiler internals + - [Syntax Summary](internals/syntax.md) - [Project Structure](internals/overall-structure.md) of the project - [Backend](internals/backend.md) details on the bytecode backend -- cgit v1.2.3