options { JAVA_UNICODE_ESCAPE=true; STATIC = false; } PARSER_BEGIN(ConnectorParser) public class ConnectorParser { public static void main (String [] args) { ConnectorParser parser; String filename = "example.con"; try { parser = new ConnectorParser(new java.io.FileInputStream(filename)); parser.Connector(); } catch (Exception e) { System.out.println(e); ParseException p = (ParseException)e; Token token = p.currentToken; System.out.println(token.image); } } } PARSER_END(ConnectorParser) /* WHITE SPACE */ SPECIAL_TOKEN : { " " | "\t" | "\n" | "\r" | "\f" } /* COMMENTS */ MORE : { "//" : IN_SINGLE_LINE_COMMENT | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT | "/*" : IN_MULTI_LINE_COMMENT } SPECIAL_TOKEN : { : DEFAULT } SPECIAL_TOKEN : { : DEFAULT } SPECIAL_TOKEN : { : DEFAULT } MORE : { < ~[] > } /* FUSEJ LITERALS */ TOKEN : { < IMPORT: "import"> | < CONNECTOR: "connector" > | < CONNECT: "connect:" > | < FOR: "for:" > | < BEFORE: "before:" > | < AFTER: "after:" > | < AFTERR: "after" > | < RETURNING: "returning:" > | < WHERE: "where:" > | < WHEN: "when:" > | < RETURNS: "returns" > | < PACKAGE: "package" > } /* LITERALS */ TOKEN : { < INTEGER_LITERAL: (["l","L"])? | (["l","L"])? | (["l","L"])? > | < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > | < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | < #OCTAL_LITERAL: "0" (["0"-"7"])* > | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* ()? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"] > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < CHARACTER_LITERAL: "'" ( (~["'","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) ) "'" > | < STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > | < JAVACODE_LITERAL: "${" (~["$"])* "}$"> } /* IDENTIFIERS */ TOKEN : { < IDENTIFIER: (|)* > | < CONNECTIONPOINTIDENTIFIER: (|)* > | < #LETTER: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] > | < #STARLETTER: [ "\u0024", "\u002a", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] > | < #DIGIT: [ "\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049" ] > } /* SEPARATORS */ TOKEN : { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE: "{" > | < RBRACE: "}" > | < LBRACKET: "[" > | < RBRACKET: "]" > | < SEMICOLON: ";" > | < COMMA: "," > | < DOT: "." > | < EQUALS: "=" > | < AND: "&&" > | < OR: "||" > | < NOT: "!" > } /**************************************************** * THE FUSEJ CONNECTOR LANGUAGE GRAMMAR STARTS HERE * ****************************************************/ void Connector() : {} { [ PackageDeclaration() ] ( ImportDeclaration() )* ConnectorDeclaration() } void PackageDeclaration() : {} { Name() } void ImportDeclaration() : {} { Name() [ "." "*" ] } void ConnectorDeclaration() : {} { Name() ConnectorBody() } void ConnectorBody() : {} { ConnectionPoint() ( | | | ) ConnectionPoint() [ ConnectionMappings()] [ ConnectionCondition() ] } void ConnectionPoint() : {} { ConnectionPointName() [ ArgumentList() ] ( ContextSpecification())* } void ConnectionPointName() : {} { ( LOOKAHEAD(2) )* } void ArgumentList() : {} { Argument() ( Argument() )* } void Argument() : {} { LOOKAHEAD(3) Name() [Name()] | "*" } void ContextSpecification() : {} { ConditionalOrExpression() | "(" ContextSpecification() ")" } void ConditionalOrExpression(): {} { ConditionalAndExpression() [LOOKAHEAD(2) "||" ContextSpecification() ] } void ConditionalAndExpression(): {} { Condition() [LOOKAHEAD(2) "&&" ContextSpecification()] } void Condition() : {} { [] (LOOKAHEAD(5) SingleProperty() | DoubleProperty() | ReturnProperty()) } void SingleProperty() : {} { Name() } void DoubleProperty() : {} { Name() } void ReturnProperty() : {} { Argument() } void ConnectionMappings() : {} { ( ConnectionMapping() )* } void ConnectionMapping() : {} { Name() (LOOKAHEAD(3) ConnectionPoint() | Name() | JavaCode() ) } void ConnectionCondition() : {} { ConnectionPoint() | JavaCode() } void Name() : {} { ( LOOKAHEAD(2) )* } void JavaCode() : {} { } /************************************************* * THE FUSEJ CONNECTOR LANGUAGE GRAMMAR END HERE * *************************************************/