org.nuiton.jaxx.compiler.css.parser.CSS.jj Maven / Gradle / Ivy
The newest version!
/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. .\CSS.jj */
/*@egen*//*
* Copyright 2006 Ethan Nicholas. All rights reserved.
* Use is subject to license terms.
*/
// I would love to have used an existing CSS parser, but all of the ones I could
// find are licensed under the LGPL. As JAXX is BSD licensed and I'm not a big
// fan of the LGPL, unfortunately that won't work.
options {
STATIC = false;
JDK_VERSION = "1.4";
}
PARSER_BEGIN(CSSParser)
package jaxx.css;
public class CSSParser/*@bgen(jjtree)*/implements CSSParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
protected JJTCSSParserState jjtree = new JJTCSSParserState();
/*@egen*/
public SimpleNode popNode() {
if ( jjtree.nodeArity() > 0) // number of child nodes
return (SimpleNode)jjtree.popNode();
else
return null;
}
void jjtreeOpenNodeScope(Node n) {
((SimpleNode) n).firstToken = getToken(1);
}
void jjtreeCloseNodeScope(Node n) {
((SimpleNode) n).lastToken = getToken(0);
}
public static void main(String args[]) {
System.out.println("Reading from standard input...");
CSSParser css = new CSSParser(System.in);
try {
SimpleNode n = css.Stylesheet();
n.dump("");
System.out.println("Thank you.");
} catch (Exception e) {
System.out.println("Oops.");
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
PARSER_END(CSSParser)
SKIP :
{
" "
| "\t"
| "\n"
| "\r"
| <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/">
}
<*> TOKEN : /* LITERALS */
{
("." )?>
|
<#INTEGER_LITERAL: (["0"-"9"])+>
}
TOKEN : /* IDENTIFIER */
{
(|)*>
|
<#LETTER: ["_", "-", "a"-"z", "A"-"Z"]>
|
<#DIGIT: ["0"-"9"]>
}
TOKEN : /* PSEUDOCLASS_IDENTIFIER */
{
> : DEFAULT
}
TOKEN: /* COLON */
{
: IN_PSEUDOCLASS
}
TOKEN: /* COLON_IN_RULE */
{
}
<*> TOKEN: /* SEMICOLON */
{
}
TOKEN : /* LEFT BRACE */
{
: IN_RULE
}
TOKEN : /* RIGHT BRACE */
{
: DEFAULT
}
TOKEN : /* JAVA_CODE_RULE START */
{
> : JAVA_CODE_RULE
}
TOKEN : /* JAVA_CODE_RULE */
{
}
TOKEN : /* JAVA_CODE_RULE END */
{
> : IN_RULE
}
TOKEN : /* PROGRAMMATIC_PSEUDOCLASS */
{
: DEFAULT
}
TOKEN : /* STRINGS */
{
}
TOKEN : /* COLORS */
{
( )?>
|
<#HEXDIGIT: ["0"-"9", "a"-"f", "A"-"F"]>
}
TOKEN : /* EMS */
{
"em">
}
TOKEN : /* EXS */
{
"ex">
}
TOKEN : /* LENGTH */
{
("pt" | "mm" | "cm" | "pc" | "in")>
}
SimpleNode Stylesheet() : {/*@bgen(jjtree) Stylesheet */
SimpleNode jjtn000 = new SimpleNode(JJTSTYLESHEET);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Stylesheet */
try {
/*@egen*/
(Rule())*/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
jjtreeCloseNodeScope(jjtn000);
}
/*@egen*/
{ return jjtn000; }/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Rule() : {/*@bgen(jjtree) Rule */
SimpleNode jjtn000 = new SimpleNode(JJTRULE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Rule */
try {
/*@egen*/
Selectors()
Declaration() (";" (Declaration())?)* /*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Selectors() : {/*@bgen(jjtree) Selectors */
SimpleNode jjtn000 = new SimpleNode(JJTSELECTORS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Selectors */
try {
/*@egen*/
Selector() ("," Selector())*/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Selector() : {/*@bgen(jjtree) Selector */
SimpleNode jjtn000 = new SimpleNode(JJTSELECTOR);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Selector */
try {
/*@egen*/
JavaClass() (Id())? (Class())? (PseudoClass())?
|
Id() (Class())? (PseudoClass())?
|
Class() (PseudoClass())?
|
PseudoClass()/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void JavaClass() : {/*@bgen(jjtree) JavaClass */
SimpleNode jjtn000 = new SimpleNode(JJTJAVACLASS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) JavaClass */
try {
/*@egen*/
| "*"/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Id() : {/*@bgen(jjtree) Id */
SimpleNode jjtn000 = new SimpleNode(JJTID);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Id */
try {
/*@egen*/
"#" /*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Class() : {/*@bgen(jjtree) Class */
SimpleNode jjtn000 = new SimpleNode(JJTCLASS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Class */
try {
/*@egen*/
"." /*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void PseudoClass() : {/*@bgen(jjtree) PseudoClass */
SimpleNode jjtn000 = new SimpleNode(JJTPSEUDOCLASS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) PseudoClass */
try {
/*@egen*/
( | ) (AnimationProperties())?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void AnimationProperties() : {/*@bgen(jjtree) AnimationProperties */
SimpleNode jjtn000 = new SimpleNode(JJTANIMATIONPROPERTIES);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) AnimationProperties */
try {
/*@egen*/
"[" AnimationProperty() ("," AnimationProperty())* "]"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void AnimationProperty() : {/*@bgen(jjtree) AnimationProperty */
SimpleNode jjtn000 = new SimpleNode(JJTANIMATIONPROPERTY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) AnimationProperty */
try {
/*@egen*/
"=" ()?/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Declaration() : {/*@bgen(jjtree) Declaration */
SimpleNode jjtn000 = new SimpleNode(JJTDECLARATION);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Declaration */
try {
/*@egen*/
Property() Expression()/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Property() : {/*@bgen(jjtree) Property */
SimpleNode jjtn000 = new SimpleNode(JJTPROPERTY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Property */
try {
/*@egen*/
/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Expression() : {/*@bgen(jjtree) Expression */
SimpleNode jjtn000 = new SimpleNode(JJTEXPRESSION);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Expression */
try {
/*@egen*/
( | | | | | | |
JavaCode())/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void JavaCode() : {/*@bgen(jjtree) JavaCode */
SimpleNode jjtn000 = new SimpleNode(JJTJAVACODE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) JavaCode */
try {
/*@egen*/
/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}
void Identifier() : {/*@bgen(jjtree) Identifier */
SimpleNode jjtn000 = new SimpleNode(JJTIDENTIFIER);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
jjtreeOpenNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Identifier */
try {
/*@egen*/
/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
jjtreeCloseNodeScope(jjtn000);
}
}
/*@egen*/
}