Show
Ignore:
Timestamp:
07/30/08 02:34:05 (5 months ago)
Author:
Chuck.Esterbrook
Message:

Added support for declaring and raising events.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/CobraParser.cobra

    r1553 r1560  
    851851                return theStruct 
    852852 
     853        def eventDecl as BoxEvent 
     854                token = .expect('EVENT') 
     855                name = .expect('ID').value to String 
     856                .expect('AS') 
     857                handlerType = .typeId 
     858                # ahem, duplicated from .boxVarDecl 
     859                docString = '' to ? 
     860                isNames = List<of String>(_isNamesStack) 
     861                if .peek.which=='IS' 
     862                        isNames = .isDeclNames 
     863                        attribs = .hasAttribs 
     864                        assert .last.which=='EOL' 
     865                        .undo  # need the EOL 
     866                        if .optionalIndent 
     867                                docString = .docString 
     868                                .dedent 
     869                else if .optionalIndent 
     870                        isNames = .isDeclNames 
     871                        attribs = .hasAttribs 
     872                        docString = .docString 
     873                        .dedent 
     874                else 
     875                        attribs = AttributeList() 
     876                return BoxEvent(token, .curBox, name, isNames, attribs, docString, handlerType) 
     877 
    853878        def enumDecl as EnumDecl 
    854879                token = .expect('ENUM') 
     
    10231048                                        on 'EOL', .endOfLine 
    10241049                                        on 'ENUM', .addDecl(box, .enumDecl) 
     1050                                        on 'EVENT', .addDecl(box, .eventDecl) 
    10251051                                        on 'SIG', .addDecl(box, .declareMethodSig) 
    10261052                                        on 'SHARED', .bodiedBoxMemberDeclsShared(box) 
     
    10941120                                docString = .docString 
    10951121                                .dedent 
    1096                 else 
    1097                         if .optionalIndent 
    1098                                 isNames = .isDeclNames 
    1099                                 attribs = .hasAttribs 
    1100                                 docString = .docString 
    1101                                 .dedent 
     1122                else if .optionalIndent 
     1123                        isNames = .isDeclNames 
     1124                        attribs = .hasAttribs 
     1125                        docString = .docString 
     1126                        .dedent 
    11021127                return BoxVar(tok, .curBox, identifier, type, isNames, initExpr, docString) 
    11031128 
     
    20362061 
    20372062        def raiseStmt as Stmt 
    2038                 .expect('RAISE') 
    2039                 .throwError('The "raise" keyword may be used in the future to raise events. If you are trying to throw an exception, use the "throw" keyword.') 
    2040                 return nil to passthrough # CC: throw FallThroughException() 
     2063                token = .expect('RAISE') 
     2064                exprs = .commaSepExprs('EOL') 
     2065                if exprs.count == 0 
     2066                        .throwError('Expecting one or more expressions after "raise", starting with the event. If you meant to throw the currently caught exception, use "throw" instead.') 
     2067                return RaiseStmt(token, exprs) 
    20412068 
    20422069        def returnStmt as Stmt