KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > eclipse > editors > InterpolationRule


1 /*
2  * Copyright (c) 2003 The Visigoth Software Society. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowledgement:
19  * "This product includes software developed by the
20  * Visigoth Software Society (http://www.visigoths.org/)."
21  * Alternately, this acknowledgement may appear in the software
22  * itself, if and wherever such third-party acknowledgements
23  * normally appear.
24  *
25  * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names
26  * of the project contributors may be used to endorse or promote
27  * products derived from this software without prior written
28  * permission. For written permission, please contact
29  * visigoths@visigoths.org.
30  *
31  * 5. Products derived from this software may not be called
32  * "FreeMarker" or "Visigoth" nor may "FreeMarker" or "Visigoth"
33  * appear in their names without prior written permission of the
34  * Visigoth Software Society.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Visigoth Software Society. For more
52  * information on the Visigoth Software Society, please see
53  * http://www.visigoths.org/
54  */

55
56 package freemarker.eclipse.editors;
57
58 import org.eclipse.jface.text.rules.ICharacterScanner;
59 import org.eclipse.jface.text.rules.IToken;
60 import org.eclipse.jface.text.rules.PatternRule;
61 import org.eclipse.jface.text.rules.Token;
62
63 /**
64  * A FreeMarker interpolation rule. Although this rule extends the
65  * PatterRule class, it correctly handles both the interpolation
66  * starting character sequences (i.e. "${" and "#{"), as well as
67  * quoted strings inside the interpolations.
68  *
69  * @author <a HREF="mailto:per&#64;percederberg.net">Per Cederberg</a>
70  * @version $Id: InterpolationRule.java,v 1.2 2003/11/30 22:22:04 cederberg Exp $
71  */

72 public class InterpolationRule extends PatternRule {
73
74     /**
75      * Creates a new FreeMarker interpolation rule.
76      *
77      * @param token the token to use for this rule
78      */

79     public InterpolationRule(IToken token) {
80         super("${", "}", token, (char) 0, false);
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.jface.text.rules.PatternRule#doEvaluate(org.eclipse.jface.text.rules.ICharacterScanner, boolean)
85      */

86     protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
87         if (!resume && !FreemarkerTools.readInterpolationStart(scanner)) {
88             return Token.UNDEFINED;
89         }
90         FreemarkerTools.readInterpolationEnd(scanner);
91         return fToken;
92     }
93 }
94
Popular Tags