picofuse

scanner.h
Go to the documentation of this file.
1 
43 #pragma once
44 #include <picofuse/sys.h>
45 #include <stdbool.h>
46 #include <stddef.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
53 // TYPES
54 
66 typedef enum {
81 
91 typedef enum {
92  sys_scanner_none = 0,
93 
98 
103 
107 
110 
114 
119 
123 
126 
130 
134 
137 
141 
148 
152 
156 
162 
172 typedef struct sys_scanner_t {
175  ptrdiff_t start;
176  size_t bytes;
178  size_t runes;
179  sys_scanner_class_t isa;
180 } sys_scanner_t;
181 
183 // METHODS
184 
195 
203 extern bool sys_scanner_next(sys_scanner_t *it);
204 
215 extern size_t sys_scanner_token(sys_scanner_t *it, char *buf, size_t cap);
216 
218 
219 #ifdef __cplusplus
220 }
221 #endif
Recognize &#39;//&#39; line comments - same rules as sys_scanner_comments_hash, triggered by "//" instead...
Definition: scanner.h:133
sys_scanner_flags_t
Flags controlling which tokenization rules sys_scanner_init() applies.
Definition: scanner.h:91
Both quote styles - sys_scanner_quotes_single | _double.
Definition: scanner.h:125
sys_scanner_flags_t flags
flags given to init() (private)
Definition: scanner.h:174
sys_scanner_numbers, plus a fractional part ("3.14") and/or an exponent ("1e10", "1.5e-3").
Definition: scanner.h:160
sys_scanner_keywords, plus &#39;-&#39; allowed within an identifier.
Definition: scanner.h:113
Give &#39; &#39; its own sys_scanner_newline class instead of merging it into a sys_scanner_space run - usefu...
Definition: scanner.h:102
one control character (non-whitespace)
Definition: scanner.h:73
Recognize &#39;#&#39; line comments as sys_scanner_comment, running to (not including) the next &#39; &#39; or end of...
Definition: scanner.h:129
System abstraction headers and process lifecycle hooks.
whitespace run - see sys_rune_is_space()
Definition: scanner.h:68
Both comment styles - sys_scanner_comments_hash | _slash.
Definition: scanner.h:136
a comment - sys_scanner_comments
Definition: scanner.h:78
sys_scanner_class_t
Classification of a scanned token.
Definition: scanner.h:66
sys_scanner_numbers, plus "0b"/"0B" followed by binary digits, e.g.
Definition: scanner.h:151
struct sys_iostream_t sys_iostream_t
An opaque byte stream.
Definition: io.h:68
Recognize [+-]?[0-9]+ as a single sys_scanner_number token instead of a separate sign and digit run...
Definition: scanner.h:140
a -escape sequence - sys_scanner_escapes
Definition: scanner.h:74
letter run
Definition: scanner.h:70
bool sys_scanner_next(sys_scanner_t *it)
Advance to the next token.
size_t bytes
length of the current token, in bytes
Definition: scanner.h:177
Recognize [A-Za-z][A-Za-z0-9]* identifiers as a single sys_scanner_keyword token instead of separate ...
Definition: scanner.h:106
sys_scanner_numbers, plus "0x"/"0X" followed by hex digits, e.g.
Definition: scanner.h:155
Scanner state: reads a stream into a sequence of typed tokens.
Definition: scanner.h:172
sys_scanner_keywords, plus &#39;_&#39; allowed within an identifier.
Definition: scanner.h:109
a number - sys_scanner_numbers
Definition: scanner.h:79
size_t runes
number of runes in the current token
Definition: scanner.h:178
Recognize &#39;...&#39;-quoted strings as sys_scanner_string.
Definition: scanner.h:118
ptrdiff_t start
absolute stream position where the current
Definition: scanner.h:175
an identifier - sys_scanner_keywords
Definition: scanner.h:76
a quoted string - sys_scanner_quotes
Definition: scanner.h:77
sys_iostream_t * stream
source (private)
Definition: scanner.h:173
one symbol character
Definition: scanner.h:72
Recognize \" \\ \/ \b \f \n \r \t and \uXXXX as a single sys_scanner_escape token instead of ordinary...
Definition: scanner.h:97
size_t sys_scanner_token(sys_scanner_t *it, char *buf, size_t cap)
Read the current token&#39;s text.
struct sys_scanner_t sys_scanner_t
Scanner state: reads a stream into a sequence of typed tokens.
one punctuation character
Definition: scanner.h:71
Recognize "..."-quoted strings - same rules as sys_scanner_quotes_single, triggered by &#39;"&#39; instead...
Definition: scanner.h:122
one &#39; &#39; - sys_scanner_newlines
Definition: scanner.h:75
sys_scanner_numbers, plus octal: "0o"/"0O" (Python/Rust/Swift style, self-describing) or a bare leadi...
Definition: scanner.h:147
sys_scanner_class_t isa
classification of the current token
Definition: scanner.h:179
unclassified or malformed
Definition: scanner.h:67
decimal digit run
Definition: scanner.h:69
sys_scanner_t sys_scanner_init(sys_iostream_t *stream, sys_scanner_flags_t flags)
Initialize a scanner over a stream.