comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg @ 18410:f444ef4684ec

SL: sanitize whitespace in ATG
author Andreas Woess <andreas.woess@jku.at>
date Tue, 21 Oct 2014 15:11:32 +0200
parents 7c8ddb4233cd
children dc2e000bed40
comparison
equal deleted inserted replaced
18409:d405651001d1 18410:f444ef4684ec
54 PRODUCTIONS 54 PRODUCTIONS
55 55
56 56
57 SimpleLanguage 57 SimpleLanguage
58 = 58 =
59 Function 59 Function
60 { 60 {
61 Function 61 Function
62 } 62 }
63 . 63 .
64 64
65 65
66 Function 66 Function
67 = 67 =
68 "function" 68 "function"
69 identifier (. Token identifierToken = t; .) 69 identifier (. Token identifierToken = t; .)
70 "(" (. int bodyStartPos = t.charPos; .) 70 "(" (. int bodyStartPos = t.charPos; .)
71 (. factory.startFunction(identifierToken, bodyStartPos); .) 71 (. factory.startFunction(identifierToken, bodyStartPos); .)
72 [ 72 [
73 identifier (. factory.addFormalParameter(t); .) 73 identifier (. factory.addFormalParameter(t); .)
74 { 74 {
75 "," 75 ","
76 identifier (. factory.addFormalParameter(t); .) 76 identifier (. factory.addFormalParameter(t); .)
77 } 77 }
78 ] 78 ]
79 ")" 79 ")"
80 Block<out SLStatementNode body, false> (. factory.finishFunction(body); .) 80 Block<out SLStatementNode body, false> (. factory.finishFunction(body); .)
81 . 81 .
82 82
83 83
84 84
85 Block<out SLStatementNode result, boolean inLoop> 85 Block<out SLStatementNode result, boolean inLoop>
86 = (. factory.startBlock(); 86 = (. factory.startBlock();
87 List<SLStatementNode> body = new ArrayList<>(); .) 87 List<SLStatementNode> body = new ArrayList<>(); .)
88 "{" (. int start = t.charPos; .) 88 "{" (. int start = t.charPos; .)
89 { 89 {
90 Statement<out SLStatementNode s, inLoop> (. body.add(s); .) 90 Statement<out SLStatementNode s, inLoop> (. body.add(s); .)
91 } 91 }
92 "}" (. int length = (t.charPos + t.val.length()) - start; .) 92 "}" (. int length = (t.charPos + t.val.length()) - start; .)
93 (. result = factory.finishBlock(body, start, length); .) 93 (. result = factory.finishBlock(body, start, length); .)
94 . 94 .
95 95
96 96
97 Statement<out SLStatementNode result, boolean inLoop> 97 Statement<out SLStatementNode result, boolean inLoop>
98 = (. result = null; .) 98 = (. result = null; .)
102 "break" (. if (inLoop) { result = factory.createBreak(t); } else { SemErr("break used outside of loop"); } .) 102 "break" (. if (inLoop) { result = factory.createBreak(t); } else { SemErr("break used outside of loop"); } .)
103 ";" 103 ";"
104 | 104 |
105 "continue" (. if (inLoop) { result = factory.createContinue(t); } else { SemErr("continue used outside of loop"); } .) 105 "continue" (. if (inLoop) { result = factory.createContinue(t); } else { SemErr("continue used outside of loop"); } .)
106 ";" 106 ";"
107 | 107 |
108 IfStatement<out result, inLoop> 108 IfStatement<out result, inLoop>
109 | 109 |
110 ReturnStatement<out result> 110 ReturnStatement<out result>
111 | 111 |
112 Expression<out result> ";" 112 Expression<out result> ";"
114 . 114 .
115 115
116 116
117 WhileStatement<out SLStatementNode result> 117 WhileStatement<out SLStatementNode result>
118 = 118 =
119 "while" (. Token whileToken = t; .) 119 "while" (. Token whileToken = t; .)
120 "(" 120 "("
121 Expression<out SLExpressionNode condition> 121 Expression<out SLExpressionNode condition>
122 ")" 122 ")"
123 Block<out SLStatementNode body, true> (. result = factory.createWhile(whileToken, condition, body); .) 123 Block<out SLStatementNode body, true> (. result = factory.createWhile(whileToken, condition, body); .)
124 . 124 .
125 125
126 126
127 IfStatement<out SLStatementNode result, boolean inLoop> 127 IfStatement<out SLStatementNode result, boolean inLoop>
128 = 128 =
129 "if" (. Token ifToken = t; .) 129 "if" (. Token ifToken = t; .)
130 "(" 130 "("
131 Expression<out SLExpressionNode condition> 131 Expression<out SLExpressionNode condition>
132 ")" 132 ")"
133 Block<out SLStatementNode thenPart, inLoop> (. SLStatementNode elsePart = null; .) 133 Block<out SLStatementNode thenPart, inLoop> (. SLStatementNode elsePart = null; .)
134 [ 134 [
135 "else" 135 "else"
136 Block<out elsePart, inLoop> 136 Block<out elsePart, inLoop>
137 ] (. result = factory.createIf(ifToken, condition, thenPart, elsePart); .) 137 ] (. result = factory.createIf(ifToken, condition, thenPart, elsePart); .)
138 . 138 .
139 139
140 140
207 "(" (. List<SLExpressionNode> parameters = new ArrayList<>(); 207 "(" (. List<SLExpressionNode> parameters = new ArrayList<>();
208 SLExpressionNode parameter; .) 208 SLExpressionNode parameter; .)
209 [ 209 [
210 Expression<out parameter> (. parameters.add(parameter); .) 210 Expression<out parameter> (. parameters.add(parameter); .)
211 { 211 {
212 "," 212 ","
213 Expression<out parameter> (. parameters.add(parameter); .) 213 Expression<out parameter> (. parameters.add(parameter); .)
214 } 214 }
215 ] 215 ]
216 ")" (. Token finalToken = t; .) 216 ")" (. Token finalToken = t; .)
217 (. result = factory.createCall(nameToken, parameters, finalToken); .) 217 (. result = factory.createCall(nameToken, parameters, finalToken); .)
218 | 218 |
219 "=" 219 "="
220 Expression<out SLExpressionNode value> (. result = factory.createAssignment(nameToken, value); .) 220 Expression<out SLExpressionNode value> (. result = factory.createAssignment(nameToken, value); .)
221 | 221 |
222 (. result = factory.createRead(nameToken); .) 222 (. result = factory.createRead(nameToken); .)
223 ) 223 )
224 | 224 |
225 stringLiteral (. result = factory.createStringLiteral(t); .) 225 stringLiteral (. result = factory.createStringLiteral(t); .)
226 | 226 |
227 numericLiteral (. result = factory.createNumericLiteral(t); .) 227 numericLiteral (. result = factory.createNumericLiteral(t); .)
228 | 228 |
229 "(" (. int start = t.charPos; .) 229 "(" (. int start = t.charPos; .)
230 Expression<out result> (. SLExpressionNode expr = result; .) 230 Expression<out result> (. SLExpressionNode expr = result; .)
231 ")" (. int length = (t.charPos + t.val.length()) - start; .) 231 ")" (. int length = (t.charPos + t.val.length()) - start; .)
232 (. result = factory.createParenExpression(expr, start, length); .) 232 (. result = factory.createParenExpression(expr, start, length); .)
233 ) 233 )
234 . 234 .
235 235
236 236
237 END SimpleLanguage. 237 END SimpleLanguage.