#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include <iso646.h>
#include <string.h>
#include <assert.h>
#include <sys/resource.h>
#include <errno.h>
#include "array.h"
#include "macros.h"
#include <time.h>
Data Structures | |
struct | Options |
struct | Marker |
struct | Error |
struct | Marker_array |
struct | Marker_array_slice |
struct | Marker_array_mut_slice |
struct | TokenType_array |
struct | TokenType_array_slice |
struct | TokenType_array_mut_slice |
struct | Byte_array |
struct | Byte_array_slice |
struct | Byte_array_mut_slice |
struct | Macro |
Macros | |
#define | is_not not_eq |
#define | is == |
#define | in(min, x, max) (x >= min && x <= max) |
#define | mem_eq(a, b, len) (0 is memcmp(a, b, len)) |
#define | str_eq(a, b) (0 is strcmp(a, b)) |
#define | strn_eq(a, b, len) (0 is strncmp(a, b, len)) |
#define | NDEBUG |
#define | CEDRO_VERSION "1.0" |
#define | CEDRO_PRAGMA "#pragma Cedro 1." |
#define | CEDRO_PRAGMA_LEN 16 |
#define | LANG(es, en) (strn_eq(getenv("LANG"), "es", 2)? es: en) |
#define | eprintln(...) eprint(__VA_ARGS__), eprint("\n") |
#define | TYPEDEF_STRUCT(T, TYPE) |
#define | TYPEDEF(T, TYPE) |
#define | B(string) ((const unsigned char * const)string) |
#define | precedence(token_type) (token_type - T_OP_1) |
#define | is_keyword(token_type) (token_type >= T_TYPE && token_type <= T_CONTROL_FLOW_LABEL) |
#define | is_operator(token_type) (token_type >= T_OP_1 && token_type <= T_COMMA) |
#define | is_fence(token_type) (token_type >= T_BLOCK_START && token_type <= T_GROUP_END) |
#define | skip_space_forward(start, end) while (start is_not end and (start->token_type is T_SPACE or start->token_type is T_COMMENT)) ++start |
#define | skip_space_back(start, end) while (end is_not start and ((end-1)->token_type is T_SPACE or (end-1)->token_type is T_COMMENT)) --end |
#define | TOKEN1(token) token_type = token |
#define | TOKEN2(token) ++token_end; TOKEN1(token) |
#define | TOKEN3(token) token_end += 2; TOKEN1(token) |
#define | MACROS_DECLARE |
Enumerations | |
enum | UTF8Error { UTF8_NO_ERROR , UTF8_ERROR , UTF8_ERROR_OVERLONG , UTF8_ERROR_INTERRUPTED_1 = 0x40 , UTF8_ERROR_INTERRUPTED_2 = 0x80 , UTF8_ERROR_INTERRUPTED_3 = 0xC0 } |
enum | TokenType { T_NONE , T_IDENTIFIER , T_TYPE , T_TYPE_STRUCT , T_TYPE_QUALIFIER , T_TYPE_QUALIFIER_AUTO , T_TYPEDEF , T_CONTROL_FLOW_IF , T_CONTROL_FLOW_LOOP , T_CONTROL_FLOW_SWITCH , T_CONTROL_FLOW_CASE , T_CONTROL_FLOW_BREAK , T_CONTROL_FLOW_CONTINUE , T_CONTROL_FLOW_RETURN , T_CONTROL_FLOW_GOTO , T_CONTROL_FLOW_LABEL , T_NUMBER , T_STRING , T_CHARACTER , T_SPACE , T_COMMENT , T_PREPROCESSOR , T_GENERIC_MACRO , T_BLOCK_START , T_BLOCK_END , T_TUPLE_START , T_TUPLE_END , T_INDEX_START , T_INDEX_END , T_GROUP_START , T_GROUP_END , T_OP_1 , T_OP_2 , T_OP_3 , T_OP_4 , T_OP_5 , T_OP_6 , T_OP_7 , T_OP_8 , T_OP_9 , T_OP_10 , T_OP_11 , T_OP_12 , T_OP_13 , T_OP_14 , T_COMMA , T_SEMICOLON , T_LABEL_COLON , T_BACKSTITCH , T_ELLIPSIS , T_OTHER } |
Variables | |
static const size_t | error_buffer_size = 256 |
static char | error_buffer [256] = {0} |
static const unsigned char *const | TokenType_STRING [1+T_OTHER] |
static const size_t | PADDING_Marker_ARRAY = 0 |
static const size_t | PADDING_TokenType_ARRAY = 0 |
static const size_t | PADDING_Byte_ARRAY = 8 |
static const char | spacing [80] |
static const size_t | markers_tabulator = 20 |
static const size_t | right_margin = sizeof(spacing) - 2 |
static Macro | macros [] |
static const char *const | usage_es |
static const char *const | usage_en |
Binary string, const unsigned char const*
.
#define CEDRO_PRAGMA "#pragma Cedro 1." |
Versions with the same major number are compatible in that they produce semantically equivalent output: there might be differeces in indentation etc. but will be the same after parsing by the compiler.
#define CEDRO_PRAGMA_LEN 16 |
#define CEDRO_VERSION "1.0" |
Same as fprintf(stderr, fmt, ...) fputc('\n', stderr)
but converting UTF-8 characters to Latin-1 if the LANG
environment variable does not contain UTF-8
.
#define in | ( | min, | |
x, | |||
max | |||
) | (x >= min && x <= max) |
#define is == |
#define is_fence | ( | token_type | ) | (token_type >= T_BLOCK_START && token_type <= T_GROUP_END) |
#define is_keyword | ( | token_type | ) | (token_type >= T_TYPE && token_type <= T_CONTROL_FLOW_LABEL) |
#define is_not not_eq |
#define LANG | ( | es, | |
en | |||
) | (strn_eq(getenv("LANG"), "es", 2)? es: en) |
#define MACROS_DECLARE |
#define mem_eq | ( | a, | |
b, | |||
len | |||
) | (0 is memcmp(a, b, len)) |
#define NDEBUG |
#define precedence | ( | token_type | ) | (token_type - T_OP_1) |
#define skip_space_back | ( | start, | |
end | |||
) | while (end is_not start and ((end-1)->token_type is T_SPACE or (end-1)->token_type is T_COMMENT)) --end |
Skip backward all T_SPACE
and T_COMMENT
markers.
#define skip_space_forward | ( | start, | |
end | |||
) | while (start is_not end and (start->token_type is T_SPACE or start->token_type is T_COMMENT)) ++start |
Skip forward all T_SPACE
and T_COMMENT
markers.
#define str_eq | ( | a, | |
b | |||
) | (0 is strcmp(a, b)) |
#define strn_eq | ( | a, | |
b, | |||
len | |||
) | (0 is strncmp(a, b, len)) |
#define TOKEN1 | ( | token | ) | token_type = token |
#define TOKEN2 | ( | token | ) | ++token_end; TOKEN1(token) |
#define TOKEN3 | ( | token | ) | token_end += 2; TOKEN1(token) |
#define TYPEDEF | ( | T, | |
TYPE | |||
) |
Defines mutable types mut_〈T〉 and mut_〈T〉_p (pointer), and constant types 〈T〉 and 〈T〉_p (pointer to constant).
You can define similar types for an existing type, for instance uint8_t
:
#define TYPEDEF_STRUCT | ( | T, | |
TYPE | |||
) |
Defines mutable struct types mut_〈T〉 and mut_〈T〉_p (pointer), and constant types 〈T〉 and 〈T〉_p (pointer to constant).
typedef const uint8_t Byte |
typedef const struct Byte_array Byte_array |
typedef const struct Byte_array * const * Byte_array_mut_p |
typedef struct Byte_array_mut_slice Byte_array_mut_slice |
A slice of an array where the elements are constants. Example:
typedef struct Byte_array_mut_slice * const * Byte_array_mut_slice_mut_p |
typedef struct Byte_array_mut_slice * const Byte_array_mut_slice_p |
typedef const struct Byte_array * const Byte_array_p |
typedef const struct Byte_array_slice Byte_array_slice |
typedef const struct Byte_array_slice * const * Byte_array_slice_mut_p |
typedef const struct Byte_array_slice * const Byte_array_slice_p |
typedef const uint8_t * const * Byte_mut_p |
typedef const uint8_t * const Byte_p |
typedef const struct Error * const * Error_mut_p |
typedef const char* FilePath |
typedef void(* MacroFunction_p) (mut_Marker_array_p markers, mut_Byte_array_p src) |
typedef const struct Marker_array Marker_array |
typedef const struct Marker_array * const * Marker_array_mut_p |
typedef struct Marker_array_mut_slice Marker_array_mut_slice |
A slice of an array where the elements are constants. Example:
typedef struct Marker_array_mut_slice * const * Marker_array_mut_slice_mut_p |
typedef struct Marker_array_mut_slice * const Marker_array_mut_slice_p |
typedef const struct Marker_array * const Marker_array_p |
typedef const struct Marker_array_slice Marker_array_slice |
typedef const struct Marker_array_slice * const * Marker_array_slice_mut_p |
typedef const struct Marker_array_slice * const Marker_array_slice_p |
typedef const struct Marker * const * Marker_mut_p |
typedef uint8_t mut_Byte |
typedef struct Byte_array mut_Byte_array |
Add 8 bytes after end of buffer to avoid bounds checking while scanning for tokens. No literal token is longer. The constant PADDING_Byte_ARRAY
= 8
defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0
or other appropriate value.
typedef struct Byte_array * mut_Byte_array_mut_p |
typedef struct Byte_array_mut_slice mut_Byte_array_mut_slice |
A slice of an array where the elements are mutable. Example:
typedef struct Byte_array_mut_slice * mut_Byte_array_mut_slice_mut_p |
typedef struct Byte_array_mut_slice mut_Byte_array_mut_slice_p |
typedef struct Byte_array mut_Byte_array_p |
typedef struct Byte_array_slice mut_Byte_array_slice |
typedef struct Byte_array_slice * mut_Byte_array_slice_mut_p |
typedef struct Byte_array_slice mut_Byte_array_slice_p |
typedef uint8_t * const * mut_Byte_mut_p |
typedef uint8_t * const mut_Byte_p |
typedef struct Error * mut_Error_mut_p |
typedef struct Error mut_Error_p |
typedef FILE* mut_File_p |
typedef char* mut_FilePath |
typedef struct Marker mut_Marker |
Marks a C token in the source code.
typedef struct Marker_array mut_Marker_array |
The constant PADDING_Marker_ARRAY
= 0
defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0
or other appropriate value.
typedef struct Marker_array * mut_Marker_array_mut_p |
typedef struct Marker_array_mut_slice mut_Marker_array_mut_slice |
A slice of an array where the elements are mutable. Example:
typedef struct Marker_array_mut_slice * mut_Marker_array_mut_slice_mut_p |
typedef struct Marker_array_mut_slice mut_Marker_array_mut_slice_p |
typedef struct Marker_array mut_Marker_array_p |
typedef struct Marker_array_slice mut_Marker_array_slice |
typedef struct Marker_array_slice * mut_Marker_array_slice_mut_p |
typedef struct Marker_array_slice mut_Marker_array_slice_p |
typedef struct Marker * mut_Marker_mut_p |
typedef struct Marker mut_Marker_p |
typedef enum TokenType mut_TokenType |
These token types loosely correspond to those in the C grammar.
Keywords: https://en.cppreference.com/w/c/keyword
Operator precedence levels: https://en.cppreference.com/w/c/language/operator_precedence
typedef struct TokenType_array mut_TokenType_array |
The constant PADDING_TokenType_ARRAY
= 0
defines how many items are physically available after those valid elements.
This can be used to avoid special cases near the end when searching for fixed-length sequences in the array, although you have to set them to 0
or other appropriate value.
typedef struct TokenType_array * mut_TokenType_array_mut_p |
typedef struct TokenType_array_mut_slice mut_TokenType_array_mut_slice |
A slice of an array where the elements are mutable. Example:
typedef struct TokenType_array_mut_slice * mut_TokenType_array_mut_slice_mut_p |
typedef struct TokenType_array_mut_slice mut_TokenType_array_mut_slice_p |
typedef struct TokenType_array mut_TokenType_array_p |
typedef struct TokenType_array_slice mut_TokenType_array_slice |
typedef struct TokenType_array_slice * mut_TokenType_array_slice_mut_p |
typedef struct TokenType_array_slice mut_TokenType_array_slice_p |
typedef enum TokenType * mut_TokenType_mut_p |
typedef enum TokenType mut_TokenType_p |
typedef size_t SrcIndexType |
typedef uint32_t SrcLenType |
typedef const struct TokenType_array TokenType_array |
typedef const struct TokenType_array * const * TokenType_array_mut_p |
typedef struct TokenType_array_mut_slice TokenType_array_mut_slice |
A slice of an array where the elements are constants. Example:
typedef struct TokenType_array_mut_slice * const * TokenType_array_mut_slice_mut_p |
typedef struct TokenType_array_mut_slice * const TokenType_array_mut_slice_p |
typedef const struct TokenType_array * const TokenType_array_p |
typedef const struct TokenType_array_slice TokenType_array_slice |
typedef const struct TokenType_array_slice * const * TokenType_array_slice_mut_p |
typedef const struct TokenType_array_slice * const TokenType_array_slice_p |
typedef enum TokenType * const * TokenType_mut_p |
typedef enum TokenType * const TokenType_p |
typedef enum UTF8Error * UTF8Error_p |
enum TokenType |
These token types loosely correspond to those in the C grammar.
Keywords: https://en.cppreference.com/w/c/keyword
Operator precedence levels: https://en.cppreference.com/w/c/language/operator_precedence
Enumerator | |
---|---|
T_NONE | No token, used as marker for uninitialized data. |
T_IDENTIFIER | Identifier. See |
T_TYPE | Type name: |
T_TYPE_STRUCT | Type name: |
T_TYPE_QUALIFIER | Type qualifier: |
T_TYPE_QUALIFIER_AUTO | Type qualifier: |
T_TYPEDEF | Type definition: |
T_CONTROL_FLOW_IF | Control flow keyword: |
T_CONTROL_FLOW_LOOP | Control flow keyword: |
T_CONTROL_FLOW_SWITCH | Control flow keyword: |
T_CONTROL_FLOW_CASE | Control flow keyword: |
T_CONTROL_FLOW_BREAK | Control flow keyword: |
T_CONTROL_FLOW_CONTINUE | Control flow keyword: |
T_CONTROL_FLOW_RETURN | Control flow keyword: |
T_CONTROL_FLOW_GOTO | Control flow keyword: |
T_CONTROL_FLOW_LABEL | Control flow, label for |
T_NUMBER | Number, either integer or float. See |
T_STRING | String including the quotes: |
T_CHARACTER | Character including the apostrophes: |
T_SPACE | Whitespace, a block of |
T_COMMENT | Comment block or line. |
T_PREPROCESSOR | Preprocessor directive. |
T_GENERIC_MACRO | Generic macro. |
T_BLOCK_START | Start of a block: |
T_BLOCK_END | End of a block: |
T_TUPLE_START | Start of a tuple: |
T_TUPLE_END | End of a tuple: |
T_INDEX_START | Start of an array index: |
T_INDEX_END | End of an array index: |
T_GROUP_START | Invisible grouping of tokens, for instance for operator precedence. |
T_GROUP_END | End invisible grouping of tokens. |
T_OP_1 |
|
T_OP_2 |
|
T_OP_3 |
|
T_OP_4 |
|
T_OP_5 |
|
T_OP_6 |
|
T_OP_7 |
|
T_OP_8 |
|
T_OP_9 |
|
T_OP_10 |
|
T_OP_11 |
|
T_OP_12 |
|
T_OP_13 |
|
T_OP_14 |
|
T_COMMA |
|
T_SEMICOLON | End of line: |
T_LABEL_COLON | Colon after label: |
T_BACKSTITCH | Backstitch: |
T_ELLIPSIS | Ellipsis: |
T_OTHER | Other token that is not part of the C grammar. |
enum UTF8Error |
|
static |
Append the given insert
slice to the array. Same as splice_Byte_array(_, _->len, 0, NULL, insert)
. The insert
slice, must belong to a different array.
|
static |
Append the given insert
slice to the array. Same as splice_Marker_array(_, _->len, 0, NULL, insert)
. The insert
slice, must belong to a different array.
|
static |
Append the given insert
slice to the array. Same as splice_TokenType_array(_, _->len, 0, NULL, insert)
. The insert
slice, must belong to a different array.
|
static |
Make it be a valid C string, by adding a ‘’\0'character after the last valid element, without increasing the
.len` value. It first makes sure there is at least one extra byte after the array contents in memory, by increasing the .capacity
if needed, and then sets that byte to 0
. Returns the pointer _->start
which now can be used as a C string as long as you don’t modify it.
|
static |
Returns the time in seconds, as a double precision floating point value.
|
static |
Return the slice for the whole array of const objects.
|
static |
Return the slice for the whole array of const objects.
|
static |
Return the slice for the whole array of mutable objects.
|
static |
Return the slice for the whole array of mutable objects.
|
static |
Return the slice for the whole array of mutable objects.
|
static |
Return the slice for the whole array of const objects.
Match a character literal. Assumes end
> start
.
Match a comment block. Assumes end
> start
.
|
inlinestatic |
Count appearances of the given byte in a marker.
|
static |
Call print_markers()
in an area around the given cursor.
|
inlinestatic |
Decode one Unicode® code point from a UTF-8 byte buffer. Assumes end
> cursor
.
|
static |
Delete delete
elements from the array at position
. Same as splice_Byte_array(_, position, delete, NULL, ( Byte_array_slice){0})
.
|
static |
Delete delete
elements from the array at position
. Same as splice_Marker_array(_, position, delete, NULL, ( Marker_array_slice){0})
.
|
static |
Delete delete
elements from the array at position
. Same as splice_TokenType_array(_, position, delete, NULL, ( TokenType_array_slice){0})
.
|
static |
Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_Byte_array()
.
|
static |
|
static |
Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_Marker_array()
.
|
static |
|
static |
Release any resources allocated for this struct.
Safe to call also for objects initialized as views over constants with init_from_constant_TokenType_array()
.
|
static |
|
static |
Return a pointer to the next byte after the last element.
|
static |
Return a pointer to the next byte after the last element.
|
static |
Return a pointer to the next byte after the last element.
|
static |
Return a pointer to the next byte after the last element.
|
static |
Return a pointer to the next byte after the last element.
|
static |
Return a pointer to the next byte after the last element.
|
static |
Make sure that the array is ready to hold minimum
elements, resizing the array if needed.
|
static |
Make sure that the array is ready to hold minimum
elements, resizing the array if needed.
|
static |
Make sure that the array is ready to hold minimum
elements, resizing the array if needed.
|
static |
Same as fprintf(stderr, fmt, ...)
but converting UTF-8 characters to Latin-1 if the LANG
environment variable does not contain UTF-8
.
|
static |
|
static |
Copy the characters between start
and end
into the given Byte array, appending them to the end of that Byte array. If you want to replace any previous content, do string.len = 0;
before calling this function.
To extract the text for Marker_p m
from Byte_p src
:
If you want string.start to be a zero-terminated C string:
or use as_c_string(mut_Byte_array_p _)
.
[in] | start | marker pointer. |
[in] | end | marker pointer. |
[in] | src | byte buffer with the source code. |
[out] | string | Byte buffer to receive the bytes copied from the segment. |
|
inlinestatic |
Find end of block that contains cursor
, looking forward no further than right before end
.
|
inlinestatic |
Find start of block that contains cursor
, looking back no further than start
.
|
inlinestatic |
Find end of line that contains cursor
, looking forward no further than right before end
.
|
inlinestatic |
Find start of line that contains cursor
, looking back no further than start
.
|
inlinestatic |
starting at cursor
, which should point to an opening fence {
, [
or (
, advance until the corresponding closing fence }
, ]
or )
is found, then return that address. If the fences are not closed, the return value is ènd
and an error message is stored in err
.
|
static |
Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_Byte_array(_); free(_);
.
Safe to call also for objects initialized as views over constants with init_from_constant_Byte_array()
.
|
static |
Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_Marker_array(_); free(_);
.
Safe to call also for objects initialized as views over constants with init_from_constant_Marker_array()
.
|
static |
Delete this heap-allocated struct, and release any resources allocated for it.
Same as destruct_TokenType_array(_); free(_);
.
Safe to call also for objects initialized as views over constants with init_from_constant_TokenType_array()
.
|
static |
Return a pointer to the element at position
. Panics if the index is out of range.
|
static |
Return a pointer to the element at position
. Panics if the index is out of range.
|
static |
Return a mutable pointer to the element at position
. Panics if the index is out of range.
|
static |
Return a mutable pointer to the element at position
. Panics if the index is out of range.
|
static |
Return a mutable pointer to the element at position
. Panics if the index is out of range.
|
static |
Return a pointer to the element at position
. Panics if the index is out of range.
|
inlinestatic |
Check whether a given byte appears in a marker. It is faster than count_appearances(byte, marker, marker+1, src) != 0
.
Match an identifier. Assumes end
> start
.
|
static |
Indent by the given number of spaces, for the next eprint()
or fprintf(stder, …)
.
|
static |
Extract the indentation of the line for the character at index
, including the preceding LF
character if it exists.
|
static |
Return the index for the given pointer.
|
static |
Return the index for the given pointer.
|
static |
Return the index for the given pointer.
|
static |
Initialize the array at the given pointer.
For local variables, use it like this:
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
|
static |
Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:
|
static |
Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:
|
static |
Initialize the array at the given pointer, as a view into a constant C array.
Can be used for copy-on-write strings:
|
static |
Initialize a marker with the given values.
|
static |
Initialize the array at the given pointer.
For local variables, use it like this:
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
|
static |
Initialize the array at the given pointer.
For local variables, use it like this:
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
|
static |
Initialize the slice to point at (*array_p)[start
...end
]. end
can be 0, in which case the slice extends to the end of array_p
.
Match a keyword or identifier.
[in] | start | of source code segment to search in. |
[in] | end | of source code segment. |
See enum TokenType
for a list of keywords.
|
static |
Compute the line number in the current state of the file.
int main | ( | int | argc, |
char ** | argv | ||
) |
|
static |
Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:
|
static |
Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:
|
static |
Transfer ownership of any resources allocated for this struct. This just indicates that the caller is no longer responsible for releasing those resources.
Example:
|
static |
Heap-allocate and initialize a mut_Byte_array.
|
static |
Heap-allocate and initialize a mut_Byte_array.
|
static |
Build a new marker for the given string, pointing to its first appearance in src
. If not found, append the text to src
and return a marker poiting there.
|
static |
Heap-allocate and initialize a mut_Marker_array.
|
static |
Heap-allocate and initialize a mut_Marker_array.
|
static |
Heap-allocate and initialize a mut_TokenType_array.
|
static |
Heap-allocate and initialize a mut_TokenType_array.
Match a number. This matches invalid numbers like 3.4.6, 09, and 3e23.48.34e+11. See ISO/IEC 9899:TC3 6.4.8 “Preprocessing numbers”. Rejecting that is left to the compiler. Assumes end
> start
.
|
static |
Compute the line number in the original file.
Fallback match, just read one UTF-8 Unicode® Code Point as one token of type T_OTHER
. Assumes end
> start
.
|
static |
Parse the given source code into the markers
array, appending the new markers to whatever was already there.
The file must contain #pragma Cedro x.y
with x
as the major and y
as the minor revision. Everything up to that marker is output verbatim without any processing, so standard C files are by default not modified.
Remember to empty the markers
array before calling this function if you are re-parsing from scratch.
|
static |
Remove the element at the end/top of the array, copying its bits into *item_p
unless item_p
is 0
, in which case destruct_Byte_block() is called on those elements.
|
static |
Remove the element at the end/top of the array, copying its bits into *item_p
unless item_p
is 0
, in which case destruct_Marker_block() is called on those elements.
|
static |
Remove the element at the end/top of the array, copying its bits into *item_p
unless item_p
is 0
, in which case destruct_TokenType_block() is called on those elements.
Match a pre-processor directive. Assumes end
> start
.
|
static |
Print an error produced when reading a file.
|
static |
Print a human-legible dump of the markers array to stderr. Ignores the options about showing spaces/comments: it is meant as a raw display of the markers array.
[in] | markers | parsed program. |
[in] | src | original source code. |
[in] | prefix | string to be added at the beginning of the line. |
[in] | start | index to start with. |
[in] | end | index to end with: if 0 , use the end of the array. |
|
static |
Push a bit copy of the element on the end/top of the array, resizing the array if needed.
|
static |
Append a formatted C string to the end of the given buffer. It’s the same as printf(...), only the result is stored instead of printed to stdout.
|
static |
Push a bit copy of the element on the end/top of the array, resizing the array if needed.
|
static |
Append the C string bytes to the end of the given buffer.
|
static |
Push a bit copy of the element on the end/top of the array, resizing the array if needed.
|
static |
Read a file into the given buffer. Returns error code, 0 if it succeeds.
|
static |
Get new slice for the given marker.
Match whitespace: one or more space, TAB
, CR
, or NL
characters. Assumes end
> start
.
|
static |
Splice the given insert
slice in place of the removed elements, resizing the array if needed. Starting at position
, delete
elements are deleted and the elements in the insert
slice are inserted there as bit copies. If deleted
is not NULL
, the deleted elements are not destroyed but copied to that array. The insert
slice must belong to a different array or be empty.
|
static |
Splice the given insert
slice in place of the removed elements, resizing the array if needed. Starting at position
, delete
elements are deleted and the elements in the insert
slice are inserted there as bit copies. If deleted
is not NULL
, the deleted elements are not destroyed but copied to that array. The insert
slice must belong to a different array or be empty.
|
static |
Splice the given insert
slice in place of the removed elements, resizing the array if needed. Starting at position
, delete
elements are deleted and the elements in the insert
slice are inserted there as bit copies. If deleted
is not NULL
, the deleted elements are not destroyed but copied to that array. The insert
slice must belong to a different array or be empty.
|
inlinestatic |
Check whether the text in a marker is the same as the given string.
|
static |
Return a pointer to the start of the array (same as _->start
)
|
static |
Return a pointer to the start of the array (same as _->start
)
|
static |
Return a pointer to the start of the array (same as _->start
)
|
static |
Return a pointer to the start of the array (same as _->start
)
|
static |
Return a pointer to the start of the array (same as _->start
)
|
static |
Return a pointer to the start of the array (same as _->start
)
Match a string literal. Assumes end
> start
.
|
static |
Tabulate to the given number of spaces, for the next eprint()
or fprintf(stder, …)
.
|
static |
Format the markers back into source code form.
[in] | markers | tokens for the current form of the program. |
[in] | src | original source code, with any new tokens appended. |
[in] | original_src_len | original source code length. |
[in] | src_file_name | file name corresponding to src . |
[in] | options | formatting options. |
[in] | out | FILE pointer where the source code will be written. |
bool utf8_error | ( | UTF8Error | err | ) |
|
static |
|
static |
|
static |
|
static |
Tabulator position when printing markers in print_markers()
.
|
static |
|
static |
|
static |
|
static |
Right margin position for the newline escapes in block macros.
|
static |
ISO/IEC 9899:TC3 WG14/N1256 §6.7.8 page 126: “14 An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.” http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf#138
|
static |
|
static |
|
static |