[antlr-interest] Re: Skipping grammar
pwolleba
pwolleba at yahoo.no
Thu Oct 9 00:54:17 PDT 2003
Hello everyone
As you maybe know have I been struggling to parse a document language
which we are using at work. Anyway I have come to the conclusion that
I have to use multi lexer after some recommendations on this news
group.
So far it seems to be the correct choice, however now I have found a
new problem which I need your help to solve! (I will paste the code
below)
When parsing the document the parser is working properly, the tree
builder does not!
I have divided the parsing into two different documents where we
start with the model node, and when finding a method node it will
load the next parser. I have added "System.out.println" to see if the
method parser is loaded an activated, and it does, I get the correct
information printed.
The problem start when I want to print the full tree that is built by
both parsers, it doesn't print all, I just get some of the structure!
Model
|
|------BeerModel
|
|------Method
|
|------on subscribe
I expected more a structure like this
Model
|
|------BeerModel
|
|------Method
|
|----onsubscribe
|
|----Arguments
| |- test1
| |- test2
|
|----Expression
|
|-the expression text
I hope that you can find my error, and explain it to me. If you find
anything else I also should change please dont hesitate to tell me.
Best regards,
Per
------------------------------------MODEL PARSER-----------
header{
package accessclassgenerator;
}
class ModelParser extends Parser;
options {
buildAST=true;
k=2;
}
tokens{
DECLARATION;
}
modelNode : (MODEL^) modelDeclaration;
modelDeclaration : identifier (modelInherits)? (LCURLY!)
(modelDeclerationList)? (RCURLY!)(SEMI!);
modelDeclerationList : (modelDeclerations)+;
modelDeclerations :(methodeNode);
modelInherits : (INHERITS^) modelInheritsBody;
modelInheritsBody : identifier (DOT! modelInheritsBody)?;
methodeNode : methodeBody {#methodeNode=#
([DECLARATION,"method"],#methodeNode);};
methodeBody : (JAVADOC_OPEN!) {
MethodParser parser = new MethodParser
(getInputState());
parser.methodeNode();
{#methodeBody=#([parser.getAST
()],#methodeBody);};
};
identifier : ID;
class ModelLexer extends Lexer;
options {
k=10;
filter=true;
/* importVocab = Common;*/
}
LPAREN : '(';
RPAREN : ')';
LCURLY : '{';
RCURLY : '}';
SEMI : ';';
COMMA : ',';
INHERITS : "inherits ";
MODEL : "model ";
JAVADOC_OPEN: "method " {StartGenerate.selector.push("methodLexer");};
ID : (CHAR|'_')(CHAR|'_'|'0'..'9')*;
STRING_LITERAL :('"'!)(~'"')*('"'!);
WS : (' '
| '\t'
| '\n' { newline(); }
| '\r')
{ $setType(Token.SKIP); }
;
protected
CHAR : ('a'..'z'|'A'..'Z');
----------------------METHOD PARSER----------------------------
header{
package accessclassgenerator;
}
class MethodParser extends Parser;
options {
buildAST=true;
k=2;
}
tokens {
ARGUMENTS;
EXPRESSION;
}
methodeNode : (ID^) methodeDecleration methodBody;
methodeDecleration : (LPAREN!) (methodArguments)? (RPAREN!)
{#methodeDecleration=#
([ARGUMENTS,"Arguments"],#methodeDecleration);}
;
methodArguments : (methodArgument (COMMA! methodArguments)?)
;
methodArgument : declarationName;
methodBody : (i:METHOD_BODY^) {System.out.println(i.getText
());}
;
declarationName : (i:ID^) {System.out.println(i.getText());};
class MethodLexer extends Lexer;
options {
k=7;
/*importVocab = Common;*/
filter=true;
}
LPAREN : '(';
RPAREN : ')';
LCURLY : '{';
RCURLY : '}';
SEMI : ';';
COMMA : ',';
JAVADOC_CLOSE : (RCURLY)!(SEMI)! {StartGenerate.selector.pop();};
METHOD_BODY : '{'! (BracedExpr |~'}')* JAVADOC_CLOSE;
ID : (CHAR|'_')(CHAR|'_'|'0'..'9')*;
STRING_LITERAL :('"'!)(~'"')*('"'!);
WS : (' '
| '\t'
| '\n' { newline(); }
| '\r')
{ $setType(Token.SKIP); }
;
protected
CHAR : ('a'..'z'|'A'..'Z');
protected
BracedExpr : '{' (BracedExpr | ~'}')* "}";
---------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list