~emersion/mrsh

ref: 4da12aae651dac2f0c6818f54d5d8b5f0a9e8bf6 mrsh/include/mrsh/parser.h -rw-r--r-- 1.5 KiB
4da12aaeDrew DeVault Implement 'shift' builtin 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef _MRSH_PARSER_H
#define _MRSH_PARSER_H

#include <mrsh/ast.h>
#include <stdio.h>

struct mrsh_parser;

/**
 * An alias callback. The alias named is given as a parameter and the alias
 * value should be returned. NULL should be returned if the alias doesn't exist.
 */
typedef const char *(*mrsh_parser_alias_func_t)(const char *name,
	void *user_data);

struct mrsh_parser *mrsh_parser_create(FILE *f);
struct mrsh_parser *mrsh_parser_create_from_buffer(const char *buf, size_t len);
void mrsh_parser_destroy(struct mrsh_parser *state);
/**
 * Parse a complete multi-line program.
 */
struct mrsh_program *mrsh_parse_program(struct mrsh_parser *state);
/**
 * Parse a program line. Continuation lines are consumed.
 */
struct mrsh_program *mrsh_parse_line(struct mrsh_parser *state);
/**
 * Parse a single word. Continuation lines are consumed.
 */
struct mrsh_word *mrsh_parse_word(struct mrsh_parser *state);
/**
 * Check if the input has been completely consumed.
 */
bool mrsh_parser_eof(struct mrsh_parser *state);
/**
 * Set the alias callback.
 */
void mrsh_parser_set_alias(struct mrsh_parser *state,
	mrsh_parser_alias_func_t alias, void *user_data);
/**
 * Check if the parser ended with a syntax error. The error message is returned.
 * The error position can optionally be obtained.
 */
const char *mrsh_parser_error(struct mrsh_parser *state,
	struct mrsh_position *pos);
/**
 * Check if the input ends on a continuation line.
 */
bool mrsh_parser_continuation_line(struct mrsh_parser *state);

#endif