|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | tokenizer_entry |
| One name of the token list (the caller's memory). More... | |
| struct | tokenizer |
| The tokeniser: the token list as a hash table over the caller's arrays, and the rule set. Read-only while tokenising. More... | |
Macros | |
| #define | TOKENIZER_AB3_COLUMNS 250 |
| Characters of a line of a main source AmiBlitz3 keeps (MAX_Columns, Shared/common.ab3:96). | |
| #define | TOKENIZER_BOUND(len) |
| Bytes tokenizer_text and tokenizer_line may write for len bytes of text: a name of one letter becomes a 2-byte token, a string or a comment at the end of the text gets its 0. | |
| #define | TOKENIZER_LITHI 0x90 |
| The first byte of a literal character (TOKENIZER_RULES_AB3_LIT). | |
| #define | TOKENIZER_AB3_TEXT 1 /* tokenised as text */ |
| #define | TOKENIZER_AB3_HEADER 2 /* its embedded header skipped */ |
| #define | TOKENIZER_AB3_INCNAMES 7 |
| The names AmiBlitz3 tries for an include at one place (ab3_GetIncludeLock, AmiBlitz3.ab3:25796): the name, then its extension replaced by .ab3, .ab2, .bb2, then these behind the old extension (dos_SetExt/dos_RemExt of dos.include.ab3). | |
| #define | TOKENIZER_AB3_TOKENISED 2 |
| #define | TOKENIZER_AB3_REFUSED 0 |
Enumerations | |
| enum | tokenizer_rules { TOKENIZER_RULES_AB3 = 1 , TOKENIZER_RULES_AB3_LIT = 2 } |
| The rule sets. More... | |
| enum | tokenizer_err { TOKENIZER_OK , TOKENIZER_DUPLICATE , TOKENIZER_E_RULES , TOKENIZER_E_BUCKETS , TOKENIZER_E_FULL , TOKENIZER_E_NAME , TOKENIZER_E_SPACE } |
| Results of the functions (TOKENIZER_OK = 0). More... | |
Functions | |
| 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. | |
| 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. | |
| 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. | |
| 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). | |
| 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. | |
| #define TOKENIZER_AB3_COLUMNS 250 |
Characters of a line of a main source AmiBlitz3 keeps (MAX_Columns, Shared/common.ab3:96).
| #define TOKENIZER_AB3_HEADER 2 /* its embedded header skipped */ |
| #define TOKENIZER_AB3_INCNAMES 7 |
The names AmiBlitz3 tries for an include at one place (ab3_GetIncludeLock, AmiBlitz3.ab3:25796): the name, then its extension replaced by .ab3, .ab2, .bb2, then these behind the old extension (dos_SetExt/dos_RemExt of dos.include.ab3).
| #define TOKENIZER_AB3_REFUSED 0 |
| #define TOKENIZER_AB3_TEXT 1 /* tokenised as text */ |
| #define TOKENIZER_AB3_TOKENISED 2 |
| #define TOKENIZER_BOUND | ( | len | ) |
| #define TOKENIZER_LITHI 0x90 |
The first byte of a literal character (TOKENIZER_RULES_AB3_LIT).
| enum tokenizer_err |
| enum tokenizer_rules |
| 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 |