libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_scanner.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblScanner, generic text tokenizer and lexer
3 * \ingroup utils
4 *
5 * The main operation is to set the delimeter pattern (regex, powered by the
6 * TinyCRegex submodule), and then use GblScanner_peekToken() (and friends)
7 * to "view" the upcoming token without actually advancing the stream or do
8 * GblScanner_scanToken() (and friends) to take the next token and advance the
9 * buffer.
10 *
11 * This basically lets GblScanner operate with a one-token lookahead at all time.
12 * If you need to inspect more tokens than just that without modifying the buffer
13 * state, that's when you would use GblScanner_pushCursor() to save your state,
14 * then peek/scan, and when you need to back up and restore an old state,
15 * use GblScanner_popCursor().
16 *
17 * The main two operations are peek and scan, with their results being immediately
18 * stored in the public GblStringView variables GblScanner::next and GblScanner::token
19 * respectively. The variations of peek/scan are simply using GblStringView to handle
20 * type conversions for you, like GblScanner_scanUint32() for example, scans into
21 * GblScanner::token and then calls GblStringView_toUint32() on the token for you
22 * automatically.
23 *
24 * \todo
25 * - continue testing type-specific peek/scan functions
26 * - write own scanf() implementation that knows how
27 * many characters have been read
28 * - store GblPattern now instead of GblStringRef
29 * - peekPattern(), scanPattern()
30 *
31 * \author 2023 Falco Girgis
32 * \copyright MIT License
33 */
34#ifndef GIMBAL_SCANNER_H
35#define GIMBAL_SCANNER_H
36
37#include "../meta/instances/gimbal_object.h"
38#include "../strings/gimbal_pattern.h"
39#include "../meta/signals/gimbal_signal.h"
40
41/*! \name Type System
42 * \brief Type UUID and cast operators
43 * @{
44 */
45#define GBL_SCANNER_TYPE (GBL_TYPEID(GblScanner)) //!< Type UUID for GblScanner
46#define GBL_SCANNER(self) (GBL_CAST(GblScanner, self)) //!< Function-style cast for GblInstance
47#define GBL_SCANNER_CLASS(klass) (GBL_CLASS_CAST(GblScanner, klass)) //!< Function-style cast for GblClass
48#define GBL_SCANNER_GET_CLASS(self) (GBL_CLASSOF(GblScanner, self)) //!< Get a GblScannerClass from GblInstance
49//! @}
50
51//! Default delimeters used with GblScanner for tokenizing the input stream
52#define GBL_SCANNER_DELIMETERS_DEFAULT "[ \t\n\r]"
53
54#define GBL_SELF_TYPE GblScanner
55
57
59
60/*! \enum GBL_SCANNER_FLAGS
61 * \brief Extensible enum of flags used for GblScanner::status.
62 */
64 // Builtin Non-error state flags (bit 0)
65 GBL_SCANNER_OK = 0x00000000, //!< No errors present
66 GBL_SCANNER_EOF = 0x00000001, //!< End-of-file
67 // Builtin Error flags (bits 29-31)
68 GBL_SCANNER_SCAN_ERROR = 0x20000000, //!< Failed to scan the previous token
69 GBL_SCANNER_PEEK_ERROR = 0x40000000, //!< Failed to peek the previous token
70 GBL_SCANNER_SKIP_ERROR = 0x80000000, //!< Failed previous skip call
71 // User masks (bits 1-28)
72 GBL_SCANNER_USER_STATE = 0x00fffff2, //!< Mask of non-error user flags
73 GBL_SCANNER_USER_ERROR = 0x1f000000, //!< Mask of error user flags
74 // Masks for combined state and error flags
75 GBL_SCANNER_STATE = 0x00ffffff, //!< Mask of all scanner state flags
76 GBL_SCANNER_ERROR = 0xff000000, //!< Mask of all scanner error flags
77};
78
79//! Represents the current region of interest for a GblScanner
80typedef struct GblScannerCursor {
81 size_t position; //!< Current character position
82 size_t line; //!< Current line number
83 size_t column; //!< Current column number
84 size_t length; //!< Length of current region of interest
85} GblScannerCursor;
86
87/*! \struct GblScannerClass
88 * \extends GblObjectClass
89 * \brief GblClass VTable structure for GblScanner
90 *
91 * GblScannerClass provides a virtual function table for
92 * polymorphically overriding the tokenization logic.
93 *
94 * \sa GblScanner
95 */
96GBL_CLASS_DERIVE(GblScanner, GblObject)
97 //! Called every time the next token is to be extracted from the stream
98 GBL_RESULT (*pFnNextToken)(GBL_SELF, GblStringView* pToken);
100
101/*! \struct GblScanner
102 * \extends GblObject
103 * \ingroup utils
104 * \brief Generic text stream scanner object
105 *
106 * GblScanner offers a generic way to scan through a stream
107 * of text, parsing its contents into variables of any type
108 * supported by the type system.
109 *
110 * \sa GblScannerClass
111 */
113 GblStringView token; //!< Current token in the stream
114 GblStringView next; //!< Peeked-at next token in the stream
115 const GblStringRef* pError; //!< Pending error message
116 GBL_SCANNER_FLAGS status; //!< Status after the last operation
118
119//! \cond
120GBL_PROPERTIES(GblScanner,
121 (input, GBL_GENERIC, (READ, WRITE, CONSTRUCT), GBL_STRING_TYPE),
122 (delimeters, GBL_GENERIC, (READ, WRITE, CONSTRUCT), GBL_STRING_TYPE),
123 (token, GBL_GENERIC, (READ), GBL_STRING_TYPE),
124 (next, GBL_GENERIC, (READ), GBL_STRING_TYPE),
125 (status, GBL_GENERIC, (READ), GBL_FLAGS_TYPE),
126 (error, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE)
127)
128
129GBL_SIGNALS(GblScanner,
130 (reset, (GBL_INSTANCE_TYPE, pReceiver)),
131 (eof, (GBL_INSTANCE_TYPE, pReceiver)),
132 (peeked, (GBL_INSTANCE_TYPE, pReceiver)),
133 (scanned, (GBL_INSTANCE_TYPE, pReceiver)),
134 (raised, (GBL_INSTANCE_TYPE, pReceiver))
135)
136//! \endcond
137
138/*! \name Default Delimeters
139 * \brief Accessor methods for the default delimeter pattern
140 * \relatesalso GblScannerClass
141 * @{
142 */
143//! Returns a string reference to the current default delimeter pattern on the given class
147//! Sets the default delimeter pattern on the given class to a copy of \p pStr
149 (GBL_KLASS,
150 const char* pPattern) GBL_NOEXCEPT;
151//! Moves the given string reference to be owned by the given class as its delimeter pattern
153 (GBL_KLASS,
154 const GblStringRef* pPattern) GBL_NOEXCEPT;
155//! @}
156
157//! Returns the GblType UUID associated with GblScanner
159
160/*! \name Lifetime Management
161 * \brief Methods for managing GblScanner creation/destruction
162 * @{
163 */
164//! Creates and returns a new GblScanner, setting its input to the given string with optional length
165GBL_EXPORT GblScanner* GblScanner_create (const char* pStr,
166 size_t len/*=0*/) GBL_NOEXCEPT;
167//! Acquires a reference to the given scanner, incrementing its reference count and returning its address
169//! Releases a reference to the given scanner, returning the remaining count, and destroying the scanner when it hits 0
171//! @}
172
173/*! \name Input and Delimeters
174 * \brief Methods for setting input and delimeter pattern
175 * \relatesalso GblScanner
176 * @{
177 */
178//! Returns a string reference to the string current being used as the input stream
181//! Sets the input stream to the given string, optionally taking its size, and resetting the stream
183 const char* pStr,
184 size_t count/*=0*/) GBL_NOEXCEPT;
185//! Sets the input stream to given string reference, taking ownership of it, and resetting the sream
187 const GblStringRef* pRef) GBL_NOEXCEPT;
188//! Returns a reference to the string used as the delimeter regular expression pattern
191//! Sets the stream's delimeter regular expression pattern to \p pPattern
193 const char* pPattern) GBL_NOEXCEPT;
194//! @}
195
196/*! \name Errors
197 * \brief Methods for managing errors
198 * \relatesalso GblScanner
199 */
200//! Clears the pending error message string and any error flags which are set on the given scanner
202//! Raises an error, setting the given flags and message for the given scanner
204 GblFlags flags,
205 const char* pFmt,
206 ...) GBL_NOEXCEPT;
207//! @}
208
209/*! \name Stream
210 * \brief Methods for controlling the input stream
211 * \relatesalso GblScanner
212 * @{
213 */
214//! Resets the state of the input stream, moving the cursor back to the beginning
216//! Fetches the current position of the cursor into the input stream
218//! Moves the cursor's current stream position by the given positive or negative offset
220 int whence) GBL_NOEXCEPT;
221//! @}
222
223/*! \name Cursor
224 * \brief Methods for managing the stream cursor
225 * \relatesalso GblScanner
226 * @{
227 */
228//! Returns the top cursor on the stack, which maintains the current position into the input stream
229GBL_EXPORT const GblScannerCursor*
231//! Returns the depth of the cursor stack for the given scanner object
233//! Pushes the value of the current cursor onto the stack, saving its state
235//! Pops the value of the current cursor from the top of the stack, reloading its state
237//! @}
238
239/*! \name Scanning
240 * \brief Methods for scanning the next token
241 * \relatesalso GblScanner
242 * @{
243 */
244//! Scans the next token, storing it to GblScanner::token or returning GBL_FALSE upon failure
246//! Scans the next token to GblScanner::token if it matches the given pattern or returning GBL_FALSE upon failure
248//! \todo implement me: GblScanner_scanMatch() overload
250//! Scans the given number of lines to GblScanner::token or returns GBL_FALSE upon failure
252//! Scans the given number of bytes to GblScanner::token or returns GBL_FALSE upon failure
254//! Scans the next token as a boolean to GblScanner::token, returning GBL_TRUE and setting \p pBool to the scanned value upon success
256//! Scans the next token as a character to GblScanner::token, returning GBL_TRUE and setting \p pChar to the scanned value upon success
258//! Scans the next token as an 8-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
260//! Scans the next token as a 16-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
262//! Scans the next token as a 16-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
264//! Scans the next token as a 32-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
266//! Scans the next token as a 32-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
268//! Scans the next token as a 64-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
270//! Scans the next token as a 64-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
272//! Scans the next token as a float to GblScanner::token, returning GBL_TRUE and setting \p pFloat to the scanned value upon success
274//! Scans the next token as a double to GblScanner::token, returning GBL_TRUE and setting \p pDouble to the scanned value upon success
276//! Scans the next token and attempts to convert it from a string to the given type, \p t, moving its value through the variadic argument list
278//! Same as GblScanner_scanType(), except taking a va_list* rather than (a) variadic argument(s)
280//! Generic overload macro which automatically calls the respective scan function for the type of \p ptr
281#define GblScanner_scan(self, ptr)
282 GBL_META_GENERIC_MACRO_GENERATE(GBL_SCANNER_SCAN_TABLE_, ptr)(self, ptr)
283//! @}
284
285/*! \name Peeking
286 * \brief Methods for peeking at the next token
287 * \relatesalso GblScanner
288 * @{
289 */
290//! Peeks at the next token, without advancing the stream, storing it to GblScanner::next or returning GBL_FALSE upon failure
292//! Peeks at the next token, storing it to GblScanner::next if it exactly matches the given pattern or returning GBL_FALSE upon failure
294//! \todo implement me: GblScanner_peekMatch() overload
296//! Peeks at the next \p count lines, storing them to GblScanner::next or returning GBL_FALSE upon encountering EOF
298//! Peeks at the next \p count bytes, storing them to GblScanner::next or returning GBL_FALSE upon encountering EOF
300//! Peeks at the next token, without advancing, setting \p pBool and returning GBL_TRUE if it's boolean-convertible, or returning GBL_FALSE otherwise
302//! Peeks at the next token, without advancing, setting \p pChar and returning GBL_TRUE if it's character-convertible, or returning GBL_FALSE otherwise
304//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint8-convertible, or returning GBL_FALSE otherwise
306//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint16-convertible, or returning GBL_FALSE otherwise
308//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int16-convertible, or returning GBL_FALSE otherwise
310//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int32-convertible, or returning GBL_FALSE otherwise
312//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint32-convertible, or returning GBL_FALSE otherwise
314//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int64-convertible, or returning GBL_FALSE otherwise
316//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint64-convertible, or returning GBL_FALSE otherwise
318//! Peeks at the next token, without advancing, setting \p pFloat and returning GBL_TRUE if it's float-convertible, or returning GBL_FALSE otherwise
320//! Peeks at the next token, without advancing, setting \p pDouble and returning GBL_TRUE if it's double-convertible, or returning GBL_FALSE otherwise
322//! Peeks at the next token, without advancing, attempting to convert it to the given variant type, moving its value to the variadic argument, returning GBL_TRUE upon success
324//! Same as GblScanner_peekType(), except taking a va_list* rather than (a) variadic argument(s)
326//! Generic overload macro which automatically calls the respective peek function for the type of \p ptr
327#define GblScanner_peek(self, ptr)
328 GBL_META_GENERIC_MACRO_GENERATE(GBL_SCANNER_PEEK_TABLE_, ptr)(self, ptr)
329//! @}
330
331/*! \name Skipping
332 * \brief Methods for skipping over the input steram
333 * \relatesalso GblScanner
334 * @{
335 */
336//! Attempts to skip the next \p count tokens from the stream, returning GBL_TRUE upon success or GBL_FALSE upon EOF
338//! Attempts to skip to just past the given regex \p pPattern, returning GBL_TRUE upon success or GBL_FALSE if not found or upon EOF
340//! \todo implement me: GblScanner_skipMatch() overload
342//! Attemps to skip to the matching regex \p pPattern, returning GBL_TRUE upon success or GBL_FALSE if not found or upon EOF
344//! \todo implement me: GblScanner_skipToMatch() overload
346//! Attempts to skip \p count lines, returning GBL_TRUE upon success or GBL_FALSE upon EOF
348//! Attempts to skip \p count bytes, returning GBL_TRUE upon success or GBL_FALSE upon EOF
350//! @}
351
352/*! \name Utilities
353 * \brief Methods providing other utilities
354 * \relatesalso GblScanner
355 * @{
356 */
357//! Invokes the C stdlib routine, sscanf(), at the current position of the input stream
359//! Invokes the C stdlib routine, vscanf(), at the current position of the input stream
360GBL_EXPORT int GblScanner_vscanf (GBL_SELF, const char* pFmt, va_list* pList) GBL_NOEXCEPT;
361//! @}
362
364
365///\cond
366#define GBL_SCANNER_PEEK_TABLE_ (
368 (
369 (char*, GblScanner_peekChar),
370 (uint8_t*, GblScanner_peekUint8),
371 (uint16_t*, GblScanner_peekUint16),
372 (int16_t*, GblScanner_peekInt16),
373 (uint32_t*, GblScanner_peekUint32),
374 (int32_t*, GblScanner_peekInt32),
375 (uint64_t*, GblScanner_peekUint64),
376 (int64_t*, GblScanner_peekInt64),
377 (float*, GblScanner_peekFloat),
378 (double*, GblScanner_peekDouble)
379 ) \
380)
381
382#define GBL_SCANNER_SCAN_TABLE_ (
384 (
385 (char*, GblScanner_scanChar),
386 (uint8_t*, GblScanner_scanUint8),
387 (uint16_t*, GblScanner_scanUint16),
388 (int16_t*, GblScanner_scanInt16),
389 (uint32_t*, GblScanner_scanUint32),
390 (int32_t*, GblScanner_scanInt32),
391 (uint64_t*, GblScanner_scanUint64),
392 (int64_t*, GblScanner_scanInt64),
393 (float*, GblScanner_scanFloat),
394 (double*, GblScanner_scanDouble)
395 ) \
396)
397
398#define GblScanner_create(...)
399 GblScanner_createDefault_(__VA_ARGS__)
400#define GblScanner_createDefault_(...)
401 GblScanner_createDefault__(__VA_ARGS__, 0)
402#define GblScanner_createDefault__(string, count, ...)
403 (GblScanner_create)(string, count)
404
405#define GblScanner_cursor(...)
406 GblScanner_cursorDefault_(__VA_ARGS__)
407#define GblScanner_cursorDefault_(...)
408 GblScanner_cursorDefault__(__VA_ARGS__, 0)
409#define GblScanner_cursorDefault__(self, depth, ...)
410 (GblScanner_cursor)(self, depth)
411
412#define GblScanner_setInput(...)
413 GblScanner_setInputDefault_(__VA_ARGS__)
414#define GblScanner_setInputDefault_(...)
415 GblScanner_setInputDefault__(__VA_ARGS__, 0)
416#define GblScanner_setInputDefault__(self, string, count, ...)
417 (GblScanner_setInput)(self, string, count)
418///\endcond
419
420#undef GBL_SELF_TYPE
421
422#endif // GIMBAL_SCANNER_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_DECLARE_ENUM(E)
#define GBL_CLASS_DERIVE(...)
#define GBL_INSTANCE_END
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_FLAGS_TYPE
GblType UUID for flags.
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
#define GBL_META_GENERIC_MACRO_NO_DEFAULT
#define GBL_META_GENERIC_MACRO_GENERATE(traits, X)
#define GBL_STRING_TYPE
Builtin ID for string GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
GblScanner * GblScanner_create(const char *pStr, size_t len)
Creates and returns a new GblScanner, setting its input to the given string with optional length.
GblScanner * GblScanner_ref(GblScanner *pSelf)
Acquires a reference to the given scanner, incrementing its reference count and returning its address...
GBL_SCANNER_FLAGS
Extensible enum of flags used for GblScanner::status.
@ GBL_SCANNER_ERROR
Mask of all scanner error flags.
@ GBL_SCANNER_STATE
Mask of all scanner state flags.
@ GBL_SCANNER_EOF
End-of-file.
@ GBL_SCANNER_OK
No errors present.
@ GBL_SCANNER_SKIP_ERROR
Failed previous skip call.
@ GBL_SCANNER_SCAN_ERROR
Failed to scan the previous token.
@ GBL_SCANNER_PEEK_ERROR
Failed to peek the previous token.
@ GBL_SCANNER_USER_ERROR
Mask of error user flags.
@ GBL_SCANNER_USER_STATE
Mask of non-error user flags.
GblRefCount GblScanner_unref(GblScanner *pSelf)
Releases a reference to the given scanner, returning the remaining count, and destroying the scanner ...
#define GBL_SIGNALS(instanceStruct,...)
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
const char GblStringRef
Reference-counted, const char*-compatible string type.
GblStringRef * GblScannerClass_defaultDelimeters(const GblScannerClass *pSelf)
Returns a string reference to the current default delimeter pattern on the given class.
GblType GblScanner_type(void)
Returns the GblType UUID associated with GblScanner.
void GblScannerClass_setDefaultDelimetersRef(GblScannerClass *pSelf, const GblStringRef *pPattern)
Moves the given string reference to be owned by the given class as its delimeter pattern.
void GblScannerClass_setDefaultDelimeters(GblScannerClass *pSelf, const char *pPattern)
Sets the default delimeter pattern on the given class to a copy of pStr.
Represents the current region of interest for a GblScanner.
size_t column
Current column number.
size_t length
Length of current region of interest.
size_t position
Current character position.
size_t line
Current line number.
Generic text stream scanner object.
GblBool GblScanner_scanInt64(GblScanner *pSelf, int64_t *pInt)
Scans the next token as a 64-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
GblBool GblScanner_peekBool(GblScanner *pSelf, GblBool *pBool)
Peeks at the next token, without advancing, setting pBool and returning GBL_TRUE if it's boolean-conv...
GblBool GblScanner_scanUint16(GblScanner *pSelf, uint16_t *pUint)
Scans the next token as a 16-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_peekInt16(GblScanner *pSelf, int16_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int16-convert...
GblBool GblScanner_skipMatch(GblScanner *pSelf, const char *pPattern)
Attempts to skip to just past the given regex pPattern, returning GBL_TRUE upon success or GBL_FALSE ...
GblBool GblScanner_peekTypeVa(GblScanner *pSelf, GblType t, va_list *pVa)
Same as GblScanner_peekType(), except taking a va_list* rather than (a) variadic argument(s)
void GblScanner_raiseError(GblScanner *pSelf, GblFlags flags, const char *pFmt,...)
Raises an error, setting the given flags and message for the given scanner.
GblBool GblScanner_skipTokens(GblScanner *pSelf, size_t count)
Attempts to skip the next count tokens from the stream, returning GBL_TRUE upon success or GBL_FALSE ...
GblBool GblScanner_peekDouble(GblScanner *pSelf, double *pDouble)
Peeks at the next token, without advancing, setting pDouble and returning GBL_TRUE if it's double-con...
GblBool GblScanner_skipPattern(GblScanner *pSelf, const GblPattern *pPat)
size_t GblScanner_tell(const GblScanner *pSelf)
Fetches the current position of the cursor into the input stream.
GblBool GblScanner_peekType(GblScanner *pSelf, GblType t,...)
Peeks at the next token, without advancing, attempting to convert it to the given variant type,...
void GblScanner_clearError(GblScanner *pSelf)
Clears the pending error message string and any error flags which are set on the given scanner.
GblBool GblScanner_peekLines(GblScanner *pSelf, size_t count)
Peeks at the next count lines, storing them to GblScanner::next or returning GBL_FALSE upon encounter...
GblBool GblScanner_peekUint32(GblScanner *pSelf, uint32_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint32-conve...
GblBool GblScanner_peekInt64(GblScanner *pSelf, int64_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int64-convert...
GblBool GblScanner_skipLines(GblScanner *pSelf, size_t count)
Attempts to skip count lines, returning GBL_TRUE upon success or GBL_FALSE upon EOF.
const GblScannerCursor * GblScanner_cursor(const GblScanner *pSelf, size_t depth)
Returns the top cursor on the stack, which maintains the current position into the input stream.
GblBool GblScanner_peekFloat(GblScanner *pSelf, float *pFloat)
Peeks at the next token, without advancing, setting pFloat and returning GBL_TRUE if it's float-conve...
GblBool GblScanner_scanToken(GblScanner *pSelf)
Scans the next token, storing it to GblScanner::token or returning GBL_FALSE upon failure.
GblBool GblScanner_scanMatch(GblScanner *pSelf, const char *pPat)
Scans the next token to GblScanner::token if it matches the given pattern or returning GBL_FALSE upon...
GblBool GblScanner_scanUint64(GblScanner *pSelf, uint64_t *pUint)
Scans the next token as a 64-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanUint32(GblScanner *pSelf, uint32_t *pUint)
Scans the next token as a 32-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanBytes(GblScanner *pSelf, size_t bytes)
Scans the given number of bytes to GblScanner::token or returns GBL_FALSE upon failure.
const GblStringRef * pError
Pending error message.
int GblScanner_vscanf(GblScanner *pSelf, const char *pFmt, va_list *pList)
Invokes the C stdlib routine, vscanf(), at the current position of the input stream.
GblStringView token
Current token in the stream.
GblStringView next
Peeked-at next token in the stream.
GblBool GblScanner_peekPattern(GblScanner *pSelf, const GblPattern *pPat)
void GblScanner_setDelimeters(GblScanner *pSelf, const char *pPattern)
Sets the stream's delimeter regular expression pattern to pPattern.
GblBool GblScanner_seek(GblScanner *pSelf, int whence)
Moves the cursor's current stream position by the given positive or negative offset.
GblBool GblScanner_scanTypeVa(GblScanner *pSelf, GblType t, va_list *pVa)
Same as GblScanner_scanType(), except taking a va_list* rather than (a) variadic argument(s)
GBL_RESULT GblScanner_popCursor(GblScanner *pSelf)
Pops the value of the current cursor from the top of the stack, reloading its state.
GblBool GblScanner_scanPattern(GblScanner *pSelf, const GblPattern *pPat)
GblBool GblScanner_skipToMatch(GblScanner *pSelf, const char *pPattern)
Attemps to skip to the matching regex pPattern, returning GBL_TRUE upon success or GBL_FALSE if not f...
GblStringRef * GblScanner_delimeters(const GblScanner *pSelf)
Returns a reference to the string used as the delimeter regular expression pattern.
size_t GblScanner_cursorDepth(const GblScanner *pSelf)
Returns the depth of the cursor stack for the given scanner object.
GblBool GblScanner_peekUint8(GblScanner *pSelf, uint8_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint8-conver...
void GblScanner_reset(GblScanner *pSelf)
Resets the state of the input stream, moving the cursor back to the beginning.
GblBool GblScanner_peekUint16(GblScanner *pSelf, uint16_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint16-conve...
int GblScanner_scanf(GblScanner *pSelf, const char *pFmt,...)
Invokes the C stdlib routine, sscanf(), at the current position of the input stream.
GblStringRef * GblScanner_input(const GblScanner *pSelf)
Returns a string reference to the string current being used as the input stream.
GblBool GblScanner_peekInt32(GblScanner *pSelf, int32_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int32-convert...
GblBool GblScanner_peekBytes(GblScanner *pSelf, size_t count)
Peeks at the next count bytes, storing them to GblScanner::next or returning GBL_FALSE upon encounter...
GblBool GblScanner_peekMatch(GblScanner *pSelf, const char *pMatch)
Peeks at the next token, storing it to GblScanner::next if it exactly matches the given pattern or re...
void GblScanner_setInput(GblScanner *pSelf, const char *pStr, size_t count)
Sets the input stream to the given string, optionally taking its size, and resetting the stream.
GblBool GblScanner_scanInt32(GblScanner *pSelf, int32_t *pInt)
Scans the next token as a 32-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
GblBool GblScanner_scanLines(GblScanner *pSelf, size_t lines)
Scans the given number of lines to GblScanner::token or returns GBL_FALSE upon failure.
GblBool GblScanner_skipBytes(GblScanner *pSelf, size_t count)
Attempts to skip count bytes, returning GBL_TRUE upon success or GBL_FALSE upon EOF.
GblBool GblScanner_peekToken(GblScanner *pSelf)
Peeks at the next token, without advancing the stream, storing it to GblScanner::next or returning GB...
GblBool GblScanner_scanType(GblScanner *pSelf, GblType t,...)
Scans the next token and attempts to convert it from a string to the given type, t,...
GblBool GblScanner_peekUint64(GblScanner *pSelf, uint64_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint64-conve...
GblBool GblScanner_scanBool(GblScanner *pSelf, GblBool *pBool)
Scans the next token as a boolean to GblScanner::token, returning GBL_TRUE and setting pBool to the s...
GBL_SCANNER_FLAGS status
Status after the last operation.
GblBool GblScanner_scanDouble(GblScanner *pSelf, double *pDouble)
Scans the next token as a double to GblScanner::token, returning GBL_TRUE and setting pDouble to the ...
GBL_RESULT GblScanner_pushCursor(GblScanner *pSelf)
Pushes the value of the current cursor onto the stack, saving its state.
GblBool GblScanner_skipToPattern(GblScanner *pSelf, const GblPattern *pPat)
GblBool GblScanner_peekChar(GblScanner *pSelf, char *pChar)
Peeks at the next token, without advancing, setting pChar and returning GBL_TRUE if it's character-co...
GblBool GblScanner_scanFloat(GblScanner *pSelf, float *pFloat)
Scans the next token as a float to GblScanner::token, returning GBL_TRUE and setting pFloat to the sc...
GblBool GblScanner_scanUint8(GblScanner *pSelf, uint8_t *pUint)
Scans the next token as an 8-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanChar(GblScanner *pSelf, char *pChar)
Scans the next token as a character to GblScanner::token, returning GBL_TRUE and setting pChar to the...
GblBool GblScanner_scanInt16(GblScanner *pSelf, int16_t *pInt)
Scans the next token as a 16-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
void GblScanner_setInputRef(GblScanner *pSelf, const GblStringRef *pRef)
Sets the input stream to given string reference, taking ownership of it, and resetting the sream.