parser.py (10165:7e9edf4297a9) parser.py (10307:6df951dcd7d9)
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 304 unchanged lines hidden (view full) ---

313 p[0] = ast.EnumDeclAST(self, p[3], p[4], p[7])
314
315 def p_decl__state_decl(self, p):
316 "decl : STATE_DECL '(' type pairs ')' '{' type_states '}'"
317 p[4]["enumeration"] = "yes"
318 p[4]["state_decl"] = "yes"
319 p[0] = ast.StateDeclAST(self, p[3], p[4], p[7])
320
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 304 unchanged lines hidden (view full) ---

313 p[0] = ast.EnumDeclAST(self, p[3], p[4], p[7])
314
315 def p_decl__state_decl(self, p):
316 "decl : STATE_DECL '(' type pairs ')' '{' type_states '}'"
317 p[4]["enumeration"] = "yes"
318 p[4]["state_decl"] = "yes"
319 p[0] = ast.StateDeclAST(self, p[3], p[4], p[7])
320
321 def p_decl__object(self, p):
322 "decl : type ident pairs SEMI"
323 p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3])
321 # Type fields
322 def p_type_members__list(self, p):
323 "type_members : type_member type_members"
324 p[0] = [ p[1] ] + p[2]
324
325
326 def p_type_members__empty(self, p):
327 "type_members : empty"
328 p[0] = []
329
330 def p_type_member__0(self, p):
331 """type_member : obj_decl
332 | func_decl
333 | func_def"""
334 p[0] = p[1]
335
336 # Member / Variable declarations
337 def p_decl__obj_decl(self, p):
338 "decl : obj_decl"
339 p[0] = p[1]
340
341 def p_obj_decl__0(self, p):
342 "obj_decl : type ident pairs SEMI"
343 p[0] = ast.ObjDeclAST(self, p[1], p[2], p[3], None)
344
345 def p_obj_decl__1(self, p):
346 "obj_decl : type STAR ident pairs SEMI"
347 p[0] = ast.ObjDeclAST(self, p[1], p[3], p[4], None)
348
349 def p_obj_decl__2(self, p):
350 "obj_decl : type ident ASSIGN expr SEMI"
351 p[0] = ast.ObjDeclAST(self, p[1], p[2], ast.PairListAST(self), p[4])
352
353 def p_obj_decl__3(self, p):
354 "obj_decl : type STAR ident ASSIGN expr SEMI"
355 p[0] = ast.ObjDeclAST(self, p[1], p[3], ast.PairListAST(self), p[5])
356
325 # Function definition and declaration
326 def p_decl__func_decl(self, p):
327 "decl : func_decl"
328 p[0] = p[1]
329
330 def p_func_decl__0(self, p):
331 """func_decl : void ident '(' params ')' pairs SEMI
332 | type ident '(' params ')' pairs SEMI"""
333 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None)
334
357 # Function definition and declaration
358 def p_decl__func_decl(self, p):
359 "decl : func_decl"
360 p[0] = p[1]
361
362 def p_func_decl__0(self, p):
363 """func_decl : void ident '(' params ')' pairs SEMI
364 | type ident '(' params ')' pairs SEMI"""
365 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None)
366
367 def p_func_decl__1(self, p):
368 """func_decl : void ident '(' types ')' pairs SEMI
369 | type ident '(' types ')' pairs SEMI"""
370 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], None)
371
335 def p_decl__func_def(self, p):
336 "decl : func_def"
337 p[0] = p[1]
338
339 def p_func_def__0(self, p):
340 """func_def : void ident '(' params ')' pairs statements
341 | type ident '(' params ')' pairs statements"""
342 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7])
343
372 def p_decl__func_def(self, p):
373 "decl : func_def"
374 p[0] = p[1]
375
376 def p_func_def__0(self, p):
377 """func_def : void ident '(' params ')' pairs statements
378 | type ident '(' params ')' pairs statements"""
379 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7])
380
344 # Type fields
345 def p_type_members__list(self, p):
346 "type_members : type_member type_members"
347 p[0] = [ p[1] ] + p[2]
348
349 def p_type_members__empty(self, p):
350 "type_members : empty"
351 p[0] = []
352
353 def p_type_method__0(self, p):
354 "type_member : type_or_void ident '(' types ')' pairs SEMI"
355 p[0] = ast.TypeFieldMethodAST(self, p[1], p[2], p[4], p[6])
356
357 def p_type_method__1(self, p):
358 "type_member : type_or_void ident '(' params ')' pairs statements"
359 p[0] = ast.FuncDeclAST(self, p[1], p[2], p[4], p[6], p[7])
360
361 def p_type_member__1(self, p):
362 "type_member : type_or_void ident pairs SEMI"
363 p[0] = ast.TypeFieldMemberAST(self, p[1], p[2], p[3], None)
364
365 def p_type_member__2(self, p):
366 "type_member : type_or_void ident ASSIGN expr SEMI"
367 p[0] = ast.TypeFieldMemberAST(self, p[1], p[2],
368 ast.PairListAST(self), p[4])
369
370 # Enum fields
371 def p_type_enums__list(self, p):
372 "type_enums : type_enum type_enums"
373 p[0] = [ p[1] ] + p[2]
374
375 def p_type_enums__empty(self, p):
376 "type_enums : empty"
377 p[0] = []

--- 10 unchanged lines hidden (view full) ---

388 def p_type_states__empty(self, p):
389 "type_states : empty"
390 p[0] = []
391
392 def p_type_state(self, p):
393 "type_state : ident ',' enumeration pairs SEMI"
394 p[0] = ast.TypeFieldStateAST(self, p[1], p[3], p[4])
395
381 # Enum fields
382 def p_type_enums__list(self, p):
383 "type_enums : type_enum type_enums"
384 p[0] = [ p[1] ] + p[2]
385
386 def p_type_enums__empty(self, p):
387 "type_enums : empty"
388 p[0] = []

--- 10 unchanged lines hidden (view full) ---

399 def p_type_states__empty(self, p):
400 "type_states : empty"
401 p[0] = []
402
403 def p_type_state(self, p):
404 "type_state : ident ',' enumeration pairs SEMI"
405 p[0] = ast.TypeFieldStateAST(self, p[1], p[3], p[4])
406
396 # Type
397 def p_types__multiple(self, p):
398 "types : type ',' types"
399 p[0] = [ p[1] ] + p[3]
400
401 def p_types__one(self, p):
402 "types : type"
403 p[0] = [ p[1] ]
404
405 def p_types__empty(self, p):
406 "types : empty"
407 p[0] = []
408
409 def p_typestr__multi(self, p):
410 "typestr : typestr DOUBLE_COLON ident"
411 p[0] = '%s::%s' % (p[1], p[3])
412
413 def p_typestr__single(self, p):
414 "typestr : ident"
415 p[0] = p[1]
416
417 def p_type__one(self, p):
418 "type : typestr"
419 p[0] = ast.TypeAST(self, p[1])
420
421 def p_void(self, p):
422 "void : VOID"
423 p[0] = ast.TypeAST(self, p[1])
424
425 def p_type_or_void(self, p):
426 """type_or_void : type
427 | void"""
428 p[0] = p[1]
429
430 # Formal Param
431 def p_params__many(self, p):
432 "params : param ',' params"
433 p[0] = [ p[1] ] + p[3]
434
435 def p_params__one(self, p):
436 "params : param"
437 p[0] = [ p[1] ]

--- 21 unchanged lines hidden (view full) ---

459 def p_param__default_bool(self, p):
460 "param : type ident '=' LIT_BOOL"
461 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
462
463 def p_param__default_string(self, p):
464 "param : type ident '=' STRING"
465 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
466
407 # Formal Param
408 def p_params__many(self, p):
409 "params : param ',' params"
410 p[0] = [ p[1] ] + p[3]
411
412 def p_params__one(self, p):
413 "params : param"
414 p[0] = [ p[1] ]

--- 21 unchanged lines hidden (view full) ---

436 def p_param__default_bool(self, p):
437 "param : type ident '=' LIT_BOOL"
438 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
439
440 def p_param__default_string(self, p):
441 "param : type ident '=' STRING"
442 p[0] = ast.FormalParamAST(self, p[1], p[2], p[4])
443
444 # Type
445 def p_types__multiple(self, p):
446 "types : type ',' types"
447 p[0] = [ p[1] ] + p[3]
448
449 def p_types__one(self, p):
450 "types : type"
451 p[0] = [ p[1] ]
452
453 def p_types__empty(self, p):
454 "types : empty"
455 p[0] = []
456
457 def p_typestr__multi(self, p):
458 "typestr : typestr DOUBLE_COLON ident"
459 p[0] = '%s::%s' % (p[1], p[3])
460
461 def p_typestr__single(self, p):
462 "typestr : ident"
463 p[0] = p[1]
464
465 def p_type__one(self, p):
466 "type : typestr"
467 p[0] = ast.TypeAST(self, p[1])
468
469 def p_void(self, p):
470 "void : VOID"
471 p[0] = ast.TypeAST(self, p[1])
472
467 # Idents and lists
468 def p_idents__braced(self, p):
469 "idents : '{' identx '}'"
470 p[0] = p[2]
471
472 def p_idents__bare(self, p):
473 "idents : ident"
474 p[0] = [ p[1] ]

--- 245 unchanged lines hidden ---
473 # Idents and lists
474 def p_idents__braced(self, p):
475 "idents : '{' identx '}'"
476 p[0] = p[2]
477
478 def p_idents__bare(self, p):
479 "idents : ident"
480 p[0] = [ p[1] ]

--- 245 unchanged lines hidden ---