Differences From Artifact [9df8a8a07696ff22]:
- File
polemy/parse.d
- 2010-11-23 07:42:13 - part of checkin [6ac127ddd0] on branch trunk - new evaluator (user: kinaba) [annotate]
To Artifact [b6858e7b65012cb1]:
- File
polemy/parse.d
- 2010-11-23 10:37:54 - part of checkin [5e924caac9] on branch trunk - added AST-rewriting macro sample. (user: kinaba) [annotate]
152 152 // [TODO] make this customizable from program
153 153 private static string[][] operator_perferences = [
154 154 ["||"],
155 155 ["&&"],
156 156 ["!="],
157 157 ["=="],
158 158 ["<","<=",">",">="],
159 - ["|"],
160 - ["^"],
161 - ["&"],
162 - ["<<", ">>"],
159 +// ["|"],
160 +// ["^"],
161 +// ["&"],
162 +// ["<<", ">>", "<<<", ">>>"],
163 163 ["+","-"],
164 164 ["~"],
165 165 ["*","/","%"],
166 - ["^^","**"],
166 +// ["^^","**"],
167 167 [".",".?"]
168 168 ];
169 169
170 170 AST E(size_t level)
171 171 {
172 172 /// Expression ::= (Binary left-associative operators over) Funcall
173 173
................................................................................
192 192 return Funcall();
193 193 else
194 194 return rec(E(level+1));
195 195 }
196 196
197 197 AST Funcall()
198 198 {
199 - /// Funcall ::= BaseExpression ["(" Expression%"," ")"]*
199 + /// Funcall ::= BaseExpression ["(" Expression%"," ")" | "{" ENTRIES "}"]*
200 200
201 201 auto e = BaseExpression();
202 202 for(;;)
203 203 if( tryEat("(") )
204 204 {
205 205 auto pos = currentPosition();
206 206 AST[] args;
................................................................................
222 222 else
223 223 break;
224 224 return e;
225 225 }
226 226
227 227 AST parseTableSetAfterBrace(AST e)
228 228 {
229 + /// TableSet ::= "{" (ID ":" E) % "," "}"
230 +
229 231 if( tryEat("}") )
230 232 return e;
231 233 auto pos = currentPosition();
232 234 for(;;)
233 235 {
234 236 string key = eatId("for table key", AllowQuoted);
235 237 eat(":", "after table key");
................................................................................
314 316 }
315 317 scope(exit) lex.popFront;
316 318 return new Var(pos, lex.front.str);
317 319 }
318 320
319 321 AST parsePatternMatch(LexPosition pos)
320 322 {
321 - // case( pmExpr )cases
323 + // case "(" pmExpr ")" CASES
322 324 //==>
323 325 // let pmVar = pmExpr in (... let pmTryFirst = ... in pmTryFirst())
324 326 eat("(", "after case");
325 327 AST pmExpr = E(0);
326 328 eat(")", "after case");
327 329 string pmVar = freshVarName();
328 330 string pmTryFirst = freshVarName();
................................................................................
657 659 case( 1 )
658 660 when(x){1}
659 661 `));
660 662 assert_nothrow(parseString(`
661 663 case( 1 )
662 664 when({aaaa:_}){1}
663 665 `));
666 + assert_nothrow(parseString(`
667 + case( 1 )
668 + when({aaaa:@value(x)}){1}
669 + when({aaaa:{bbb:_}, ccc:123}){1}
670 + `));
664 671 }