View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2004 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.millscript.syntax;
22  
23  import org.millscript.millscript.expr.Expr;
24  import org.millscript.millscript.expr.NameExpr;
25  
26  /**
27   * This defines the MillScript parser interface.
28   */
29  public interface Parser extends Tokenizer {
30  
31      /**
32       * Constant value for low precedence.
33       */
34      int LOW_PREC = 10000;
35  
36      /**
37       * Constant value for comma precedence.
38       */
39      int COMMA_PREC = 20000;
40  
41      /**
42       * Constant value for slightly tighter than comma precedence. This would be
43       * used to read up to the next comma precedence item.
44       */
45      int COMMA_PREC1 = COMMA_PREC + 1;
46  
47      /**
48       * Constant value for relation operator precedence.
49       */
50      int RELOP_PREC = 30000;
51  
52      /**
53       * Constant value for not syntax precedence.
54       */
55      int NOT_PREC = RELOP_PREC;
56  
57      /**
58       * Constant value for arithmetic precedence.
59       */
60      int ARITH_PREC = 40000;
61  
62      /**
63       * Constant value for tight precedence.
64       */
65      int TIGHT_PREC = 50000;
66  
67      /**
68       * Returns the enclosing class for this parser.
69       *
70       * @return  a NameExpr for the enclosing class
71       */
72      NameExpr getEnclosingClass();
73  
74      /**
75       * Returns the current string, as an application of the format function
76       * with the current interpolation map values as arguments. The values in
77       * the interpolation map will be parsed into expressions.
78       *
79       * @return  an ApplyExpr, applying the format function to format the current
80       * string
81       * @see TokenizerImpl#interpolationMap
82       * @see org.millscript.millscript.functions.FormatFunction
83       */
84      Expr makeInterpolatedExpr();
85  
86      /**
87       * Reads the next token from the source as an attribute name and returns
88       * it. An alert will be generated if the next token is not a name.
89       *
90       * @return  a String containing a tag name
91       */
92      String readAttributeName();
93  
94      /**
95       * Reads a sequence of expressions from the source as a Block.
96       *
97       * @return  a Block wrapping the sequence of expressions read
98       * @see #readStmnts()
99       */
100     Expr readBlock();
101 
102     /**
103      * Reads a sequence of expressions, followed by the specified symbol, from
104      * the source as a Block.
105      *
106      * @param sym   the symbol which must follow the block
107      * @return  a Block wrapping the sequence of expressions read
108      * @see #readStmntsTo(String)
109      */
110     Expr readBlockTo( final String sym );
111 
112     /**
113      * Reads the next expression from the source.
114      *
115      * @return  an Expr for the next token in the source
116      */
117     Expr readExpr();
118 
119     /**
120      * Reads the next expression from the source at the
121      * <code>COMMA_PREC1</code> precedence level. Hence this will read up to
122      * the next comma.
123      *
124      * @return  an Expr for the next token in the source
125      */
126     Expr readExprComma();
127 
128     /**
129      * Reads the next expression from the source at the specified precedence
130      * level.
131      *
132      * @param prec  the precedence level to read the next expression at
133      * @return  an Expr for the next token in the source
134      */
135     Expr readExprPrec( final int prec );
136 
137     /**
138      * Reads the next expression from the source, which must be followed by the
139      * specified symbol.
140      *
141      * @param sym   the symbol which must follow the expression
142      * @return  an Expr for the next token in the source
143      */
144     Expr readExprTo( final String sym );
145 
146     /**
147      * Reads the next token from the source as a name and returns a name
148      * expression for it. A name is a symbol that is not a keyword. An alert
149      * will be generated if the next token is a built in identifier.
150      *
151      * @return  a NameExpr for the next token
152      */
153     NameExpr readName();
154 
155     /**
156      * Reads the optional next expression from the source. Optional means that
157      * there doesn't have to be another expression in the source.
158      *
159      * @return  an Expr for the next token in the source
160      */
161     Expr readOptExpr();
162 
163     /**
164      * Reads the optional next expression from the source at the specified
165      * precedence level. Optional means that there doesn't have to be another
166      * expression in the source.
167      *
168      * @param prec  the precedence level to read the next expression at
169      * @return  an Expr for the next token in the source
170      */
171     Expr readOptExprPrec( final int prec );
172 
173     /**
174      * Reads the next token from the source as the optional primary expression
175      * in a potential sequence of expressions.
176      *
177      * @return  an Expr for the next token in the source
178      */
179     Expr readOptPrimary();
180 
181     /**
182      * Reads the next token from the source as the primary expression in a
183      * potential sequence of expressions.
184      *
185      * @return  an Expr for the next token in the source
186      */
187     Expr readPrimary();
188 
189     /**
190      * Reads a sequence of expressions from the source. The sequence of
191      * expressions are wrapped as a comma expression. This method will read up
192      * to the end of file, or a built-in keyword.
193      *
194      * @return  an Expr for the sequence of expressions read
195      */
196     Expr readStmnts();
197 
198     /**
199      * Reads a sequence of expressions from the source, which must be followed
200      * by the specified symbol.
201      *
202      * @param sym   the symbol which must follow the statements
203      * @return  an Expr for the sequence of expressions read
204      * @see #readStmnts()
205      */
206     Expr readStmntsTo( final String sym );
207 
208     /**
209      * Reads the next token from the source as a symbol and returns it. An
210      * alert will be generated if the next token is not a name.
211      *
212      * @return  a String containing the next symbol
213      */
214     String readSymbol();
215 
216     /**
217      * Reads the next token from the source as a tag name and returns it. An
218      * alert will be generated if the next token is not a name.
219      *
220      * @return  a String containing a tag name
221      */
222     String readTagName();
223 
224 }