Skip to content

Commit

Permalink
Minor Typescript grammar fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
inspirer committed Sep 13, 2017
1 parent 47de99e commit 10940ef
Show file tree
Hide file tree
Showing 6 changed files with 25,607 additions and 25,393 deletions.
25 changes: 25 additions & 0 deletions tm-parsers/js/ast/ast.go
Expand Up @@ -1328,6 +1328,15 @@ type ConstructSignature struct {
Node
}

func (n ConstructSignature) Modifier() []Modifier {
nodes := n.Children(selector.Modifier)
var result []Modifier = make([]Modifier, 0, len(nodes))
for _, node := range nodes {
result = append(result, ToJsNode(node).(Modifier))
}
return result
}

func (n ConstructSignature) TypeParameters() *TypeParameters {
if child := n.Child(selector.TypeParameters); child != nil {
return &TypeParameters{child}
Expand Down Expand Up @@ -2049,6 +2058,15 @@ type IndexSignature struct {
Node
}

func (n IndexSignature) Modifier() []Modifier {
nodes := n.Children(selector.Modifier)
var result []Modifier = make([]Modifier, 0, len(nodes))
for _, node := range nodes {
result = append(result, ToJsNode(node).(Modifier))
}
return result
}

func (n IndexSignature) TypeAnnotation() TypeAnnotation {
return TypeAnnotation{n.Child(selector.TypeAnnotation)}
}
Expand Down Expand Up @@ -3110,6 +3128,13 @@ type TsAmbientModule struct {
Node
}

func (n TsAmbientModule) BindingIdentifier() *BindingIdentifier {
if child := n.Child(selector.BindingIdentifier); child != nil {
return &BindingIdentifier{child}
}
return nil
}

func (n TsAmbientModule) ModuleItem() []ModuleItem {
nodes := n.Children(selector.ModuleItem)
var result []ModuleItem = make([]ModuleItem, 0, len(nodes))
Expand Down
12 changes: 6 additions & 6 deletions tm-parsers/js/js.tm
Expand Up @@ -1126,7 +1126,7 @@ ImportDeclaration -> ImportDeclaration :
;

ImportRequireDeclaration -> TsImportRequireDeclaration:
'import' BindingIdentifier '=' 'require' '(' StringLiteral ')' ';' ;
'export'? 'import' BindingIdentifier '=' 'require' '(' StringLiteral ')' ';' ;

ImportClause :
ImportedDefaultBinding
Expand Down Expand Up @@ -1446,13 +1446,13 @@ BindingIdentifierOrPattern<Yield, Await> :
;

ConstructSignature -> ConstructSignature :
'new' TypeParameters? ParameterList<~Yield, ~Await> TypeAnnotation? ;
Modifiers? 'new' TypeParameters? ParameterList<~Yield, ~Await> TypeAnnotation? ;

# Note: using IdentifierName instead of BindingIdentifier to avoid r/r
# conflicts with ComputedPropertyName.
IndexSignature -> IndexSignature :
'[' IdentifierName ':' 'string' ']' TypeAnnotation
| '[' IdentifierName ':' 'number' ']' TypeAnnotation
Modifiers? '[' IdentifierName ':' 'string' ']' TypeAnnotation
| Modifiers? '[' IdentifierName ':' 'number' ']' TypeAnnotation
;

MethodSignature -> MethodSignature :
Expand Down Expand Up @@ -1485,7 +1485,7 @@ EnumMember -> TsEnumMember:
# A.8 Namespaces

NamespaceDeclaration -> TsNamespace:
'namespace' IdentifierPath NamespaceBody ;
('namespace' | 'module') IdentifierPath NamespaceBody ;

IdentifierPath:
BindingIdentifier
Expand Down Expand Up @@ -1564,7 +1564,7 @@ AmbientNamespaceElement -> TsAmbientElement /* interface */:
;

AmbientModuleDeclaration -> TsAmbientModule:
'declare' 'module' StringLiteral '{' ModuleBodyopt '}' ;
'declare' 'module' (StringLiteral | IdentifierNameDecl) '{' ModuleBodyopt '}' ;

%%

Expand Down
15 changes: 12 additions & 3 deletions tm-parsers/js/listener.go
Expand Up @@ -181,8 +181,8 @@ const (
RestParameter // BindingIdentifier TypeAnnotation?
TsThisParameter // TypeAnnotation
AccessibilityModifier
ConstructSignature // TypeParameters? Parameters TypeAnnotation?
IndexSignature // TypeAnnotation
ConstructSignature // (Modifier)* TypeParameters? Parameters TypeAnnotation?
IndexSignature // (Modifier)* TypeAnnotation
MethodSignature // (Modifier)* PropertyName TypeParameters? Parameters TypeAnnotation?
TypeAliasDeclaration // BindingIdentifier TypeParameters? TsType
TsInterface // BindingIdentifier TypeParameters? TsInterfaceExtends? ObjectType
Expand All @@ -206,7 +206,7 @@ const (
TsAmbientIndexMember // IndexSignature
TsAmbientInterface // TsInterface
TsAmbientImportAlias // TsImportAliasDeclaration
TsAmbientModule // (ModuleItem)*
TsAmbientModule // BindingIdentifier? (ModuleItem)*
InsertedSemicolon
MultiLineComment
SingleLineComment
Expand Down Expand Up @@ -3812,6 +3812,7 @@ var ruleNodeType = [...]NodeType{
0, // ModuleItem : StatementListItem
ImportDeclaration, // ImportDeclaration : 'import' ImportClause FromClause ';'
ImportDeclaration, // ImportDeclaration : 'import' ModuleSpecifier ';'
TsImportRequireDeclaration, // ImportRequireDeclaration : 'export' 'import' BindingIdentifier '=' 'require' '(' StringLiteral ')' ';'
TsImportRequireDeclaration, // ImportRequireDeclaration : 'import' BindingIdentifier '=' 'require' '(' StringLiteral ')' ';'
0, // ImportClause : ImportedDefaultBinding
0, // ImportClause : NameSpaceImport
Expand Down Expand Up @@ -4178,11 +4179,17 @@ var ruleNodeType = [...]NodeType{
AccessibilityModifier, // AccessibilityModifier : 'public'
AccessibilityModifier, // AccessibilityModifier : 'private'
AccessibilityModifier, // AccessibilityModifier : 'protected'
ConstructSignature, // ConstructSignature : Modifiers 'new' TypeParameters ParameterList TypeAnnotation
ConstructSignature, // ConstructSignature : Modifiers 'new' TypeParameters ParameterList
ConstructSignature, // ConstructSignature : Modifiers 'new' ParameterList TypeAnnotation
ConstructSignature, // ConstructSignature : Modifiers 'new' ParameterList
ConstructSignature, // ConstructSignature : 'new' TypeParameters ParameterList TypeAnnotation
ConstructSignature, // ConstructSignature : 'new' TypeParameters ParameterList
ConstructSignature, // ConstructSignature : 'new' ParameterList TypeAnnotation
ConstructSignature, // ConstructSignature : 'new' ParameterList
IndexSignature, // IndexSignature : Modifiers '[' IdentifierName ':' 'string' ']' TypeAnnotation
IndexSignature, // IndexSignature : '[' IdentifierName ':' 'string' ']' TypeAnnotation
IndexSignature, // IndexSignature : Modifiers '[' IdentifierName ':' 'number' ']' TypeAnnotation
IndexSignature, // IndexSignature : '[' IdentifierName ':' 'number' ']' TypeAnnotation
MethodSignature, // MethodSignature : Modifiers PropertyName_WithoutNew '?' FormalParameters
MethodSignature, // MethodSignature : Modifiers PropertyName_WithoutNew FormalParameters
Expand All @@ -4203,6 +4210,7 @@ var ruleNodeType = [...]NodeType{
TsEnumMember, // EnumMember : PropertyName
TsEnumMember, // EnumMember : PropertyName '=' AssignmentExpression_In
TsNamespace, // NamespaceDeclaration : 'namespace' IdentifierPath NamespaceBody
TsNamespace, // NamespaceDeclaration : 'module' IdentifierPath NamespaceBody
0, // IdentifierPath : BindingIdentifier
0, // IdentifierPath : IdentifierPath '.' BindingIdentifier
TsNamespaceBody, // NamespaceBody : '{' ModuleItemList '}'
Expand Down Expand Up @@ -4261,6 +4269,7 @@ var ruleNodeType = [...]NodeType{
TsAmbientTypeAlias, // AmbientNamespaceElement : 'export' TypeAliasDeclaration
TsAmbientTypeAlias, // AmbientNamespaceElement : TypeAliasDeclaration
TsAmbientModule, // AmbientModuleDeclaration : 'declare' 'module' StringLiteral '{' ModuleBodyopt '}'
TsAmbientModule, // AmbientModuleDeclaration : 'declare' 'module' IdentifierNameDecl '{' ModuleBodyopt '}'
0, // Elisionopt : Elision
0, // Elisionopt :
0, // TypeAnnotationopt : TypeAnnotation
Expand Down
42 changes: 21 additions & 21 deletions tm-parsers/js/parser.go
Expand Up @@ -21,41 +21,41 @@ func (e SyntaxError) Error() string {
}

func (p *Parser) Parse(lexer *Lexer) error {
return p.parse(5, 5396, lexer)
return p.parse(5, 5431, lexer)
}

func lookaheadRule(lexer *Lexer, next, rule int32, lhs *stackEntry) {
switch rule {
case 3537:
if lookahead(lexer, next, 0, 5390) {
case 3546:
if lookahead(lexer, next, 0, 5425) {
lhs.sym.symbol = 654 /* lookahead_StartOfArrowFunction */
} else {
lhs.sym.symbol = 155 /* lookahead_notStartOfArrowFunction */
}
return
case 3538:
if lookahead(lexer, next, 1, 5391) {
case 3547:
if lookahead(lexer, next, 1, 5426) {
lhs.sym.symbol = 332 /* lookahead_StartOfParametrizedCall */
} else {
lhs.sym.symbol = 288 /* lookahead_notStartOfParametrizedCall */
}
return
case 3539:
if lookahead(lexer, next, 4, 5394) {
case 3548:
if lookahead(lexer, next, 4, 5429) {
lhs.sym.symbol = 808 /* lookahead_StartOfMappedType */
} else {
lhs.sym.symbol = 800 /* lookahead_notStartOfMappedType */
}
return
case 3540:
if lookahead(lexer, next, 3, 5393) {
case 3549:
if lookahead(lexer, next, 3, 5428) {
lhs.sym.symbol = 814 /* lookahead_StartOfFunctionType */
} else {
lhs.sym.symbol = 793 /* lookahead_notStartOfFunctionType */
}
return
case 3541:
if lookahead(lexer, next, 2, 5392) {
case 3550:
if lookahead(lexer, next, 2, 5427) {
lhs.sym.symbol = 710 /* lookahead_StartsOfExtendsTypeRef */
} else {
lhs.sym.symbol = 709 /* lookahead_notStartsOfExtendsTypeRef */
Expand All @@ -65,23 +65,23 @@ func lookaheadRule(lexer *Lexer, next, rule int32, lhs *stackEntry) {
}

func AtStartOfArrowFunction(lexer *Lexer, next int32) bool {
return lookahead(lexer, next, 0, 5390)
return lookahead(lexer, next, 0, 5425)
}

func AtStartOfParametrizedCall(lexer *Lexer, next int32) bool {
return lookahead(lexer, next, 1, 5391)
return lookahead(lexer, next, 1, 5426)
}

func AtStartsOfExtendsTypeRef(lexer *Lexer, next int32) bool {
return lookahead(lexer, next, 2, 5392)
return lookahead(lexer, next, 2, 5427)
}

func AtStartOfFunctionType(lexer *Lexer, next int32) bool {
return lookahead(lexer, next, 3, 5393)
return lookahead(lexer, next, 3, 5428)
}

func AtStartOfMappedType(lexer *Lexer, next int32) bool {
return lookahead(lexer, next, 4, 5394)
return lookahead(lexer, next, 4, 5429)
}

func lookahead(l *Lexer, next int32, start, end int16) bool {
Expand Down Expand Up @@ -184,35 +184,35 @@ func (p *Parser) applyRule(rule int32, lhs *stackEntry, rhs []stackEntry) {
p.listener(IdentifierReference, rhs[2].sym.offset, rhs[2].sym.endoffset)
case 2704: // IterationStatement_Yield : 'for' '(' 'async' lookahead_notStartOfArrowFunction 'of' AssignmentExpression_In_Yield ')' Statement_Yield
p.listener(IdentifierReference, rhs[2].sym.offset, rhs[2].sym.endoffset)
case 3537:
case 3546:
if AtStartOfArrowFunction(p.lexer, p.next.symbol) {
lhs.sym.symbol = 654 /* lookahead_StartOfArrowFunction */
} else {
lhs.sym.symbol = 155 /* lookahead_notStartOfArrowFunction */
}
return
case 3538:
case 3547:
if AtStartOfParametrizedCall(p.lexer, p.next.symbol) {
lhs.sym.symbol = 332 /* lookahead_StartOfParametrizedCall */
} else {
lhs.sym.symbol = 288 /* lookahead_notStartOfParametrizedCall */
}
return
case 3539:
case 3548:
if AtStartOfMappedType(p.lexer, p.next.symbol) {
lhs.sym.symbol = 808 /* lookahead_StartOfMappedType */
} else {
lhs.sym.symbol = 800 /* lookahead_notStartOfMappedType */
}
return
case 3540:
case 3549:
if AtStartOfFunctionType(p.lexer, p.next.symbol) {
lhs.sym.symbol = 814 /* lookahead_StartOfFunctionType */
} else {
lhs.sym.symbol = 793 /* lookahead_notStartOfFunctionType */
}
return
case 3541:
case 3550:
if AtStartsOfExtendsTypeRef(p.lexer, p.next.symbol) {
lhs.sym.symbol = 710 /* lookahead_StartsOfExtendsTypeRef */
} else {
Expand Down

0 comments on commit 10940ef

Please sign in to comment.