11package fish .cichlidmc .tinyjson .parser .util ;
22
3- import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .CARRIAGE_RETURN ;
4- import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .EOF ;
5- import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .LINE_BREAK ;
3+ import fish .cichlidmc .tinyjson .JsonException ;
4+ import org .jspecify .annotations .Nullable ;
65
76import java .io .IOException ;
87import java .io .PushbackReader ;
98import java .io .Reader ;
109import java .util .Arrays ;
1110import java .util .function .Function ;
1211
13- import fish .cichlidmc .tinyjson .JsonException ;
12+ import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .CARRIAGE_RETURN ;
13+ import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .EOF ;
14+ import static fish .cichlidmc .tinyjson .parser .util .ParserUtils .LINE_BREAK ;
1415
1516public final class ParseInput {
1617 private final PushbackReader reader ;
1718
1819 private int line = 1 ;
1920 private int col = 1 ;
2021
21- // Nullable
22+ @ Nullable
2223 private CommentState commentState ;
2324
2425 public ParseInput (Reader reader ) {
2526 this .reader = new PushbackReader (reader , 64 );
2627 }
2728
28- /**
29- * Read the next character, incrementing the parser location. Throws if the end of input is reached.
30- * Line breaks are unified into \n.
31- */
29+ /// Read the next character, incrementing the parser location. Throws if the end of input is reached.
30+ /// Line breaks are unified into \n.
3231 public char next () throws IOException {
3332 char next = this .read ();
3433 if (next == CARRIAGE_RETURN && this .peek () == LINE_BREAK ) {
@@ -53,9 +52,7 @@ private void nextLine() {
5352 this .col = 1 ;
5453 }
5554
56- /**
57- * Skip past all whitespace at the start of the input, including comments.
58- */
55+ /// Skip past all whitespace at the start of the input, including comments.
5956 public void skipWhitespace () throws IOException {
6057 while (true ) {
6158 int next = this .peek ();
@@ -118,17 +115,13 @@ public void skipWhitespace() throws IOException {
118115 }
119116 }
120117
121- /**
122- * Read the next non-whitespace character, throwing if EOF is reached.
123- */
118+ /// Read the next non-whitespace character, throwing if EOF is reached.
124119 public char peekNonWhitespace () throws IOException {
125120 this .skipWhitespace ();
126121 return this .peekOrThrow ();
127122 }
128123
129- /**
130- * Read the next N characters into an array, throwing if EOF is reached.
131- */
124+ /// Read the next N characters into an array, throwing if EOF is reached.
132125 public char [] next (int n ) throws IOException {
133126 char [] array = new char [n ];
134127 for (int i = 0 ; i < n ; i ++) {
@@ -137,9 +130,7 @@ public char[] next(int n) throws IOException {
137130 return array ;
138131 }
139132
140- /**
141- * Read the next character without consuming it. May be EOF.
142- */
133+ /// Read the next character without consuming it. May be EOF.
143134 public int peek () throws IOException {
144135 int next = this .tryRead ();
145136 if (next != EOF ) {
@@ -148,18 +139,14 @@ public int peek() throws IOException {
148139 return next ;
149140 }
150141
151- /**
152- * Read the next character without consuming it, throwing if it's EOF.
153- */
142+ /// Read the next character without consuming it, throwing if it's EOF.
154143 public char peekOrThrow () throws IOException {
155144 char next = this .read ();
156145 this .reader .unread (next );
157146 return next ;
158147 }
159148
160- /**
161- * Peek the next N characters into an array. May be shorter than expected due to EOF.
162- */
149+ /// Peek the next N characters into an array. May be shorter than expected due to EOF.
163150 public char [] peek (int n ) throws IOException {
164151 char [] chars = new char [n ];
165152 for (int i = 0 ; i < n ; i ++) {
@@ -178,9 +165,7 @@ public char[] peek(int n) throws IOException {
178165 return chars ;
179166 }
180167
181- /**
182- * Try to read the next character. May be EOF.
183- */
168+ /// Try to read the next character. May be EOF.
184169 public int tryRead () throws IOException {
185170 return this .reader .read ();
186171 }
@@ -189,17 +174,13 @@ public Position pos() {
189174 return new Position (this .line , this .col );
190175 }
191176
192- /**
193- * Return a new JsonException to be thrown. Message may contain
194- * "${pos}" as a placeholder for the current input position.
195- */
177+ /// Return a new JsonException to be thrown. Message may contain
178+ /// "${pos}" as a placeholder for the current input position.
196179 public JsonException error (Function <Position , String > messageFactory ) {
197180 return new JsonException (messageFactory .apply (this .pos ()));
198181 }
199182
200- /**
201- * Shortcut for error that just adds 'at ${pos}' to the end.
202- */
183+ /// Shortcut for error that just adds 'at ${pos}' to the end.
203184 public JsonException errorAt (String message ) {
204185 return this .error (pos -> message + " at " + pos );
205186 }
0 commit comments