01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.css.lex;
15:
16: import org.itsnat.core.ItsNatException;
17: import java.util.Iterator;
18: import java.util.List;
19:
20: /**
21: *
22: * @author jmarranz
23: */
24: public abstract class Block extends Token {
25: protected SourceCode content;
26:
27: /** Creates a new instance of Block */
28: public Block(String code, Cursor cursor) {
29: super (cursor.getPos()); // apunta al caracter de comienzo del bloque
30: parse(code, cursor);
31: }
32:
33: public void parse(String code, Cursor cursor) {
34: // cursor apunta al caracter de comienzo del bloque
35: cursor.inc(); // interior del bloque
36: char endChar = getEndBlockChar();
37: List tokens = Token.parse(code, cursor, true, endChar);
38:
39: int end = cursor.getPos();
40: if (end >= code.length())
41: throw new ItsNatException("Missing matching " + endChar
42: + " start pos: " + start + " code: \"" + code
43: + "\"");
44:
45: this .end = end; // apunta al caracter de final del bloque
46: this .content = new SourceCode(tokens);
47: }
48:
49: public abstract char getBeginBlockChar();
50:
51: public abstract char getEndBlockChar();
52:
53: public String toString() {
54: return "(" + content.toString() + ")";
55: }
56:
57: public SourceCode getContent() {
58: return content;
59: }
60: }
|