Skip to content

Method: getInputMatcher()

1: package de.fhdw.wtf.dsl.scanner.common;
2:
3: import de.fhdw.wtf.common.token.Position;
4:
5: /**
6: * Represents a transition in the {@link Scanner} "Automata". The transition is defined by given "from"
7: * {@link StateMatcher}, {@link InputMatcher} and some rules for the target {@link ScannerState} witch will be
8: * implemented by subclasses.
9: *
10: * <h2>Example:</h2> Any state that matches the "from" {@link StateMatcher} := f<br>
11: * Any input that matches the {@link InputMatcher} := i<br>
12: * target state := t<br>
13: * <br>
14: * <b>f - i -> t</b>
15: */
16: public abstract class Delta {
17:         
18:         private final StateMatcher fromStateMatcher;
19:         private final InputMatcher inputMatcher;
20:         
21:         /**
22:          * Constructor for {@link Delta}s.
23:          *
24:          * @param fromStateMatcher
25:          * : original state
26:          * @param inputMatcher
27:          */
28:         protected Delta(final StateMatcher fromStateMatcher, final InputMatcher inputMatcher) {
29:                 this.fromStateMatcher = fromStateMatcher;
30:                 this.inputMatcher = inputMatcher;
31:         }
32:         
33:         private StateMatcher getFromStateMatcher() {
34:                 return this.fromStateMatcher;
35:         }
36:         
37:         private InputMatcher getInputMatcher() {
38:                 return this.inputMatcher;
39:         }
40:         
41:         /**
42:          * Tests if the given combination of current {@link ScannerState} and input {@link Character} matches this
43:          * {@link Delta}.
44:          *
45:          * @param currentState
46:          * the current State of the {@link Scanner}
47:          * @param input
48:          * the input to be tested
49:          * @return the matching result
50:          */
51:         public boolean match(final ScannerState currentState, final Character input) {
52:                 return this.getFromStateMatcher().match(currentState) && this.getInputMatcher().match(input);
53:         }
54:         
55:         /**
56:          * Returns the next {@link ScannerState} by using this {@link Delta}.
57:          *
58:          * @param position
59:          * start position of the new {@link ScannerState}
60:          * @param currentState
61:          * the current {@link ScannerState}
62:          * @return the next {@link ScannerState}
63:          */
64:         public abstract ScannerState getNextScannerState(Position position, ScannerState currentState);
65: }