Mercurial > projects > dang
comparison src/parser/Parser.d @ 209:42e663451371
Renamed some of the actions. Declarations now have it's own action.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 19:05:17 +0200 |
parents | e0551773a005 |
children |
comparison
equal
deleted
inserted
replaced
208:41ccd50e7cbc | 209:42e663451371 |
---|---|
75 Decl parseDecl(Attribute att) | 75 Decl parseDecl(Attribute att) |
76 { | 76 { |
77 switch(peek.type) | 77 switch(peek.type) |
78 { | 78 { |
79 case Tok.Struct: | 79 case Tok.Struct: |
80 Id type = Id(next()); | 80 next(); |
81 Id iden = Id(require(Tok.Identifier)); | 81 Id iden = Id(require(Tok.Identifier)); |
82 return parseStruct(type, iden, att); | 82 return parseStruct(iden, att); |
83 | 83 |
84 case Tok.Class: | 84 case Tok.Class: |
85 Id type = Id(next()); | 85 next(); |
86 Id iden = Id(require(Tok.Identifier)); | 86 Id iden = Id(require(Tok.Identifier)); |
87 return parseClass(type, iden, att); | 87 return parseClass(iden, att); |
88 | 88 |
89 case Tok.Interface: | 89 case Tok.Interface: |
90 Id type = Id(next()); | 90 next(); |
91 Id iden = Id(require(Tok.Identifier)); | 91 Id iden = Id(require(Tok.Identifier)); |
92 return parseInterface(type, iden, att); | 92 return parseInterface(iden, att); |
93 | 93 |
94 case Tok.Alias: | 94 case Tok.Alias: |
95 next(); | 95 next(); |
96 auto decl = parseDecl(Attribute()); | 96 auto decl = parseDecl(Attribute()); |
97 return action.actOnAliasDecl(decl, att); | 97 return action.actOnAliasDecl(decl, att); |
102 | 102 |
103 switch(peek.type) | 103 switch(peek.type) |
104 { | 104 { |
105 case Tok.Seperator: | 105 case Tok.Seperator: |
106 Token sep = next(); | 106 Token sep = next(); |
107 return action.actOnDeclarator(type, iden, null, att); | 107 return action.actOnVarDecl(type, iden, null, att); |
108 | 108 |
109 case Tok.Assign: | 109 case Tok.Assign: |
110 Token assign = next(); | 110 Token assign = next(); |
111 Exp exp = parseExpression(); | 111 Exp exp = parseExpression(); |
112 require(Tok.Seperator); | 112 require(Tok.Seperator); |
113 return action.actOnDeclarator(type, iden, exp, att); | 113 return action.actOnVarDecl(type, iden, exp, att); |
114 | 114 |
115 case Tok.OpenParentheses: | 115 case Tok.OpenParentheses: |
116 return parseFunc(type, iden, att); | 116 return parseFunc(type, iden, att); |
117 | 117 |
118 default: | 118 default: |
119 auto n1 = next(); | 119 auto n1 = next(); |
120 isEOF(type.tok); | 120 isEOF(type.tok); |
121 messages.report(UnexpectedTok, n1.location).arg(n1.get(sm)); | 121 messages.report(UnexpectedTok, n1.location).arg(n1.get(sm)); |
122 return action.actOnDeclarator(type, iden, null, att); | 122 return action.actOnVarDecl(type, iden, null, att); |
123 } | 123 } |
124 messages.report(InvalidDeclType, peek.location) | 124 messages.report(InvalidDeclType, peek.location) |
125 .arg(sm.getText(peek.asRange)); | 125 .arg(sm.getText(peek.asRange)); |
126 | 126 |
127 default: | 127 default: |
261 } | 261 } |
262 | 262 |
263 /** | 263 /** |
264 Parse interface | 264 Parse interface |
265 */ | 265 */ |
266 Decl parseInterface(Id type, Id iden, Attribute att) | 266 Decl parseInterface(Id iden, Attribute att) |
267 { | 267 { |
268 auto decl = action.actOnDeclarator(type, iden, null, att); | 268 auto decl = action.actOnInterfaceDecl(iden, att); |
269 | 269 |
270 if (peek.type == Tok.Colon) | 270 if (peek.type == Tok.Colon) |
271 // SuperInterfaces | 271 // SuperInterfaces |
272 { | 272 { |
273 next(); // Remove colon. | 273 next(); // Remove colon. |
311 } | 311 } |
312 | 312 |
313 /** | 313 /** |
314 Parse class | 314 Parse class |
315 */ | 315 */ |
316 Decl parseClass(Id type, Id iden, Attribute att) | 316 Decl parseClass(Id iden, Attribute att) |
317 { | 317 { |
318 auto decl = action.actOnDeclarator(type, iden, null, att); | 318 auto decl = action.actOnClassDecl(iden, att); |
319 | 319 |
320 if (peek.type == Tok.Colon) | 320 if (peek.type == Tok.Colon) |
321 // BaseClassList - Super class and interfaces(in that order) | 321 // BaseClassList - Super class and interfaces(in that order) |
322 { | 322 { |
323 next(); // Remove colon. | 323 next(); // Remove colon. |
378 } | 378 } |
379 | 379 |
380 /** | 380 /** |
381 Parse struct | 381 Parse struct |
382 */ | 382 */ |
383 Decl parseStruct(Id type, Id iden, Attribute att) | 383 Decl parseStruct(Id iden, Attribute att) |
384 { | 384 { |
385 auto decl = action.actOnDeclarator(type, iden, null, att); | 385 auto decl = action.actOnStructDecl(iden, att); |
386 | 386 |
387 require(Tok.OpenBrace); | 387 require(Tok.OpenBrace); |
388 | 388 |
389 auto nes = parseAttributeInit; | 389 auto nes = parseAttributeInit; |
390 while( !isa(Tok.EOF) && !isa(Tok.CloseBrace) ) | 390 while( !isa(Tok.EOF) && !isa(Tok.CloseBrace) ) |
714 Exp init; | 714 Exp init; |
715 if (skip(Tok.Assign)) | 715 if (skip(Tok.Assign)) |
716 init = parseExpression(); | 716 init = parseExpression(); |
717 require(Tok.Seperator); | 717 require(Tok.Seperator); |
718 Attribute att; | 718 Attribute att; |
719 Decl d = action.actOnDeclarator(type, id, init, att); | 719 Decl d = action.actOnVarDecl(type, id, init, att); |
720 return d; | 720 return d; |
721 } | 721 } |
722 | 722 |
723 /** | 723 /** |
724 Parses a function/method given the already parsed return type and name | 724 Parses a function/method given the already parsed return type and name |
868 Id i; | 868 Id i; |
869 if(peek.type == Tok.Identifier) | 869 if(peek.type == Tok.Identifier) |
870 i = parseIdentifier(); | 870 i = parseIdentifier(); |
871 | 871 |
872 // Act on function type param | 872 // Act on function type param |
873 decls ~= action.actOnDeclarator(t, i, null, Attribute()); | 873 decls ~= action.actOnVarDecl(t, i, null, Attribute()); |
874 | 874 |
875 if(peek.type == Tok.Comma) | 875 if(peek.type == Tok.Comma) |
876 next(); | 876 next(); |
877 } | 877 } |
878 | 878 |