xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/JFlexLexer.java (revision 5d9f3aa0ca3da3a714233f987fa732f62c0965f6)
1b5840353SAdam Hornáček /*
2b5840353SAdam Hornáček  * CDDL HEADER START
3b5840353SAdam Hornáček  *
4b5840353SAdam Hornáček  * The contents of this file are subject to the terms of the
5b5840353SAdam Hornáček  * Common Development and Distribution License (the "License").
6b5840353SAdam Hornáček  * You may not use this file except in compliance with the License.
7b5840353SAdam Hornáček  *
8b5840353SAdam Hornáček  * See LICENSE.txt included in this distribution for the specific
9b5840353SAdam Hornáček  * language governing permissions and limitations under the License.
10b5840353SAdam Hornáček  *
11b5840353SAdam Hornáček  * When distributing Covered Code, include this CDDL HEADER in each
12b5840353SAdam Hornáček  * file and include the License file at LICENSE.txt.
13b5840353SAdam Hornáček  * If applicable, add the following below this CDDL HEADER, with the
14b5840353SAdam Hornáček  * fields enclosed by brackets "[]" replaced with your own identifying
15b5840353SAdam Hornáček  * information: Portions Copyright [yyyy] [name of copyright owner]
16b5840353SAdam Hornáček  *
17b5840353SAdam Hornáček  * CDDL HEADER END
18b5840353SAdam Hornáček  */
19b5840353SAdam Hornáček 
20b5840353SAdam Hornáček /*
21b5840353SAdam Hornáček  * Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
22b5840353SAdam Hornáček  */
239805b761SAdam Hornáček package org.opengrok.indexer.analysis;
24b5840353SAdam Hornáček 
25b5840353SAdam Hornáček import java.io.IOException;
26b5840353SAdam Hornáček import java.io.Reader;
27b5840353SAdam Hornáček 
28b5840353SAdam Hornáček /**
29b5840353SAdam Hornáček  * Represents an API for lexers created by JFlex for {@code %type int}.
30b5840353SAdam Hornáček  * <p>http://jflex.de
31b5840353SAdam Hornáček  */
32b5840353SAdam Hornáček public interface JFlexLexer {
33b5840353SAdam Hornáček 
34b5840353SAdam Hornáček     /**
35b5840353SAdam Hornáček      * Gets the matched input text as documented by JFlex.
36b5840353SAdam Hornáček      * @return "the matched input text region"
37b5840353SAdam Hornáček      */
yytext()38b5840353SAdam Hornáček     String yytext();
39b5840353SAdam Hornáček 
40b5840353SAdam Hornáček     /**
41b5840353SAdam Hornáček      * Gets the matched input text length as documented by JFlex.
42b5840353SAdam Hornáček      * @return "the length of the matched input text region (does not require a
43b5840353SAdam Hornáček      * String object to be created)"
44b5840353SAdam Hornáček      */
yylength()45b5840353SAdam Hornáček     int yylength();
46b5840353SAdam Hornáček 
47b5840353SAdam Hornáček     /**
48b5840353SAdam Hornáček      * Gets a character from the matched input text as documented by JFlex.
49b5840353SAdam Hornáček      * @param pos "a value from 0 to {@link #yylength()}-1"
50b5840353SAdam Hornáček      * @return "the character at position {@code pos} from the matched text. It
51b5840353SAdam Hornáček      * is equivalent to {@link #yytext()} then {@link String#charAt(int)} --
52b5840353SAdam Hornáček      * but faster."
53b5840353SAdam Hornáček      */
yycharat(int pos)54b5840353SAdam Hornáček     char yycharat(int pos);
55b5840353SAdam Hornáček 
56b5840353SAdam Hornáček     /**
57*ff44f24aSAdam Hornáček      * Closes the input stream [as documented by JFlex]. All subsequent calls
58*ff44f24aSAdam Hornáček      * to the scanning method will return the end of file value.
59b5840353SAdam Hornáček      * @throws IOException if an error occurs while closing
60b5840353SAdam Hornáček      */
yyclose()61b5840353SAdam Hornáček     void yyclose() throws IOException;
62b5840353SAdam Hornáček 
63b5840353SAdam Hornáček     /**
64*ff44f24aSAdam Hornáček      * Closes the current input stream [as documented by JFlex], and resets
65*ff44f24aSAdam Hornáček      * the scanner to read from a new Reader.
66b5840353SAdam Hornáček      * @param reader the new reader
67b5840353SAdam Hornáček      */
yyreset(Reader reader)68b5840353SAdam Hornáček     void yyreset(Reader reader);
69b5840353SAdam Hornáček 
70b5840353SAdam Hornáček     /**
71b5840353SAdam Hornáček      * Gets the current lexical state as documented by JFlex.
72b5840353SAdam Hornáček      * @return "the current lexical state of the scanner."
73b5840353SAdam Hornáček      */
yystate()74b5840353SAdam Hornáček     int yystate();
75b5840353SAdam Hornáček 
76b5840353SAdam Hornáček     /**
77*ff44f24aSAdam Hornáček      * Enters the lexical state {@code lexicalState} [as documented by JFlex].
78b5840353SAdam Hornáček      * @param lexicalState the new state
79b5840353SAdam Hornáček      */
yybegin(int lexicalState)80b5840353SAdam Hornáček     void yybegin(int lexicalState);
81b5840353SAdam Hornáček 
82b5840353SAdam Hornáček     /**
83b5840353SAdam Hornáček      * "Pushes {@code number} characters of the matched text back into the
84b5840353SAdam Hornáček      * input stream [as documented by JFlex].
85b5840353SAdam Hornáček      * <p>[The characters] will be read again in the next call of the scanning
86b5840353SAdam Hornáček      * method.
87b5840353SAdam Hornáček      * <p>The number of characters to be read again must not be greater than
88b5840353SAdam Hornáček      * the length of the matched text. The pushed back characters will not be
89b5840353SAdam Hornáček      * included in {@link #yylength()} and {@link #yytext()}."
90b5840353SAdam Hornáček      * @param number the [constrained] number of characters
91b5840353SAdam Hornáček      */
yypushback(int number)92b5840353SAdam Hornáček     void yypushback(int number);
93b5840353SAdam Hornáček 
94b5840353SAdam Hornáček     /**
95b5840353SAdam Hornáček      * "Runs the scanner [as documented by JFlex].
96b5840353SAdam Hornáček      * <p>[The method] can be used to get the next token from the input."
97b5840353SAdam Hornáček      * <p>"Consume[s] input until one of the expressions in the specification
98b5840353SAdam Hornáček      * is matched or an error occurs."
99b5840353SAdam Hornáček      * @return a value returned by the lexer specification if defined or the
100b5840353SAdam Hornáček      * {@code EOF} value upon reading end-of-file
101b5840353SAdam Hornáček      * @throws IOException if an error occurs reading the input
102b5840353SAdam Hornáček      */
yylex()103b5840353SAdam Hornáček     int yylex() throws IOException;
104b5840353SAdam Hornáček }
105