options { JDK_VERSION = "1.5"; USER_CHAR_STREAM = true; STATIC = false; MULTI = true; } PARSER_BEGIN(FramclipseNonScriptParser) package com.framsticks.framclipse.internal.parser; import java.io.StringReader; public class FramclipseNonScriptParser { private CharStreamWithOffset charStream = null; public java.util.Collection exceptions = new java.util.ArrayList(); public FramclipseNonScriptParser(String input) { this(new CharStreamWithOffset(new StringReader(input))); } private FramclipseNonScriptParser(CharStreamWithOffset charStream) { this((CharStream)charStream); this.charStream = charStream; } public static void main(String args[]) { String s = "expdef: \n name: urnohorl \n id: horla \n code:~ function kupa(a,b) { yeah \n } \n~\n\n\n"; FramclipseNonScriptParser t = new FramclipseNonScriptParser(s); try { SimpleNode n = t.FramclipseFile(); n.dump(""); System.out.println("Thank you."); } catch (Exception e) { System.out.println("Oops."); System.out.println(e.getMessage()); //e.printStackTrace(); } } } PARSER_END(FramclipseNonScriptParser) TOKEN_MGR_DECLS : { int blockNestingDepth ; } SKIP : { < "/*"(~["*"])* "*"(~["/"] (~["*"])* "*")* "/" > | <"//"(~["\r","\n"])*["\r"]"\n"> } SKIP : /* WHITE SPACE */ { " " | "\t" | "\r" | "\n" | "\f" } SKIP : /* WHITE SPACE */ { " " | "\t" } TOKEN : /* IDENTIFIERS */ { < IDENTIFIER: (|)* > | < #LETTER: ["_","a"-"z","A"-"Z"] > | < #DIGIT: ["0"-"9"] > } TOKEN : { < EOL: ("\r")?"\n" > } TOKEN : { : CodeSection } TOKEN : { < MULTI_SECT_START : ":~" > : MultiSect } TOKEN : { : SingleSect } TOKEN : { : GlobalInclude } SKIP : { <"# "(~["\r","\n"])*["\r"]"\n"> } TOKEN : { < INCLUDE_STRING: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\"","_"] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > : DEFAULT } TOKEN : { < MULTI_SECT_END : "~" (" ")* ("\r")?"\n" > : DEFAULT } TOKEN : { } TOKEN : { < STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\"","_"] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > | < UNTERM_STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","'","\"","_"] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* ["\r"] "\n" > } TOKEN : { < CODE_SECTION_END : "~" (" ")* ("\r")?"\n" > : DEFAULT } TOKEN : { | | /* | | | | | | | | | | | | */ } TOKEN : /* SEPARATORS */ { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE : "{" > { blockNestingDepth = 1 ; } : Block | "}" | < LBRACKET: "[" > | < RBRACKET: "]" > | < SEMICOLON: ";" > | < COMMA: "," > | < DOT: "." > } TOKEN : /* IDENTIFIERS */ { < IDENT: (|)* > } TOKEN : { < NESTED_LBRACE : "{" > { blockNestingDepth += 1 ; } | < RBRACE : "}" > { blockNestingDepth --; SwitchTo( blockNestingDepth==0 ? CodeSection : Block ) ; } } SKIP : { <~[]> } TOKEN : { < SINGLE_SECT_END : ("\r")?"\n" > : DEFAULT } TOKEN : { < PROP_VALUE : (~["\r","\n"])* > } ASTFramclipseFile FramclipseFile() : {} { /* FObject() (LOOKAHEAD (()+ FObject()) ()+ FObject())* ()* */ (((FObject()|GlobalInclude()) (|))|)* { return jjtThis; } } void FObject() : { } { {jjtThis.setBeginOffset(charStream.getBeginOffset());} { jjtThis.setClassName(token.image); } (|) (Property() | CodeSection() )* { jjtThis.setEndOffset(charStream.getBeginOffset() - 1); } } void CodeSection() : {} { { jjtThis.setBeginOffset(charStream.getBeginOffset()); } (GlobalDecl() | Function() | IncludeStmt())* { jjtThis.setEndOffset(charStream.getBeginOffset()); } } void Function() : {} { try{ { jjtThis.setBeginOffset(charStream.getBeginOffset()); } IdentList() [ IdentList() ] (CodeBlock())* } catch(ParseException e) { token_source.SwitchTo(DEFAULT); //error_skipto(new int[] { EOF }); } { jjtThis.setEndOffset(charStream.getBeginOffset()); } } void GlobalDecl() : {} { { jjtThis.setBeginOffset(charStream.getBeginOffset()); } IdentList() { jjtThis.setEndOffset(charStream.getBeginOffset()); } } void IncludeStmt() : {} { { jjtThis.setBeginOffset(charStream.getBeginOffset()); } { jjtThis.setFileName(token.image); } { jjtThis.setEndOffset(charStream.getOffset()); } } void GlobalInclude() : {} { { jjtThis.setBeginOffset(charStream.getBeginOffset()); } { jjtThis.setFileName(token.image); } { jjtThis.setEndOffset(charStream.getOffset()); } } void IdentList() : {} { { jjtThis.addIdent(token.image); } ( { jjtThis.addIdent(token.image); } )* } void Property() : {} { { jjtThis.setBeginOffset(charStream.getBeginOffset()); } { jjtThis.setName(token.image); } ( SingleLinePropertyValue() { jjtThis.setEndOffset(charStream.getBeginOffset() - 1); } | MultiLinePropertyValue() { jjtThis.setEndOffset(charStream.getBeginOffset()); } ) } void SingleLinePropertyValue() : {} { { jjtThis.setValue(token.image); } (| ) } void CodeBlock() #void : {} { (CodeBlock())* } void MultiLinePropertyValue() : {} { } JAVACODE void error_skipto(int[] kinds) #void { //ParseException e = generateParseException(); // generate the exception object. //System.out.println(e.toString()); // print the error message Token t; if(kinds.length > 0) { java.util.Arrays.sort(kinds); do { t = getNextToken(); } while (java.util.Arrays.binarySearch(kinds, t.kind) < 0); } }