Skip to content

Method: getFirstPosition()

1: package de.fhdw.wtf.dsl.scanner.modelScanner.state;
2:
3: import de.fhdw.wtf.common.stream.TokenStream;
4: import de.fhdw.wtf.common.token.Position;
5: import de.fhdw.wtf.dsl.scanner.common.ScannerState;
6:
7: /**
8: * State for processing multi-char elements.
9: */
10: public abstract class MultiCharState implements ScannerState {
11:         
12:         /**
13:          * Beginning characters which have not been reflected in a token.
14:          */
15:         private String currentInput;
16:         
17:         /**
18:          * Position of the first input character in the original input stream.
19:          */
20:         private final Position firstPosition;
21:         
22:         /**
23:          * Constructor.
24:          *
25:          * @param currentInput
26:          * initial input.
27:          * @param firstPosition
28:          * of the first char.
29:          */
30:         protected MultiCharState(final String currentInput, final Position firstPosition) {
31:                 this.setCurrentInput(currentInput);
32:                 this.firstPosition = firstPosition;
33:         }
34:         
35:         @Override
36:         public void process(final char input, final TokenStream outputStream, final Position position) {
37:                 this.append(input);
38:         }
39:         
40:         /**
41:          * Appends input at the end of the {@link MultiCharState#currentInput}.
42:          *
43:          * @param input
44:          * character to be appended to the currentInput field
45:          */
46:         protected void append(final char input) {
47:                 this.setCurrentInput(this.getCurrentInput() + input);
48:         }
49:         
50:         /**
51:          * Setter for {@link MultiCharState#currentInput}.
52:          *
53:          * @param newCurrentInput
54:          * new value of currentInput
55:          */
56:         protected void setCurrentInput(final String newCurrentInput) {
57:                 this.currentInput = newCurrentInput;
58:         }
59:         
60:         /**
61:          * Getter for {@link MultiCharState#currentInput}<br>
62:          * witch holds the by now processed <code>String</code>.
63:          *
64:          * @return {@link MultiCharState#currentInput}
65:          */
66:         protected String getCurrentInput() {
67:                 return this.currentInput;
68:         }
69:         
70:         /**
71:          * Getter for the position of the first character scanned by this state.
72:          *
73:          * @return first character position
74:          */
75:         public Position getFirstPosition() {
76:                 return this.firstPosition;
77:         }
78: }