001 
002 /*
003  *  Descripter 1.0 - Java Script Engines
004  *  Copyright (C) 2010-2015  Jianjun Liu (J.J.Liu)
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 options {
021     BUILD_NODE_FILES = true;
022     FORCE_LA_CHECK = false;
023     JDK_VERSION = "1.6";
024     JAVA_UNICODE_ESCAPE = true;
025     UNICODE_INPUT = true;
026     MULTI = true;
027     NODE_CLASS = "AbstractNode";
028     NODE_DEFAULT_VOID = true;
029     NODE_PACKAGE = "org.descripter.js.ss.parse";
030     NODE_PREFIX = "JSSP";
031     NODE_SCOPE_HOOK = true;
032     NODE_USES_PARSER = true;
033     STATIC = false;
034     VISITOR = true;
035     VISITOR_DATA_TYPE = "Object";
036     VISITOR_RETURN_TYPE = "Object";
037     VISITOR_EXCEPTION = "";
038 }
039 
040 PARSER_BEGIN(JSSPParser)
041 
042 package org.descripter.js.ss.parse;
043 
044 public class JSSPParser
045 {
046     void jjtreeOpenNodeScope(Node n) {
047         ((AbstractNode)n).firstToken = getToken(1);
048     }
049 
050     void jjtreeCloseNodeScope(Node n) {
051         ((AbstractNode)n).lastToken = getToken(0);
052     }
053 }
054 PARSER_END(JSSPParser)
055 
056 SPECIAL_TOKEN :
057 {
058     < LF: "\n" >     /* Line Feed */
059 |   < CR: "\r" >     /* Carriage Return */
060 |   < LS: "\u2028" > /* Line separator */
061 |   < PS: "\u2029" > /* Paragraph separator */
062 }
063 
064 MORE [IGNORE_CASE] :
065 {
066     "<%" : IN_SCRIPT
067 |   "\"" : IN_DOUBLE_STRING
068 |   "\'" : IN_SINGLE_STRING
069 }
070 
071 <IN_SCRIPT> TOKEN :
072 {
073     <SCRIPT: "%>" > : DEFAULT
074 }
075 
076 <IN_DOUBLE_STRING> TOKEN :
077 {
078     <DOUBLE_STRING: "\"" > : DEFAULT
079 }
080 
081 <IN_SINGLE_STRING> TOKEN :
082 {
083     <SINGLE_STRING: "\'" > : DEFAULT
084 }
085 
086 <DEFAULT> TOKEN :
087 {
088     <HTML:
089         (
090                  ~["<","\"","\'","\n","\r","\u2028","\u2029"]
091         |   ("<" ~["%","\"","\'","\n","\r","\u2028","\u2029"])
092         )*
093     > : DEFAULT
094 }
095 
096 <IN_DOUBLE_STRING,IN_SINGLE_STRING,IN_SCRIPT,DEFAULT> MORE :
097 {
098     < ~[] >
099 }
100 
101 JSSPPage Page() #Page :
102 {}
103 {
104   (
105     Script() | Html()
106   )*
107   < EOF >
108   {
109     return jjtThis;
110   }
111 }
112 
113 void Script() #Script :
114 {
115     Token t;
116 }
117 {
118 (
119     t = < SCRIPT >
120 )   {
121         jjtThis.jjtSetValue(t.image.substring(2, t.image.length() - 2));
122     }
123 }
124 
125 void Html() #Html :
126 {
127     Token t;
128 }
129 {
130 (
131         t = < DOUBLE_STRING >
132     |   t = < SINGLE_STRING >
133     |   t = < HTML >
134 )   {
135         jjtThis.jjtSetValue(t.image);
136     }
137 }
138