|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "tokenizer.h"Macros | |
| #define | F_STOP 0x001 /* ends a word: look it up */ |
| #define | F_NEW 0x002 /* a token may start behind it */ |
| #define | F_IS 0x004 /* belongs to a word */ |
| #define | F_FIRST 0x008 /* starts a word */ |
| #define | F_COPY 0x010 /* copied to the output */ |
| #define | F_QUOT 0x020 /* starts a string */ |
| #define | F_COMMENT 0x040 /* starts a comment */ |
| #define | F_EOL 0x080 /* ends a line: a 0 */ |
| #define | F_TAB 0x100 /* a space */ |
| #define | GET(i) |
| #define | PUT(b) |
| #define | PUTLIT(b) |
| #define | AT(i) |
Functions | |
| static uint32_t | hash (const uint8_t *s, size_t len) |
| static int | same (const uint8_t *a, const uint8_t *b, size_t len) |
| int | tokenizer_init (struct tokenizer *t, int rules, struct tokenizer_entry *entry, uint32_t cap, uint16_t *bucket, uint32_t nbucket) |
| Set up an empty tokeniser. | |
| static uint32_t | lookup (const struct tokenizer *t, const uint8_t *name, size_t len) |
| int | tokenizer_add (struct tokenizer *t, const uint8_t *name, size_t len, uint16_t num) |
| Add a name to the token list, in the compiler's order. A name that is there already keeps its first token (AmiBlitz3's preproc_QueryTokens): the call changes nothing. | |
| int | tokenizer_find (const struct tokenizer *t, const uint8_t *name, size_t len, uint16_t *num) |
| Look a name up, byte for byte. | |
| static unsigned | flags (unsigned c) |
| static int | run (const struct tokenizer *t, const uint8_t *src, size_t len, int lf, uint8_t *dst, size_t cap, size_t *out) |
| int | tokenizer_text (const struct tokenizer *t, const uint8_t *src, size_t len, uint8_t *dst, size_t cap, size_t *out) |
| Tokenise a text as AmiBlitz3 tokenises a whole source buffer. Every LF (and every 0 byte) of the text ends a line with a 0; a TAB outside strings and comments becomes a space, CR, DEL and the other control characters are dropped, a byte from 128 becomes '?'; inside a string or a comment every byte stays except TAB (a space). A word that ends the text (no character behind it) is not looked up, a string or comment that ends it gets its 0 (AmiBlitz3 reads the 0 behind its buffer). With TOKENIZER_RULES_AB3_LIT a byte from 128 inside a string or a comment is written as the pair TOKENIZER_LITHI byte. | |
| int | tokenizer_line (const struct tokenizer *t, const uint8_t *src, size_t len, uint8_t *dst, size_t cap, size_t *out) |
| Tokenise one line: as tokenizer_text of the line followed by its LF, so the output ends with the line's 0. | |
| size_t | tokenizer_ab3_header (const uint8_t *src, size_t len) |
| The end of the embedded header of a main source, as AmiBlitz3's ParseAB3Header finds it (CLIModeSupport.ab3:576): the lines up to the first one whose letters, '_', '/' and '-' before a '=' read "/xtra" in any case, that line with its LF included. | |
| size_t | tokenizer_ab3_incheader (const uint8_t *src, size_t len) |
| The end of the embedded header of an include, as AmiBlitz3's SkipXtraHeader finds it (CLIModeSupport.ab3:401): leading lines with a ';' up to a "/xtra", "/XTRA" or "/Xtra", that line with its LF included. | |
| size_t | tokenizer_lines (const uint8_t *src, size_t len) |
| The lines a header of len bytes has (each LF ends one, a last line without LF counts). | |
| size_t | tokenizer_ab3_mainline (const uint8_t *tok, size_t len, size_t pos, size_t *keep) |
| One line of a tokenised main source as AmiBlitz3's LoadSource takes it (CLIModeSupport.ab3:480): the bytes from pos up to the next 0 or the end, of which at most TOKENIZER_AB3_COLUMNS are kept. | |
| size_t | tokenizer_ab3_mainline_lit (const uint8_t *tok, size_t len, size_t pos, size_t *keep) |
| tokenizer_ab3_mainline for a text tokenised with TOKENIZER_RULES_AB3_LIT: a literal character (TOKENIZER_LITHI and a byte from 128) counts as the one byte AmiBlitz3 keeps for it, and the cut never falls between its two bytes; every other byte counts one, as there. The line kept has at most TOKENIZER_AB3_COLUMNS bytes as well (the editor's line length is a byte): a line with literal characters may keep fewer characters than AmiBlitz3. | |
| size_t | tokenizer_ab3_getext (const char *name, size_t len) |
| The extension of a file name as AmiBlitz3's dos_GetExt finds it (Sourcecodes/Includes/dos.include.ab3:2353): the part behind the last '.' among the last 10 characters, not a '.' at the start. | |
| static size_t | remext (const char *name, size_t len) |
| static size_t | setext (const char *name, size_t len, const char *e1, size_t n1, const char *e2, char *out, size_t cap) |
| size_t | tokenizer_ab3_incname (const char *name, size_t len, int k, char *out, size_t cap) |
| One of the names AmiBlitz3 tries for an include. | |
| int | tokenizer_ab3_inctype (const char *name, size_t len) |
| How AmiBlitz3 includes a file of this (full) name (processInclude, AmiBlitz3.ab3:20754): by its last three characters, case-sensitively. | |
| static int | isext (const char *name, size_t len, const char *ext) |
| int | tokenizer_ab3_source (const char *name, size_t len) |
| Whether AmiBlitz3 tokenises a main source of this name as text (CLIModeSupport.ab3 LoadSource: not a .bb or .bb2, in any case) and skips its embedded header (not a .ab2 either, whose settings are in its companion .xtra). | |
| #define F_COMMENT 0x040 /* starts a comment */ |
| #define F_EOL 0x080 /* ends a line: a 0 */ |
| #define F_FIRST 0x008 /* starts a word */ |
| #define F_NEW 0x002 /* a token may start behind it */ |
| #define F_QUOT 0x020 /* starts a string */ |
| #define F_STOP 0x001 /* ends a word: look it up */ |
| #define F_TAB 0x100 /* a space */ |
| #define PUT | ( | b | ) |
| #define PUTLIT | ( | b | ) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| size_t tokenizer_ab3_getext | ( | const char * | name, |
| size_t | len ) |
The extension of a file name as AmiBlitz3's dos_GetExt finds it (Sourcecodes/Includes/dos.include.ab3:2353): the part behind the last '.' among the last 10 characters, not a '.' at the start.
| size_t tokenizer_ab3_header | ( | const uint8_t * | src, |
| size_t | len ) |
The end of the embedded header of a main source, as AmiBlitz3's ParseAB3Header finds it (CLIModeSupport.ab3:576): the lines up to the first one whose letters, '_', '/' and '-' before a '=' read "/xtra" in any case, that line with its LF included.
| src | the source text |
| len | its length |
| size_t tokenizer_ab3_incheader | ( | const uint8_t * | src, |
| size_t | len ) |
The end of the embedded header of an include, as AmiBlitz3's SkipXtraHeader finds it (CLIModeSupport.ab3:401): leading lines with a ';' up to a "/xtra", "/XTRA" or "/Xtra", that line with its LF included.
| src | the include's text |
| len | its length |
| size_t tokenizer_ab3_incname | ( | const char * | name, |
| size_t | len, | ||
| int | k, | ||
| char * | out, | ||
| size_t | cap ) |
| int tokenizer_ab3_inctype | ( | const char * | name, |
| size_t | len ) |
How AmiBlitz3 includes a file of this (full) name (processInclude, AmiBlitz3.ab3:20754): by its last three characters, case-sensitively.
| size_t tokenizer_ab3_mainline | ( | const uint8_t * | tok, |
| size_t | len, | ||
| size_t | pos, | ||
| size_t * | keep ) |
One line of a tokenised main source as AmiBlitz3's LoadSource takes it (CLIModeSupport.ab3:480): the bytes from pos up to the next 0 or the end, of which at most TOKENIZER_AB3_COLUMNS are kept.
| tok | the tokenised text (tokenizer_text) |
| len | its length |
| pos | the start of the line (< len) |
| keep | the bytes of the line kept (without its 0) |
| size_t tokenizer_ab3_mainline_lit | ( | const uint8_t * | tok, |
| size_t | len, | ||
| size_t | pos, | ||
| size_t * | keep ) |
tokenizer_ab3_mainline for a text tokenised with TOKENIZER_RULES_AB3_LIT: a literal character (TOKENIZER_LITHI and a byte from 128) counts as the one byte AmiBlitz3 keeps for it, and the cut never falls between its two bytes; every other byte counts one, as there. The line kept has at most TOKENIZER_AB3_COLUMNS bytes as well (the editor's line length is a byte): a line with literal characters may keep fewer characters than AmiBlitz3.
| int tokenizer_ab3_source | ( | const char * | name, |
| size_t | len ) |
Whether AmiBlitz3 tokenises a main source of this name as text (CLIModeSupport.ab3 LoadSource: not a .bb or .bb2, in any case) and skips its embedded header (not a .ab2 either, whose settings are in its companion .xtra).
| int tokenizer_add | ( | struct tokenizer * | t, |
| const uint8_t * | name, | ||
| size_t | len, | ||
| uint16_t | num ) |
Add a name to the token list, in the compiler's order. A name that is there already keeps its first token (AmiBlitz3's preproc_QueryTokens): the call changes nothing.
| t | the tokeniser |
| name | the name's bytes (kept by reference) |
| len | its length |
| num | the token number (bit 15 set as in a tokenised source, or not: it is written as given) |
| int tokenizer_find | ( | const struct tokenizer * | t, |
| const uint8_t * | name, | ||
| size_t | len, | ||
| uint16_t * | num ) |
| int tokenizer_init | ( | struct tokenizer * | t, |
| int | rules, | ||
| struct tokenizer_entry * | entry, | ||
| uint32_t | cap, | ||
| uint16_t * | bucket, | ||
| uint32_t | nbucket ) |
Set up an empty tokeniser.
| t | the object |
| rules | an enum tokenizer_rules |
| entry | room for cap names (at most 65535) |
| cap | the entries there are |
| bucket | the hash buckets: nbucket words |
| nbucket | a power of 2, 1..65536 |
| int tokenizer_line | ( | const struct tokenizer * | t, |
| const uint8_t * | src, | ||
| size_t | len, | ||
| uint8_t * | dst, | ||
| size_t | cap, | ||
| size_t * | out ) |
Tokenise one line: as tokenizer_text of the line followed by its LF, so the output ends with the line's 0.
| t | the tokeniser |
| src | the line without its LF |
| len | its length |
| dst | the output (not overlapping src) |
| cap | its size; TOKENIZER_BOUND(len) is always enough |
| out | the bytes written, the 0 included |
| size_t tokenizer_lines | ( | const uint8_t * | src, |
| size_t | len ) |
The lines a header of len bytes has (each LF ends one, a last line without LF counts).
| int tokenizer_text | ( | const struct tokenizer * | t, |
| const uint8_t * | src, | ||
| size_t | len, | ||
| uint8_t * | dst, | ||
| size_t | cap, | ||
| size_t * | out ) |
Tokenise a text as AmiBlitz3 tokenises a whole source buffer. Every LF (and every 0 byte) of the text ends a line with a 0; a TAB outside strings and comments becomes a space, CR, DEL and the other control characters are dropped, a byte from 128 becomes '?'; inside a string or a comment every byte stays except TAB (a space). A word that ends the text (no character behind it) is not looked up, a string or comment that ends it gets its 0 (AmiBlitz3 reads the 0 behind its buffer). With TOKENIZER_RULES_AB3_LIT a byte from 128 inside a string or a comment is written as the pair TOKENIZER_LITHI byte.
| t | the tokeniser |
| src | the text |
| len | its length |
| dst | the output (not overlapping src) |
| cap | its size; TOKENIZER_BOUND(len) is always enough |
| out | the bytes written |