org.nuiton.jaxx.compiler.css.parser.CSS.jjt Maven / Gradle / Ivy
/*
* 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";
NODE_SCOPE_HOOK = true;
}
PARSER_BEGIN(CSSParser)
package jaxx.css;
public class CSSParser {
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() : {}
{
(Rule())*
{ return jjtThis; }
}
void Rule() : {}
{
Selectors()
Declaration() (";" (Declaration())?)*
}
void Selectors() : {}
{
Selector() ("," Selector())*
}
void Selector() : {}
{
JavaClass() (Id())? (Class())? (PseudoClass())?
|
Id() (Class())? (PseudoClass())?
|
Class() (PseudoClass())?
|
PseudoClass()
}
void JavaClass() : {}
{
| "*"
}
void Id() : {}
{
"#"
}
void Class() : {}
{
"."
}
void PseudoClass() : {}
{
( | ) (AnimationProperties())?
}
void AnimationProperties() : {}
{
"[" AnimationProperty() ("," AnimationProperty())* "]"
}
void AnimationProperty() : {}
{
"=" ()?
}
void Declaration() : {}
{
Property() Expression()
}
void Property() : {}
{
}
void Expression() : {}
{
( | | | | | | |
JavaCode())
}
void JavaCode() : {}
{
}
void Identifier() : {}
{
}