f1a71f62ab871533d9f4651d1352f0fc9181978f
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / text / SmartyTagRule.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: SmartyTagRule.java,v 1.1 2004-09-02 18:25:04 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpdt.smarty.ui.internal.text;
15
16 import org.eclipse.jface.text.rules.ICharacterScanner;
17 import org.eclipse.jface.text.rules.IRule;
18 import org.eclipse.jface.text.rules.IToken;
19 import org.eclipse.jface.text.rules.Token;
20
21 /**
22  * Rule detecting XML tag brackets and name.
23  * 
24  * @author Igor Malinin
25  */
26 public class SmartyTagRule implements IRule {
27
28   private IToken token;
29
30   public SmartyTagRule(IToken token) {
31     this.token = token;
32   }
33
34   public IToken evaluate(ICharacterScanner scanner) {
35     int ch = scanner.read();
36     if (ch == '}') {
37       return token;
38     }
39     if (ch == '/') {
40       ch = scanner.read();
41       if (ch == '}') {
42         return token;
43       }
44
45       scanner.unread();
46       scanner.unread();
47       return Token.UNDEFINED;
48     }
49     if (ch == '{') {
50       ch = scanner.read();
51       if (ch == '/') {
52         ch = scanner.read();
53       }
54       loop: while (true) {
55         switch (ch) {
56         case ICharacterScanner.EOF:
57         case 0x09:
58         case 0x0A:
59         case 0x0D:
60         case 0x20:
61           scanner.unread();
62           break loop;
63         case '}':
64           break loop;
65         }
66
67         ch = scanner.read();
68       }
69       return token;
70     }
71     scanner.unread();
72     return Token.UNDEFINED;
73   }
74 }