compiler/Dart__Parser.st
changeset 3 46c322c66a29
parent 2 8fedb5e096fc
child 4 5ef74750c3bc
equal deleted inserted replaced
2:8fedb5e096fc 3:46c322c66a29
    39 		staticFinalDeclaration staticFinalDeclarationList
    39 		staticFinalDeclaration staticFinalDeclarationList
    40 		superCallOrFieldInitializer superclass superinterfaces switchCase
    40 		superCallOrFieldInitializer superclass superinterfaces switchCase
    41 		topLevelDefinition tryStatement type typeArguments typeList
    41 		topLevelDefinition tryStatement type typeArguments typeList
    42 		typeParameter typeParameters unaryExpression
    42 		typeParameter typeParameters unaryExpression
    43 		userDefinableOperator variableDeclaration'
    43 		userDefinableOperator variableDeclaration'
    44 	classVariableNames:''
    44 	classVariableNames:'Debugging'
    45 	poolDictionaries:''
    45 	poolDictionaries:''
    46 	category:'Languages-Dart-Parser'
    46 	category:'Languages-Dart-Parser'
    47 !
    47 !
    48 
    48 
    49 PPParser subclass:#TokenParser
    49 PPParser subclass:#TokenParser
   883 variableDeclaration
   883 variableDeclaration
   884 
   884 
   885 	^declaredIdentifier , (((',' asParser) , identifier) star)
   885 	^declaredIdentifier , (((',' asParser) , identifier) star)
   886 ! !
   886 ! !
   887 
   887 
       
   888 !Parser class methodsFor:'initialization'!
       
   889 
       
   890 debugging: aBoolean
       
   891     Debugging := aBoolean
       
   892 
       
   893     "
       
   894         JavaParser debugging: true.
       
   895         JavaParser debugging: false.
       
   896     "
       
   897 
       
   898     "Created: / 11-01-2013 / 11:32:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   899 !
       
   900 
       
   901 initialize
       
   902     "Invoked at system start or when the class is dynamically loaded."
       
   903 
       
   904     "/ please change as required (and remove this comment)
       
   905 
       
   906     Debugging := false.
       
   907 
       
   908     "Modified: / 11-01-2013 / 11:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   909 ! !
       
   910 
       
   911 !Parser methodsFor:'accessing'!
       
   912 
       
   913 start
       
   914     ^compilationUnit , (TokenParser for: #EOF).
       
   915 
       
   916     "Created: / 11-01-2013 / 13:19:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   917 ! !
       
   918 
       
   919 !Parser methodsFor:'grammar'!
       
   920 
       
   921 additiveExpression
       
   922 
       
   923         ^ (multiplicativeExpression , ((additiveOperator , multiplicativeExpression) star))
       
   924         / ((TokenParser for: #super) , ((additiveOperator , multiplicativeExpression) plus))
       
   925 
       
   926     "Modified: / 11-01-2013 / 09:59:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   927 !
       
   928 
       
   929 additiveOperator
       
   930 
       
   931 	^ ('+' asParser)
       
   932 	/ ('-' asParser)
       
   933 	
       
   934 !
       
   935 
       
   936 argumentList
       
   937 
       
   938 	^ (namedArgument , (((',' asParser) , namedArgument) star))
       
   939 	/ (expressionList , (((',' asParser) , namedArgument) star))
       
   940 	
       
   941 !
       
   942 
       
   943 arguments
       
   944 
       
   945 	^('(' asParser) , (argumentList optional) , (')' asParser)
       
   946 !
       
   947 
       
   948 assignableExpression
       
   949 
       
   950         ^ (primary , (((arguments star) , assignableSelector) plus))
       
   951         / ((TokenParser for: #super) , assignableSelector)
       
   952         / identifier
       
   953 
       
   954     "Modified: / 11-01-2013 / 10:00:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   955 !
       
   956 
       
   957 assignableSelector
       
   958 
       
   959 	^ (('[' asParser) , constantExpression , (']' asParser))
       
   960 	/ (('.' asParser) , identifier)
       
   961 	
       
   962 !
       
   963 
       
   964 assignmentOperator
       
   965 
       
   966 	^ ('=' asParser)
       
   967 	/ ('*=' asParser)
       
   968 	/ ('/=' asParser)
       
   969 	/ ('~/=' asParser)
       
   970 	/ ('%=' asParser)
       
   971 	/ ('+=' asParser)
       
   972 	/ ('-=' asParser)
       
   973 	/ ('<<=' asParser)
       
   974 	/ (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser))
       
   975 	/ (('>' asParser) , ('>' asParser) , ('=' asParser))
       
   976 	/ ('&=' asParser)
       
   977 	/ ('^=' asParser)
       
   978 	/ ('|=' asParser)
       
   979 	
       
   980 !
       
   981 
       
   982 bitwiseAndExpression
       
   983 
       
   984         ^ (equalityExpression , ((('&' asParser) , equalityExpression) star))
       
   985         / ((TokenParser for: #super) , ((('&' asParser) , equalityExpression) plus))
       
   986 
       
   987     "Modified: / 11-01-2013 / 10:00:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   988 !
       
   989 
       
   990 bitwiseOperator
       
   991 
       
   992 	^ ('&' asParser)
       
   993 	/ ('^' asParser)
       
   994 	/ ('|' asParser)
       
   995 	
       
   996 !
       
   997 
       
   998 bitwiseOrExpression
       
   999 
       
  1000 	^ (bitwiseXorExpression , ((('|' asParser) , bitwiseXorExpression) star))
       
  1001 	/ ((TokenParser for:#super) , ((('|' asParser) , bitwiseXorExpression) plus))
       
  1002 	
       
  1003 !
       
  1004 
       
  1005 bitwiseXorExpression
       
  1006 
       
  1007 	^ (bitwiseAndExpression , ((('^' asParser) , bitwiseAndExpression) star))
       
  1008 	/ ((TokenParser for:#super) , ((('^' asParser) , bitwiseAndExpression) plus))
       
  1009 	
       
  1010 !
       
  1011 
       
  1012 block
       
  1013 
       
  1014 	^('{' asParser) , statements , ('}' asParser)
       
  1015 !
       
  1016 
       
  1017 catchPart
       
  1018 
       
  1019 	^(TokenParser for:#catch) , ('(' asParser) , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (')' asParser) , block
       
  1020 !
       
  1021 
       
  1022 classDefinition
       
  1023 
       
  1024 	^ ((TokenParser for:#class) , identifier , (typeParameters optional) , (superclass optional) , (interfaces optional) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser))
       
  1025 	/ ((TokenParser for:#class) , identifier , (typeParameters optional) , (interfaces optional) , (TokenParser for:#native) , (TokenParser for:#string) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser))
       
  1026 	
       
  1027 !
       
  1028 
       
  1029 classMemberDefinition
       
  1030 
       
  1031 	^ (declaration , (';' asParser))
       
  1032 	/ (constructorDeclaration , (';' asParser))
       
  1033 	/ (methodDeclaration , functionBodyOrNative)
       
  1034 	/ ((TokenParser for:#const) , factoryConstructorDeclaration , functionNative)
       
  1035 	
       
  1036 !
       
  1037 
       
  1038 compilationUnit
       
  1039 
       
  1040         ^( ((TokenParser for: #'#!!') optional) , (directive star) , (topLevelDefinition star) )
       
  1041 
       
  1042     "Modified: / 11-01-2013 / 13:18:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1043 !
       
  1044 
       
  1045 compoundLiteral
       
  1046 
       
  1047 	^ listLiteral
       
  1048 	/ mapLiteral
       
  1049 	
       
  1050 !
       
  1051 
       
  1052 conditionalExpression
       
  1053 
       
  1054 	^logicalOrExpression , ((('?' asParser) , constantExpression , (':' asParser) , constantExpression) optional)
       
  1055 !
       
  1056 
       
  1057 constInitializedIdentifier
       
  1058 
       
  1059 	^identifier , ((('=' asParser) , constantExpression) optional)
       
  1060 !
       
  1061 
       
  1062 constInitializedVariableDeclaration
       
  1063 
       
  1064 	^declaredIdentifier , ((('=' asParser) , constantExpression) optional) , (((',' asParser) , constInitializedIdentifier) star)
       
  1065 !
       
  1066 
       
  1067 constantConstructorDeclaration
       
  1068 
       
  1069 	^(TokenParser for:#const) , qualified , formalParameterList
       
  1070 !
       
  1071 
       
  1072 constantExpression
       
  1073 
       
  1074 	^ (assignableExpression , assignmentOperator , constantExpression)
       
  1075 	/ conditionalExpression
       
  1076 	
       
  1077 !
       
  1078 
       
  1079 constructorDeclaration
       
  1080 
       
  1081 	^ (identifier , formalParameterList , ((redirection / initializers ) optional))
       
  1082 	/ (namedConstructorDeclaration , ((redirection / initializers ) optional))
       
  1083 	
       
  1084 !
       
  1085 
       
  1086 declaration
       
  1087 
       
  1088 	^ (constantConstructorDeclaration , ((redirection / initializers ) optional))
       
  1089 	/ (functionDeclaration , redirection)
       
  1090 	/ (namedConstructorDeclaration , redirection)
       
  1091 	/ ((TokenParser for:#abstract) , specialSignatureDefinition)
       
  1092 	/ ((TokenParser for:#abstract) , functionDeclaration)
       
  1093 	/ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , staticFinalDeclarationList)
       
  1094 	/ (((TokenParser for:#static) optional) , constInitializedVariableDeclaration)
       
  1095 	
       
  1096 !
       
  1097 
       
  1098 declaredIdentifier
       
  1099 
       
  1100 	^ ((TokenParser for:#final) , (type optional) , identifier)
       
  1101 	/ ((TokenParser for:#var) , identifier)
       
  1102 	/ (type , identifier)
       
  1103 	
       
  1104 !
       
  1105 
       
  1106 defaultCase
       
  1107 
       
  1108 	^(label optional) , (((TokenParser for:#case) , constantExpression , (':' asParser)) star) , (TokenParser for:#default) , (':' asParser) , statements
       
  1109 !
       
  1110 
       
  1111 defaultFormalParameter
       
  1112 
       
  1113 	^normalFormalParameter , ((('=' asParser) , constantExpression) optional)
       
  1114 !
       
  1115 
       
  1116 directive
       
  1117 
       
  1118 	^('#' asParser) , identifier , arguments , (';' asParser)
       
  1119 !
       
  1120 
       
  1121 equalityExpression
       
  1122 
       
  1123 	^ (relationalExpression , ((equalityOperator , relationalExpression) optional))
       
  1124 	/ ((TokenParser for:#super) , equalityOperator , relationalExpression)
       
  1125 	
       
  1126 !
       
  1127 
       
  1128 equalityOperator
       
  1129 
       
  1130 	^ ('==' asParser)
       
  1131 	/ ('!!=' asParser)
       
  1132 	/ ('===' asParser)
       
  1133 	/ ('!!==' asParser)
       
  1134 	
       
  1135 !
       
  1136 
       
  1137 expression
       
  1138 
       
  1139         ^ (assignableExpression , assignmentOperator , expression)
       
  1140         / conditionalExpression
       
  1141 
       
  1142     "Created: / 11-01-2013 / 13:22:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1143 !
       
  1144 
       
  1145 expressionInParentheses
       
  1146 
       
  1147 	^('(' asParser) , constantExpression , (')' asParser)
       
  1148 !
       
  1149 
       
  1150 expressionList
       
  1151 
       
  1152 	^constantExpression , (((',' asParser) , constantExpression) star)
       
  1153 !
       
  1154 
       
  1155 factoryConstructorDeclaration
       
  1156 
       
  1157 	^(TokenParser for:#factory) , qualified , (typeParameters optional) , ((('.' asParser) , identifier) optional) , formalParameterList
       
  1158 !
       
  1159 
       
  1160 factorySpecification
       
  1161 
       
  1162 	^(TokenParser for:#factory) , type
       
  1163 !
       
  1164 
       
  1165 fieldFormalParameter
       
  1166 
       
  1167 	^(finalVarOrType optional) , (TokenParser for:#this) , ('.' asParser) , identifier
       
  1168 !
       
  1169 
       
  1170 fieldInitializer
       
  1171 
       
  1172 	^(((TokenParser for:#this) , ('.' asParser)) optional) , identifier , ('=' asParser) , conditionalExpression
       
  1173 !
       
  1174 
       
  1175 finalVarOrType
       
  1176 
       
  1177 	^ ((TokenParser for:#final) , (type optional))
       
  1178 	/ (TokenParser for:#var)
       
  1179 	/ type
       
  1180 	
       
  1181 !
       
  1182 
       
  1183 finallyPart
       
  1184 
       
  1185 	^(TokenParser for:#finally) , block
       
  1186 !
       
  1187 
       
  1188 forInitializerStatement
       
  1189 
       
  1190 	^ (initializedVariableDeclaration , (';' asParser))
       
  1191 	/ ((constantExpression optional) , (';' asParser))
       
  1192 	
       
  1193 !
       
  1194 
       
  1195 forLoopParts
       
  1196 
       
  1197 	^ (forInitializerStatement , (constantExpression optional) , (';' asParser) , (expressionList optional))
       
  1198 	/ (declaredIdentifier , (TokenParser for:#in) , constantExpression)
       
  1199 	/ (identifier , (TokenParser for:#in) , constantExpression)
       
  1200 	
       
  1201 !
       
  1202 
       
  1203 formalParameterList
       
  1204 
       
  1205 	^ (('(' asParser) , (namedFormalParameters optional) , (')' asParser))
       
  1206 	/ (('(' asParser) , normalFormalParameter , (normalFormalParameterTail optional) , (')' asParser))
       
  1207 	
       
  1208 !
       
  1209 
       
  1210 functionBody
       
  1211 
       
  1212 	^ (('=>' asParser) , constantExpression , (';' asParser))
       
  1213 	/ block
       
  1214 	
       
  1215 !
       
  1216 
       
  1217 functionBodyOrNative
       
  1218 
       
  1219 	^ ((TokenParser for:#native) , functionBody)
       
  1220 	/ functionNative
       
  1221 	/ functionBody
       
  1222 	
       
  1223 !
       
  1224 
       
  1225 functionDeclaration
       
  1226 
       
  1227 	^(returnType optional) , identifier , formalParameterList
       
  1228 !
       
  1229 
       
  1230 functionExpression
       
  1231 
       
  1232 	^(((returnType optional) , identifier) optional) , formalParameterList , functionExpressionBody
       
  1233 !
       
  1234 
       
  1235 functionExpressionBody
       
  1236 
       
  1237 	^ (('=>' asParser) , constantExpression)
       
  1238 	/ block
       
  1239 	
       
  1240 !
       
  1241 
       
  1242 functionNative
       
  1243 
       
  1244 	^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (';' asParser)
       
  1245 !
       
  1246 
       
  1247 functionPrefix
       
  1248 
       
  1249 	^(returnType optional) , identifier
       
  1250 !
       
  1251 
       
  1252 functionTypeAlias
       
  1253 
       
  1254 	^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (';' asParser)
       
  1255 !
       
  1256 
       
  1257 getOrSet
       
  1258 
       
  1259 	^ (TokenParser for:#get)
       
  1260 	/ (TokenParser for:#set)
       
  1261 	
       
  1262 !
       
  1263 
       
  1264 identifier
       
  1265 
       
  1266         ^ (TokenParser for:#identifier_no_dollar)
       
  1267         / (TokenParser for:#identifier)
       
  1268         / (TokenParser for:#abstract)
       
  1269         / (TokenParser for:#assert)
       
  1270         / (TokenParser for:#class)
       
  1271         / (TokenParser for:#extends)
       
  1272         / (TokenParser for:#factory)
       
  1273         / (TokenParser for:#get)
       
  1274         / (TokenParser for:#implements)
       
  1275         / (TokenParser for:#import)
       
  1276         / (TokenParser for:#interface)
       
  1277         / (TokenParser for:#is)
       
  1278         / (TokenParser for:#library)
       
  1279         / (TokenParser for:#native)
       
  1280         / (TokenParser for:#negate)
       
  1281         / (TokenParser for:#operator)
       
  1282         / (TokenParser for:#set)
       
  1283         / (TokenParser for:#source)
       
  1284         / (TokenParser for:#static)
       
  1285         / (TokenParser for:#typedef)
       
  1286 
       
  1287     "Modified: / 11-01-2013 / 13:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1288 !
       
  1289 
       
  1290 importReference
       
  1291 
       
  1292 	^(((TokenParser for:#identifier) , (':' asParser)) optional) , (TokenParser for:#string)
       
  1293 !
       
  1294 
       
  1295 importReferences
       
  1296 
       
  1297 	^importReference , (((',' asParser) , importReference) star) , ((',' asParser) optional)
       
  1298 !
       
  1299 
       
  1300 incrementOperator
       
  1301 
       
  1302         ^ ('++' asParser)
       
  1303         / ('--' asParser)
       
  1304 
       
  1305     "Created: / 11-01-2013 / 13:27:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1306 !
       
  1307 
       
  1308 initializedIdentifier
       
  1309 
       
  1310 	^identifier , ((('=' asParser) , constantExpression) optional)
       
  1311 !
       
  1312 
       
  1313 initializedIdentifierList
       
  1314 
       
  1315 	^initializedIdentifier , (((',' asParser) , initializedIdentifier) star)
       
  1316 !
       
  1317 
       
  1318 initializedVariableDeclaration
       
  1319 
       
  1320 	^declaredIdentifier , ((('=' asParser) , constantExpression) optional) , (((',' asParser) , initializedIdentifier) star)
       
  1321 !
       
  1322 
       
  1323 initializers
       
  1324 
       
  1325 	^(':' asParser) , superCallOrFieldInitializer , (((',' asParser) , superCallOrFieldInitializer) star)
       
  1326 !
       
  1327 
       
  1328 interfaceDefinition
       
  1329 
       
  1330 	^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , ('{' asParser) , (interfaceMemberDefinition star) , ('}' asParser)
       
  1331 !
       
  1332 
       
  1333 interfaceMemberDefinition
       
  1334 
       
  1335 	^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (';' asParser))
       
  1336 	/ (functionDeclaration , (';' asParser))
       
  1337 	/ (constantConstructorDeclaration , (';' asParser))
       
  1338 	/ (namedConstructorDeclaration , (';' asParser))
       
  1339 	/ (specialSignatureDefinition , (';' asParser))
       
  1340 	/ (variableDeclaration , (';' asParser))
       
  1341 	
       
  1342 !
       
  1343 
       
  1344 interfaces
       
  1345 
       
  1346 	^(TokenParser for:#implements) , typeList
       
  1347 !
       
  1348 
       
  1349 isOperator
       
  1350 
       
  1351 	^(TokenParser for:#is) , (('!!' asParser) optional)
       
  1352 !
       
  1353 
       
  1354 iterationStatement
       
  1355 
       
  1356 	^ ((TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , statement)
       
  1357 	/ ((TokenParser for:#do) , statement , (TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , (';' asParser))
       
  1358 	/ ((TokenParser for:#for) , ('(' asParser) , forLoopParts , (')' asParser) , statement)
       
  1359 	
       
  1360 !
       
  1361 
       
  1362 label
       
  1363 
       
  1364 	^identifier , (':' asParser)
       
  1365 !
       
  1366 
       
  1367 libraryBody
       
  1368 
       
  1369 	^(libraryImport optional) , (librarySource optional)
       
  1370 !
       
  1371 
       
  1372 libraryDefinition
       
  1373 
       
  1374 	^(TokenParser for:#library) , ('{' asParser) , libraryBody , ('}' asParser)
       
  1375 !
       
  1376 
       
  1377 libraryImport
       
  1378 
       
  1379 	^(TokenParser for:#import) , ('=' asParser) , ('[' asParser) , (importReferences optional) , (']' asParser)
       
  1380 !
       
  1381 
       
  1382 librarySource
       
  1383 
       
  1384 	^(TokenParser for:#source) , ('=' asParser) , ('[' asParser) , (sourceUrls optional) , (']' asParser)
       
  1385 !
       
  1386 
       
  1387 libraryUnit
       
  1388 
       
  1389         ^libraryDefinition end
       
  1390 
       
  1391     "Modified: / 11-01-2013 / 10:07:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1392 !
       
  1393 
       
  1394 listLiteral
       
  1395 
       
  1396 	^('[' asParser) , ((expressionList , ((',' asParser) optional)) optional) , (']' asParser)
       
  1397 !
       
  1398 
       
  1399 literal
       
  1400 
       
  1401         ^ (TokenParser for: #null)
       
  1402         / (TokenParser for: #true)
       
  1403         / (TokenParser for: #false)
       
  1404         / (TokenParser for: #number)
       
  1405         / (TokenParser for:#string)
       
  1406 
       
  1407     "Modified: / 11-01-2013 / 10:08:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1408 !
       
  1409 
       
  1410 logicalAndExpression
       
  1411 
       
  1412 	^bitwiseOrExpression , ((('&&' asParser) , bitwiseOrExpression) star)
       
  1413 !
       
  1414 
       
  1415 logicalOrExpression
       
  1416 
       
  1417 	^logicalAndExpression , ((('||' asParser) , logicalAndExpression) star)
       
  1418 !
       
  1419 
       
  1420 mapLiteral
       
  1421 
       
  1422 	^('{' asParser) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , ('}' asParser)
       
  1423 !
       
  1424 
       
  1425 mapLiteralEntry
       
  1426 
       
  1427 	^(TokenParser for:#string) , (':' asParser) , constantExpression
       
  1428 !
       
  1429 
       
  1430 methodDeclaration
       
  1431 
       
  1432 	^ factoryConstructorDeclaration
       
  1433 	/ ((TokenParser for:#static) , functionDeclaration)
       
  1434 	/ specialSignatureDefinition
       
  1435 	/ (functionDeclaration , (initializers optional))
       
  1436 	/ (namedConstructorDeclaration , (initializers optional))
       
  1437 	
       
  1438 !
       
  1439 
       
  1440 multiplicativeExpression
       
  1441 
       
  1442 	^ (unaryExpression , ((multiplicativeOperator , unaryExpression) star))
       
  1443 	/ ((TokenParser for:#super) , ((multiplicativeOperator , unaryExpression) plus))
       
  1444 	
       
  1445 !
       
  1446 
       
  1447 multiplicativeOperator
       
  1448 
       
  1449 	^ ('*' asParser)
       
  1450 	/ ('/' asParser)
       
  1451 	/ ('%' asParser)
       
  1452 	/ ('~/' asParser)
       
  1453 	
       
  1454 !
       
  1455 
       
  1456 namedArgument
       
  1457 
       
  1458 	^label , constantExpression
       
  1459 !
       
  1460 
       
  1461 namedConstructorDeclaration
       
  1462 
       
  1463 	^identifier , ('.' asParser) , identifier , formalParameterList
       
  1464 !
       
  1465 
       
  1466 namedFormalParameters
       
  1467 
       
  1468 	^('[' asParser) , defaultFormalParameter , (((',' asParser) , defaultFormalParameter) star) , (']' asParser)
       
  1469 !
       
  1470 
       
  1471 negateOperator
       
  1472 
       
  1473 	^ ('!!' asParser)
       
  1474 	/ ('~' asParser)
       
  1475 	
       
  1476 !
       
  1477 
       
  1478 nonLabelledStatement
       
  1479 
       
  1480         ^ block
       
  1481         / (initializedVariableDeclaration , (';' asParser))
       
  1482         / iterationStatement
       
  1483         / selectionStatement
       
  1484         / tryStatement
       
  1485         / ((TokenParser for: #break) , (identifier optional) , (';' asParser))
       
  1486         / ((TokenParser for: #continue) , (identifier optional) , (';' asParser))
       
  1487         / ((TokenParser for: #return) , (constantExpression optional) , (';' asParser))
       
  1488         / ((TokenParser for: #throw) , (constantExpression optional) , (';' asParser))
       
  1489         / ((constantExpression optional) , (';' asParser))
       
  1490         / ((TokenParser for: #assert) , ('(' asParser) , conditionalExpression , (')' asParser) , (';' asParser))
       
  1491         / (functionDeclaration , functionBody)
       
  1492 
       
  1493     "Modified: / 11-01-2013 / 10:09:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1494 !
       
  1495 
       
  1496 normalFormalParameter
       
  1497 
       
  1498 	^ functionDeclaration
       
  1499 	/ fieldFormalParameter
       
  1500 	/ simpleFormalParameter
       
  1501 	
       
  1502 !
       
  1503 
       
  1504 normalFormalParameterTail
       
  1505 
       
  1506 	^ ((',' asParser) , namedFormalParameters)
       
  1507 	/ ((',' asParser) , normalFormalParameter , (normalFormalParameterTail optional))
       
  1508 	
       
  1509 !
       
  1510 
       
  1511 postfixExpression
       
  1512 
       
  1513 	^ (assignableExpression , postfixOperator)
       
  1514 	/ (primary , (selector star))
       
  1515 	
       
  1516 !
       
  1517 
       
  1518 postfixOperator
       
  1519 
       
  1520 	^ ('++' asParser)
       
  1521 	/ ('--' asParser)
       
  1522 	
       
  1523 !
       
  1524 
       
  1525 prefixOperator
       
  1526 
       
  1527 	^ additiveOperator
       
  1528 	/ negateOperator
       
  1529 	
       
  1530 !
       
  1531 
       
  1532 primary
       
  1533 
       
  1534 	^ primaryNoFE
       
  1535 	/ primaryFE
       
  1536 	
       
  1537 !
       
  1538 
       
  1539 primaryFE
       
  1540 
       
  1541 	^ functionExpression
       
  1542 	/ primaryNoFE
       
  1543 	
       
  1544 !
       
  1545 
       
  1546 primaryNoFE
       
  1547 
       
  1548         ^ (TokenParser for:#this)
       
  1549         / ((TokenParser for:#super) , assignableSelector)
       
  1550         / literal
       
  1551         / identifier
       
  1552         / (((TokenParser for:#const) optional) , (typeArguments optional) , compoundLiteral)
       
  1553         / (((TokenParser for: #new) / (TokenParser for:#const) ) , type , ((('.' asParser) , identifier) optional) , arguments)
       
  1554         / expressionInParentheses
       
  1555 
       
  1556     "Modified: / 11-01-2013 / 10:09:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1557 !
       
  1558 
       
  1559 qualified
       
  1560 
       
  1561 	^identifier , ((('.' asParser) , identifier) optional)
       
  1562 !
       
  1563 
       
  1564 redirection
       
  1565 
       
  1566 	^(':' asParser) , (TokenParser for:#this) , ((('.' asParser) , identifier) optional) , arguments
       
  1567 !
       
  1568 
       
  1569 relationalExpression
       
  1570 
       
  1571 	^ (shiftExpression , (((isOperator , type) / (relationalOperator , shiftExpression) ) optional))
       
  1572 	/ ((TokenParser for:#super) , relationalOperator , shiftExpression)
       
  1573 	
       
  1574 !
       
  1575 
       
  1576 relationalOperator
       
  1577 
       
  1578 	^ (('>' asParser) , ('=' asParser))
       
  1579 	/ ('>' asParser)
       
  1580 	/ ('<=' asParser)
       
  1581 	/ ('<' asParser)
       
  1582 	
       
  1583 !
       
  1584 
       
  1585 returnType
       
  1586 
       
  1587         ^ (TokenParser for: #void)
       
  1588         / type
       
  1589 
       
  1590     "Modified: / 11-01-2013 / 10:09:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1591 !
       
  1592 
       
  1593 selectionStatement
       
  1594 
       
  1595         ^ ((TokenParser for: #if) , ('(' asParser) , constantExpression , (')' asParser) , statement , (((TokenParser for: #else) , statement) optional))
       
  1596         / ((TokenParser for: #switch) , ('(' asParser) , constantExpression , (')' asParser) , ('{' asParser) , (switchCase star) , (defaultCase optional) , ('}' asParser))
       
  1597 
       
  1598     "Modified: / 11-01-2013 / 10:10:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1599 !
       
  1600 
       
  1601 selector
       
  1602 
       
  1603 	^ assignableSelector
       
  1604 	/ arguments
       
  1605 	
       
  1606 !
       
  1607 
       
  1608 shiftExpression
       
  1609 
       
  1610 	^ (additiveExpression , ((shiftOperator , additiveExpression) star))
       
  1611 	/ ((TokenParser for:#super) , ((shiftOperator , additiveExpression) plus))
       
  1612 	
       
  1613 !
       
  1614 
       
  1615 shiftOperator
       
  1616 
       
  1617 	^ ('<<' asParser)
       
  1618 	/ (('>' asParser) , ('>' asParser) , ('>' asParser))
       
  1619 	/ (('>' asParser) , ('>' asParser))
       
  1620 	
       
  1621 !
       
  1622 
       
  1623 simpleFormalParameter
       
  1624 
       
  1625 	^ declaredIdentifier
       
  1626 	/ identifier
       
  1627 	
       
  1628 !
       
  1629 
       
  1630 sourceUrls
       
  1631 
       
  1632 	^(TokenParser for:#string) , (((',' asParser) , (TokenParser for:#string)) star) , ((',' asParser) optional)
       
  1633 !
       
  1634 
       
  1635 specialSignatureDefinition
       
  1636 
       
  1637         ^ (((TokenParser for:#static) optional) , (returnType optional) , getOrSet , identifier , formalParameterList)
       
  1638         / ((returnType optional) , (TokenParser for: #operator) , userDefinableOperator , formalParameterList)
       
  1639 
       
  1640     "Modified: / 11-01-2013 / 10:10:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1641 !
       
  1642 
       
  1643 statement
       
  1644 
       
  1645 	^(label star) , nonLabelledStatement
       
  1646 !
       
  1647 
       
  1648 statements
       
  1649 
       
  1650 	^statement star
       
  1651 !
       
  1652 
       
  1653 staticFinalDeclaration
       
  1654 
       
  1655 	^identifier , ('=' asParser) , constantExpression
       
  1656 !
       
  1657 
       
  1658 staticFinalDeclarationList
       
  1659 
       
  1660 	^staticFinalDeclaration , (((',' asParser) , staticFinalDeclaration) star)
       
  1661 !
       
  1662 
       
  1663 superCallOrFieldInitializer
       
  1664 
       
  1665 	^ ((TokenParser for:#super) , arguments)
       
  1666 	/ ((TokenParser for:#super) , ('.' asParser) , identifier , arguments)
       
  1667 	/ fieldInitializer
       
  1668 	
       
  1669 !
       
  1670 
       
  1671 superclass
       
  1672 
       
  1673         ^(TokenParser for: #extends) , type
       
  1674 
       
  1675     "Modified: / 11-01-2013 / 10:10:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1676 !
       
  1677 
       
  1678 superinterfaces
       
  1679 
       
  1680         ^(TokenParser for: #extends) , typeList
       
  1681 
       
  1682     "Modified: / 11-01-2013 / 10:10:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1683 !
       
  1684 
       
  1685 switchCase
       
  1686 
       
  1687 	^(label optional) , (((TokenParser for:#case) , constantExpression , (':' asParser)) plus) , statements
       
  1688 !
       
  1689 
       
  1690 topLevelDefinition
       
  1691 
       
  1692 	^ classDefinition
       
  1693 	/ interfaceDefinition
       
  1694 	/ functionTypeAlias
       
  1695 	/ (functionDeclaration , functionBodyOrNative)
       
  1696 	/ ((returnType optional) , getOrSet , identifier , formalParameterList , functionBodyOrNative)
       
  1697 	/ ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (';' asParser))
       
  1698 	/ (constInitializedVariableDeclaration , (';' asParser))
       
  1699 	
       
  1700 !
       
  1701 
       
  1702 tryStatement
       
  1703 
       
  1704         ^(TokenParser for: #try) , block , (((catchPart plus) , (finallyPart optional)) / finallyPart )
       
  1705 
       
  1706     "Modified: / 11-01-2013 / 10:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1707 !
       
  1708 
       
  1709 type
       
  1710 
       
  1711 	^qualified , (typeArguments optional)
       
  1712 !
       
  1713 
       
  1714 typeArguments
       
  1715 
       
  1716 	^('<' asParser) , typeList , ('>' asParser)
       
  1717 !
       
  1718 
       
  1719 typeList
       
  1720 
       
  1721 	^type , (((',' asParser) , type) star)
       
  1722 !
       
  1723 
       
  1724 typeParameter
       
  1725 
       
  1726         ^identifier , (((TokenParser for: #extends) , type) optional)
       
  1727 
       
  1728     "Modified: / 11-01-2013 / 10:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1729 !
       
  1730 
       
  1731 typeParameters
       
  1732 
       
  1733 	^('<' asParser) , typeParameter , (((',' asParser) , typeParameter) star) , ('>' asParser)
       
  1734 !
       
  1735 
       
  1736 unaryExpression
       
  1737 
       
  1738 	^ postfixExpression
       
  1739 	/ (prefixOperator , unaryExpression)
       
  1740 	/ (negateOperator , (TokenParser for:#super))
       
  1741 	/ (('-' asParser) , (TokenParser for:#super))
       
  1742 	/ (postfixOperator , assignableExpression)
       
  1743 	
       
  1744 !
       
  1745 
       
  1746 userDefinableOperator
       
  1747 
       
  1748         ^ multiplicativeOperator
       
  1749         / additiveOperator
       
  1750         / shiftOperator
       
  1751         / relationalOperator
       
  1752         / bitwiseOperator
       
  1753         / ('==' asParser)
       
  1754         / ('~' asParser)
       
  1755         / (TokenParser for: #negate)
       
  1756         / (('[' asParser) , (']' asParser))
       
  1757         / (('[' asParser) , (']' asParser) , ('=' asParser))
       
  1758 
       
  1759     "Modified: / 11-01-2013 / 10:11:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1760 !
       
  1761 
       
  1762 variableDeclaration
       
  1763 
       
  1764 	^declaredIdentifier , (((',' asParser) , identifier) star)
       
  1765 ! !
       
  1766 
       
  1767 !Parser methodsFor:'initialization'!
       
  1768 
       
  1769 initializeStartingAt: aSymbol
       
  1770         | allVariableNames ignoredVariableNames productionIndexesAndNames debugger |
       
  1771         self initialize.        
       
  1772 
       
  1773         Debugging ifTrue:[
       
  1774             PPDebugger notNil ifTrue:[
       
  1775                 self assert: (Smalltalk loadPackage: 'stx:goodies/petitparser/devtools').
       
  1776                 debugger := PPDebugger new
       
  1777             ].
       
  1778         ].
       
  1779         "find all the productions that need to be initialized"
       
  1780         allVariableNames := self class allInstVarNames
       
  1781                 collect: [ :each | each asSymbol ].
       
  1782         ignoredVariableNames := self class ignoredNames
       
  1783                 collect: [ :each | each asSymbol ].
       
  1784         productionIndexesAndNames := ((1 to: self class instSize)
       
  1785                 collect: [ :index | index -> (allVariableNames at: index) ])
       
  1786                 reject: [ :assoc | ignoredVariableNames includes: assoc value ].
       
  1787 
       
  1788         "initialize productions with an undefined parser to be replaced later"
       
  1789         parser := PPUnresolvedParser named: aSymbol.
       
  1790         productionIndexesAndNames do: [ :assoc |
       
  1791                 self instVarAt: assoc key put: (PPUnresolvedParser named: assoc value) ].
       
  1792         parser def: (self perform: aSymbol).
       
  1793 
       
  1794         "resolve unresolved parsers with their actual implementation"
       
  1795         productionIndexesAndNames do: [ :assoc |
       
  1796                 (self respondsTo: assoc value)
       
  1797                         ifFalse: [ self error: 'Unable to initialize ' , assoc value printString ]
       
  1798                         ifTrue: [ 
       
  1799                             | production |
       
  1800                             production := ((self perform: assoc value)  name: assoc value; yourself).
       
  1801                             Debugging ifTrue:[
       
  1802                                 production := PPDebuggingParser parser: production  debugger: debugger
       
  1803                             ].
       
  1804 
       
  1805                             (self instVarAt: assoc key) def: production.
       
  1806 
       
  1807                                 ] ]
       
  1808 
       
  1809     "Created: / 12-03-2012 / 16:51:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1810     "Modified: / 11-01-2013 / 11:35:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1811 ! !
       
  1812 
   888 !Parser::TokenParser class methodsFor:'instance creation'!
  1813 !Parser::TokenParser class methodsFor:'instance creation'!
   889 
  1814 
   890 for: tokenType
  1815 for: tokenType
   891 
  1816 
   892     ^self new tokenType: tokenType
  1817     ^self new tokenType: tokenType
   929 
  1854 
   930 version_HG
  1855 version_HG
   931 
  1856 
   932     ^ '$Changeset: <not expanded> $'
  1857     ^ '$Changeset: <not expanded> $'
   933 ! !
  1858 ! !
       
  1859 
       
  1860 Parser initialize!