You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ov...@apache.org on 2002/02/28 02:51:16 UTC
cvs commit: xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/flow flow.g
ovidiu 02/02/27 17:51:16
Added: src/scratchpad/schecoon/src/org/apache/cocoon/flow flow.g
Log:
Added. Modeled mostly after the Java grammar, although it's yet incomplete.
Revision Changes Path
1.1 xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/flow/flow.g
Index: flow.g
===================================================================
header {
package org.apache.cocoon.flow;
}
options {
language = Java;
}
class FlowParser extends Parser;
options {
k = 2;
}
exprs
: SEMI exprs
| expr
;
expr
: assignment
| function
;
function
: "function" (IDENT)? parameters block
;
parameters
: LPAREN (IDENT)* RPAREN
;
block
: LCURLY exprs RCURLY
;
assignment
: conditional
( ( ASSIGN
| PLUS_ASSIGN
| MINUS_ASSIGN
| STAR_ASSIGN
| DIV_ASSIGN
| MOD_ASSIGN
| BAND_ASSIGN
| BXOR_ASSIGN
| BOR_ASSIGN
)
assignment
)?
;
conditional
: logicalOr
(QUESTION assignment COLON conditional)?
;
logicalOr
: logicalAnd (LOR logicalAnd)*
;
logicalAnd
: inclusiveOr (LAND inclusiveOr)*
;
inclusiveOr
: exclusiveOr (BOR exclusiveOr)*
;
exclusiveOr
: and (BXOR and)*
;
and
: equality (BAND equality)*
;
equality
: relational ((NOT_EQUAL | EQUAL) relational)*
;
relational
: additive
( ( ( LT
| GT
| LE
| GE
)
additive
)*
| "instanceof" typespec
)
;
additive
: multiplicative ((PLUS | MINUS) multiplicative)*
;
multiplicative
: unary ((STAR | DIV | MOD) unary)*
;
unary
: INC unary
| DEC unary
| MINUS unary
| PLUS unary
| unaryNotPlusMinus
;
unaryNotPlusMinus
: BNOT unary
| LNOT unary
| postfix
;
postfix
: primary
| constant
| "true"
| "false"
| "null"
| LPAREN assignment RPAREN
;
primary
: IDENT
;
constant
: NUMBER
| CHAR_LITERAL
| STRING_LITERAL
;
typespec
: IDENT
;
class FlowLexer extends Lexer;
options {
k = 2;
testLiterals=false; // don't automatically test for literals
}
QUESTION : '?' ;
LPAREN : '(' ;
RPAREN : ')' ;
LBRACK : '[' ;
RBRACK : ']' ;
LCURLY : '{' ;
RCURLY : '}' ;
COLON : ':' ;
COMMA : ',' ;
ASSIGN : '=' ;
EQUAL : "==" ;
LNOT : '!' ;
BNOT : '~' ;
NOT_EQUAL : "!=" ;
DIV : '/' ;
DIV_ASSIGN : "/=" ;
PLUS : '+' ;
PLUS_ASSIGN : "+=" ;
INC : "++" ;
MINUS : '-' ;
MINUS_ASSIGN : "-=" ;
DEC : "--" ;
STAR : '*' ;
STAR_ASSIGN : "*=" ;
MOD : '%' ;
MOD_ASSIGN : "%=" ;
GE : ">=" ;
GT : ">" ;
LE : "<=" ;
LT : '<' ;
BXOR : '^' ;
BXOR_ASSIGN : "^=" ;
BOR : '|' ;
BOR_ASSIGN : "|=" ;
LOR : "||" ;
BAND : '&' ;
BAND_ASSIGN : "&=" ;
LAND : "&&" ;
SEMI : ';' ;
protected
PANYS : ('a'..'z'|'A'..'Z'|'@'|'#'|'$'|'_'|'?');
protected
ANY : (PANYS|PLUS|MINUS|COLON|SEMI|DIV|'0'..'9'|'.'|'"'|'\''|'='|'*'|'!');
IDENT : PANYS (ANY)* PANYS;
//
// The following are stolen from java.g in the ANTLR distribution.
//
WS : ( ' '
| '\t'
| '\f'
// handle newlines
| ( "\r\n" // Evil DOS
| '\r' // Macintosh
| '\n' // Unix (the right way)
)
{ newline(); }
)
{ $setType(Token.SKIP); }
;
// Single-line comments
SL_COMMENT
: "//"
(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
{$setType(Token.SKIP); newline();}
;
// multiple-line comments
ML_COMMENT
: "/*"
( /* '\r' '\n' can be matched in one alternative or by matching
'\r' in one iteration and '\n' in another. I am trying to
handle any flavor of newline that comes in, but the language
that allows both "\r\n" and "\r" and "\n" to all be valid
newline is ambiguous. Consequently, the resulting grammar
must be ambiguous. I'm shutting this warning off.
*/
options {
generateAmbigWarnings=false;
}
:
{ LA(2)!='/' }? '*'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('*'|'\n'|'\r')
)*
"*/"
{$setType(Token.SKIP);}
;
// character literals
CHAR_LITERAL
: '\'' ( ESC | ~'\'' ) '\''
;
// string literals
STRING_LITERAL
: '"' (ESC|~('"'|'\\'))* '"'
;
// escape sequence -- note that this is protected; it can only be called
// from another lexer rule -- it will not ever directly return a token to
// the parser
// There are various ambiguities hushed in this rule. The optional
// '0'...'9' digit matches should be matched here rather than letting
// them go back to STRING_LITERAL to be matched. ANTLR does the
// right thing by matching immediately; hence, it's ok to shut off
// the FOLLOW ambig warnings.
protected
ESC
: '\\'
( 'n'
| 'r'
| 't'
| 'b'
| 'f'
| '"'
| '\''
| '\\'
| ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
| ('0'..'3')
(
options {
warnWhenFollowAmbig = false;
}
: ('0'..'7')
(
options {
warnWhenFollowAmbig = false;
}
: '0'..'7'
)?
)?
| ('4'..'7')
(
options {
warnWhenFollowAmbig = false;
}
: ('0'..'9')
)?
)
;
// hexadecimal digit (again, note it's protected!)
protected
HEX_DIGIT
: ('0'..'9'|'A'..'F'|'a'..'f')
;
// a dummy rule to force vocabulary to be all characters (except special
// ones that ANTLR uses internally (0 to 2)
protected
VOCAB
: '\3'..'\377'
;
// a numeric literal
NUM_INT
{boolean isDecimal=false;}
: '.' {_ttype = DOT;}
(('0'..'9')+ (EXPONENT)? (FLOAT_SUFFIX)? { _ttype = NUMBER; })?
| ( '0' {isDecimal = true;} // special case for just '0'
( ('x'|'X')
( // hex
// the 'e'|'E' and float suffix stuff look
// like hex digits, hence the (...)+ doesn't
// know when to stop: ambig. ANTLR resolves
// it correctly by matching immediately. It
// is therefor ok to hush warning.
options {
warnWhenFollowAmbig=false;
}
: HEX_DIGIT
)+
| ('0'..'7')+ // octal
)?
| ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal
)
( ('l'|'L')
// only check to see if it's a float if looks like decimal so far
| {isDecimal}?
( '.' ('0'..'9')* (EXPONENT)? (FLOAT_SUFFIX)?
| EXPONENT (FLOAT_SUFFIX)?
| FLOAT_SUFFIX
)
{ _ttype = NUMBER; }
)?
;
// a couple protected methods to assist in matching floating point numbers
protected
EXPONENT
: ('e'|'E') ('+'|'-')? ('0'..'9')+
;
protected
FLOAT_SUFFIX
: 'f'|'F'|'d'|'D'
;
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org