read.h 2.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Cherry programming language
 * Copyright (C) 2013 Christoph Mueller
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "cherry/runtime.h"
#include <stdlib.h>
#include <stdint.h>

25
struct org_cherry_array;
26

27
28
29
#define CY_DEFAULT 0
#define CY_SUPRESS_COMMENTS 1

30
struct org_cherry_context {
31
  const char* filename;
32
33
  const cy_byte_t* begin;  
  const cy_byte_t* src;
34
  uint32_t line;
35
  struct org_cherry_array* buffer;
36
  cy_flags_t flags;
37
38
39
};


40
41
struct org_cherry_context*   org_cherry_context(const cy_byte_t* source, const char* filename, cy_flags_t flags);
struct org_cherry_context*   org_cherry_context_repl(const cy_byte_t* source);
42
void                         org_cherry_context_repl_set_source(struct org_cherry_context* c, const cy_byte_t* source);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

void                         org_cherry_error(struct org_cherry_context* context, const char* format, ...);

enum org_cherry_tok {
  TOK_EOF,
  TOK_ROUNDLEFTBRACE,
  TOK_ROUNDRIGHTBRACE,
  TOK_SQUARELEFTBRACE,
  TOK_SQUARERIGHTBRACE,
  TOK_COMMENT,
  TOK_DOT,
  TOK_STRING,
  TOK_CHAR,
  TOK_HEX,
  TOK_DEC,
  TOK_OCT,
  TOK_BIN,
  TOK_FLOAT,
  TOK_SYMBOL,
  TOK_TRUE,
  TOK_FALSE,
  TOK_QUOTE
};


68
const cy_byte_t*       		org_cherry_tok_to_string(enum org_cherry_tok token);
69
70

enum org_cherry_tok     	org_cherry_lex(struct org_cherry_context* context);
71
const cy_byte_t*            org_cherry_pos(struct org_cherry_context* context);
72
void                        org_cherry_rewind(struct org_cherry_context* context, const cy_byte_t* pos);
73

74
const cy_byte_t*       		org_cherry_token_string(struct org_cherry_context* context);
75
76
77
size_t              		org_cherry_token_length(struct org_cherry_context* context);

struct org_cherry_value*    org_cherry_read(struct org_cherry_context* context);