001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.base;
016    
017    import java.util.List;
018    
019    /**
020     * This interface describes an incremental parser capable of predicting the possible next tokens.
021     * 
022     * @author Tobias Kuhn
023     */
024    public interface PredictiveParser {
025    
026            /**
027             * Adds the token to the end of the token sequence.
028             * 
029             * @param token The new token to be added.
030             */
031            public void addToken(String token);
032    
033            /**
034             * Adds the tokens to the token list.
035             * 
036             * @param tokens The tokens to be added.
037             */
038            public void addTokens(List<String> tokens);
039    
040            /**
041             * Removes the last token.
042             */
043            public void removeToken();
044    
045            /**
046             * Removes all tokens in the current token sequence.
047             */
048            public void removeAllTokens();
049    
050            /**
051             * Sets the given tokens. Existing tokens are removed.
052             * 
053             * @param tokens The tokens.
054             */
055            public void setTokens(List<String> tokens);
056    
057            /**
058             * Returns the current token sequence.
059             * 
060             * @return The current token sequence.
061             */
062            public List<String> getTokens();
063    
064            /**
065             * Returns the number of tokens of the current (partial) text.
066             * 
067             * @return The number of tokens.
068             */
069            public int getTokenCount();
070    
071            /**
072             * This method returns the options for the next token to be added at the end.
073             * 
074             * @return The options describing the possible next tokens.
075             */
076            public NextTokenOptions getNextTokenOptions();
077    
078            /**
079             * Returns whether the given token is a possible next token.
080             * 
081             * @param token The token.
082             * @return true if the token is a possible next token.
083             */
084            public boolean isPossibleNextToken(String token);
085    
086            /**
087             * Returns true if the current token sequence is a complete statement.
088             * 
089             * @return true if the current token sequence is complete.
090             */
091            public boolean isComplete();
092            
093            /**
094             * This method should return the token number to which the last token refers, if it is a
095             * reference like "it". -1 should be returned if the last token is not a reference, or if
096             * reference resolution is not implemented.
097             * 
098             * @return The token number to which the last token refers.
099             */
100            public int getReference();
101    
102    }