Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
10/**
11 * @file parser.h
12 * @brief Public API for parsing Fun source into bytecode.
13 */
14
15#ifndef FUN_PARSER_H
16#define FUN_PARSER_H
17
18#include "bytecode.h"
19
20/**
21 * @brief Parse a .fun source file and compile it into a bytecode chunk.
22 *
23 * The parser accepts an optional shebang on the first line and supports a
24 * minimal top-level or single-function program model. The returned bytecode
25 * will execute discovered statements (e.g., print) and then halt.
26 *
27 * @param path Filesystem path to the .fun source file. Must be a
28 * null-terminated UTF-8 string.
29 * @return Newly allocated Bytecode instance on success, or NULL on error.
30 */
32
33/**
34 * @brief Parse source from a provided string buffer (REPL/tests helper).
35 *
36 * @param source Null-terminated Fun program text.
37 * @return Newly allocated Bytecode instance on success, or NULL on error.
38 */
39Bytecode *parse_string_to_bytecode(const char *source);
40
41/**
42 * @brief Retrieve information about the last parser error, if any.
43 *
44 * @param msgBuf Output buffer to receive a human-readable error message.
45 * @param msgCap Capacity of msgBuf in bytes.
46 * @param outLine Optional output: 1-based line number where the error occurred.
47 * @param outCol Optional output: 1-based column number where the error occurred.
48 * @return 1 if an error was present and fields were populated, 0 if there is
49 * no recorded error.
50 */
51int parser_last_error(char *msgBuf, unsigned long msgCap, int *outLine, int *outCol);
52
53#endif
Definitions for the Fun VM bytecode: opcodes, instruction format, and bytecode container API.
char * path
Definition download.c:43
Bytecode * parse_string_to_bytecode(const char *source)
Parse source from a provided string buffer (REPL/tests helper).
Definition parser.c:7711
int parser_last_error(char *msgBuf, unsigned long msgCap, int *outLine, int *outCol)
Retrieve information about the last parser error, if any.
Definition parser.c:7767
Bytecode * parse_file_to_bytecode(const char *path)
Parse a .fun source file and compile it into a bytecode chunk.
Definition parser.c:7526