01: /*
02: *******************************************************************************
03: * Copyright (C) 2002-2004, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: *******************************************************************************
06: */
07: package com.ibm.icu.dev.tool.localeconverter;
08:
09: import java.io.*;
10:
11: public class QuoteTransition extends ComplexTransition {
12: public static final QuoteTransition GLOBAL = new QuoteTransition(
13: SUCCESS);
14:
15: public static final char STRING_CHAR = '"';
16:
17: public QuoteTransition(int success) {
18: super (success);
19: //{{INIT_CONTROLS
20: //}}
21: }
22:
23: public boolean accepts(int c) {
24: return STRING_CHAR == (char) c;
25: }
26:
27: protected Lex.Transition[][] getStates() {
28: return states;
29: }
30:
31: private static final Lex.Transition[][] states = { { //state 0:
32: new Lex.CharTransition(STRING_CHAR,
33: Lex.IGNORE_CONSUME, -1),
34: new Lex.ParseExceptionTransition(
35: "illegal character in quoted string") }, { //state 1:
36: new Lex.CharTransition(STRING_CHAR,
37: Lex.IGNORE_CONSUME, SUCCESS),
38: new Lex.StringTransition(EOLTransition.EOL_CHARS,
39: Lex.IGNORE_CONSUME, -2),
40: new EscapeTransition(-1),
41: new SymbolTransition(-1),
42: new Lex.EOFTransition(-2),
43: new Lex.DefaultTransition(Lex.ACCUMULATE_CONSUME,
44: -1) }, { //state 2: failure from eof
45: new Lex.ParseExceptionTransition("unterminated string") } };
46:
47: public static void main(String args[]) {
48: try {
49: Lex.Transition[][] states = { {
50: new QuoteTransition(SUCCESS),
51: new Lex.EOFTransition(),
52: new Lex.ParseExceptionTransition("bad test input") } };
53: EscapeTransition.setEscapeChar('/');
54: String text = "\"hello<\"/>>/d32world\"\"<one>/\n<two>\"";
55: StringReader sr = new StringReader(text);
56: PushbackReader pr = new PushbackReader(sr);
57: Lex parser = new Lex(states, pr);
58: //parser.debug(true);
59: int s = parser.nextToken();
60: while (s == SUCCESS) {
61: System.out.println(parser.getData());
62: s = parser.nextToken();
63: }
64: } catch (Exception e) {
65: System.out.println(e);
66: }
67: }
68: //{{DECLARE_CONTROLS
69: //}}
70: }
|