All pastes #283018 Raw Edit

Miscellany

public java v1 · immutable
#283018 ·published 2006-12-18 00:52 UTC
rendered paste body
/** A Java 1.5 grammar for ANTLR v3 derived from the spec * *  This is a very close representation of the spec; the changes *  are comestic (remove left recursion) and also fixes (the spec *  isn't exactly perfect).  I have run this on the 1.4.2 source *  and some nasty looking enums from 1.5, but have not really *  tested for 1.5 compatibility. * *  I built this with: java -Xmx100M org.antlr.Tool java.g  *  and got two errors that are ok (for now): *  java.g:691:9: Decision can match input such as *    "'0'..'9'{'E', 'e'}{'+', '-'}'0'..'9'{'D', 'F', 'd', 'f'}" *    using multiple alternatives: 3, 4 *  As a result, alternative(s) 4 were disabled for that input *  java.g:734:35: Decision can match input such as "{'$', 'A'..'Z', *    '_', 'a'..'z', '\u00C0'..'\u00D6', '\u00D8'..'\u00F6', *    '\u00F8'..'\u1FFF', '\u3040'..'\u318F', '\u3300'..'\u337F', *    '\u3400'..'\u3D2D', '\u4E00'..'\u9FFF', '\uF900'..'\uFAFF'}" *    using multiple alternatives: 1, 2 *  As a result, alternative(s) 2 were disabled for that input * *  You can turn enum on/off as a keyword :) * *  Version 1.0 -- initial release July 5, 2006 (requires 3.0b2 or higher) * *  Primary author: Terence Parr, July 2006 * *  Version 1.0.1 -- corrections by Koen Vanderkimpen & Marko van Dooren, *      October 25, 2006; *      fixed normalInterfaceDeclaration: now uses typeParameters instead *          of typeParameter (according to JLS, 3rd edition) *      fixed castExpression: no longer allows expression next to type *          (according to semantics in JLS, in contrast with syntax in JLS) */grammar XML;// LEXERfragmentLetter    :  '\u0024' |       '\u0041'..'\u005a' |       '\u005f' |       '\u0061'..'\u007a' |       '\u00c0'..'\u00d6' |       '\u00d8'..'\u00f6' |       '\u00f8'..'\u00ff' |       '\u0100'..'\u1fff' |       '\u3040'..'\u318f' |       '\u3300'..'\u337f' |       '\u3400'..'\u3d2d' |       '\u4e00'..'\u9fff' |       '\uf900'..'\ufaff'    ;fragmentJavaIDDigit    :  '\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'   ; DOCTYPE    :        '<!DOCTYPE' WS rootElementName=GENERIC_ID WS        (             ( 'SYSTEM' WS sys1=VALUE                            | 'PUBLIC' WS pub=VALUE WS sys2=VALUE              )            ( WS )?        )?        ( dtd=INTERNAL_DTD)?		'>'	; INTERNAL_DTD : '[' (options {greedy=false;} : .)* ']' ; PI :        '<?' target=GENERIC_ID WS?  ( ATTRIBUTE WS? )*  '?>'	; XMLDECL :        '<?' ('x'|'X') ('m'|'M') ('l'|'L') WS? ( ATTRIBUTE WS? )*  '?>'	; ELEMENT    : ( START_TAG            (ELEMENT            | t=PCDATA            | t=CDATA            | t=COMMENT            | pi=PI            )*            END_TAG        | EMPTY_ELEMENT        )    ; START_TAG     : '<' WS? name=GENERIC_ID WS?( ATTRIBUTE WS? )* '>'    ; EMPTY_ELEMENT     : '<' WS? name=GENERIC_ID WS?( ATTRIBUTE WS? )* '/>'    ; ATTRIBUTE     : name=GENERIC_ID WS? '=' WS? value=VALUE    ; END_TAG     : '</' WS? name=GENERIC_ID WS? '>'    ; COMMENT	:	'<!--' (options {greedy=false;} : .)* '-->'	; CDATA	:	'<![CDATA[' (options {greedy=false;} : .)* ']]>'{$channel=HIDDEN;}	; PCDATA : (~'<')+ ;  VALUE :         ( '\"' (~'\"')* '\"'        | '\'' (~'\'')* '\''        )	; GENERIC_ID     : ( LETTER | '_' | ':')         ( options {greedy=true;} : LETTER | '0'..'9' | '.' | '-' | '_' | ':' )*	; LETTER	: 'a'..'z' 	| 'A'..'Z'	;WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}    ;ML_COMMENT    :   '<!--' (options {greedy=false;} : .)* '-->' {$channel=HIDDEN;}    ;	LINE_COMMENT    : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}    ;