Skip to content

Commit 83df165

Browse files
committed
1 parent faaa4c3 commit 83df165

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+25836
-0
lines changed

src/main/c/yarp/src/yarp/ast.h

Lines changed: 981 additions & 0 deletions
Large diffs are not rendered by default.

src/main/c/yarp/src/yarp/diagnostic.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "diagnostic.h"
2+
3+
// Append an error to the given list of diagnostic.
4+
void
5+
yp_diagnostic_list_append(yp_list_t *list, const char *start, const char *end, const char *message) {
6+
yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) malloc(sizeof(yp_diagnostic_t));
7+
*diagnostic = (yp_diagnostic_t) { .start = start, .end = end, .message = message };
8+
yp_list_append(list, (yp_list_node_t *) diagnostic);
9+
}
10+
11+
// Deallocate the internal state of the given diagnostic list.
12+
void
13+
yp_diagnostic_list_free(yp_list_t *list) {
14+
yp_list_node_t *node, *next;
15+
16+
for (node = list->head; node != NULL; node = next) {
17+
next = node->next;
18+
19+
yp_diagnostic_t *diagnostic = (yp_diagnostic_t *) node;
20+
free(diagnostic);
21+
}
22+
}

src/main/c/yarp/src/yarp/diagnostic.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef YARP_DIAGNOSTIC_H
2+
#define YARP_DIAGNOSTIC_H
3+
4+
#include <stdlib.h>
5+
#include "util/yp_list.h"
6+
7+
// This struct represents a diagnostic found during parsing.
8+
typedef struct {
9+
yp_list_node_t node;
10+
const char *start;
11+
const char *end;
12+
const char *message;
13+
} yp_diagnostic_t;
14+
15+
// Append a diagnostic to the given list of diagnostics.
16+
void
17+
yp_diagnostic_list_append(yp_list_t *list, const char *start, const char *end, const char *message);
18+
19+
// Deallocate the internal state of the given diagnostic list.
20+
void
21+
yp_diagnostic_list_free(yp_list_t *list);
22+
23+
#endif

src/main/c/yarp/src/yarp/enc/ascii.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "yp_encoding.h"
2+
3+
// Each element of the following table contains a bitfield that indicates a
4+
// piece of information about the corresponding ASCII character.
5+
static unsigned char yp_encoding_ascii_table[256] = {
6+
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
7+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 0x
8+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 1x
9+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 2x
10+
0b010, 0b010, 0b010, 0b010, 0b010, 0b010, 0b010, 0b010, 0b010, 0b010, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 3x
11+
0b000, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, // 4x
12+
0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b111, 0b000, 0b000, 0b000, 0b000, 0b000, // 5x
13+
0b000, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, // 6x
14+
0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b011, 0b000, 0b000, 0b000, 0b000, 0b000, // 7x
15+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 8x
16+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // 9x
17+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Ax
18+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Bx
19+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Cx
20+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Dx
21+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Ex
22+
0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, 0b000, // Fx
23+
};
24+
25+
__attribute__((__visibility__("default"))) extern size_t
26+
yp_encoding_ascii_alpha_char(const char *c) {
27+
const unsigned char v = *c;
28+
return (yp_encoding_ascii_table[v] & YP_ENCODING_ALPHABETIC_BIT) ? 1 : 0;
29+
}
30+
31+
__attribute__((__visibility__("default"))) extern size_t
32+
yp_encoding_ascii_alnum_char(const char *c) {
33+
const unsigned char v = *c;
34+
return (yp_encoding_ascii_table[v] & YP_ENCODING_ALPHANUMERIC_BIT) ? 1 : 0;
35+
}
36+
37+
__attribute__((__visibility__("default"))) extern bool
38+
yp_encoding_ascii_isupper_char(const char *c) {
39+
const unsigned char v = *c;
40+
return (yp_encoding_ascii_table[v] & YP_ENCODING_UPPERCASE_BIT) ? true : false;
41+
}

0 commit comments

Comments
 (0)