2026-05-01 15:15:42 +02:00
|
|
|
/*
|
2025-09-16 02:11:22 +02:00
|
|
|
* This file is part of the Fun programming language.
|
2025-10-09 01:59:19 +02:00
|
|
|
* https://fun-lang.xyz/
|
2025-09-16 02:11:22 +02:00
|
|
|
*
|
|
|
|
|
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
2025-09-30 22:52:12 +02:00
|
|
|
* Licensed under the terms of the Apache-2.0 license.
|
|
|
|
|
* https://opensource.org/license/apache-2-0
|
2025-09-16 02:11:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2026-05-01 02:20:25 +02:00
|
|
|
* @file parser.h
|
|
|
|
|
* @brief Public API for parsing Fun source into bytecode.
|
2025-09-13 23:50:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef FUN_PARSER_H
|
|
|
|
|
#define FUN_PARSER_H
|
|
|
|
|
|
|
|
|
|
#include "bytecode.h"
|
|
|
|
|
|
2026-05-01 02:20:25 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Parse a .fun source file and compile it into a bytecode chunk.
|
|
|
|
|
*
|
|
|
|
|
* The parser accepts an optional shebang on the first line and supports a
|
|
|
|
|
* minimal top-level or single-function program model. The returned bytecode
|
|
|
|
|
* will execute discovered statements (e.g., print) and then halt.
|
|
|
|
|
*
|
|
|
|
|
* @param path Filesystem path to the .fun source file. Must be a
|
|
|
|
|
* null-terminated UTF-8 string.
|
|
|
|
|
* @return Newly allocated Bytecode instance on success, or NULL on error.
|
|
|
|
|
*/
|
2025-09-13 23:50:01 +02:00
|
|
|
Bytecode *parse_file_to_bytecode(const char *path);
|
|
|
|
|
|
2026-05-01 02:20:25 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Parse source from a provided string buffer (REPL/tests helper).
|
|
|
|
|
*
|
|
|
|
|
* @param source Null-terminated Fun program text.
|
|
|
|
|
* @return Newly allocated Bytecode instance on success, or NULL on error.
|
|
|
|
|
*/
|
2025-09-14 18:42:23 +02:00
|
|
|
Bytecode *parse_string_to_bytecode(const char *source);
|
|
|
|
|
|
2026-05-01 02:20:25 +02:00
|
|
|
/**
|
|
|
|
|
* @brief Retrieve information about the last parser error, if any.
|
|
|
|
|
*
|
|
|
|
|
* @param msgBuf Output buffer to receive a human-readable error message.
|
|
|
|
|
* @param msgCap Capacity of msgBuf in bytes.
|
|
|
|
|
* @param outLine Optional output: 1-based line number where the error occurred.
|
|
|
|
|
* @param outCol Optional output: 1-based column number where the error occurred.
|
|
|
|
|
* @return 1 if an error was present and fields were populated, 0 if there is
|
|
|
|
|
* no recorded error.
|
|
|
|
|
*/
|
2025-09-14 22:35:23 +02:00
|
|
|
int parser_last_error(char *msgBuf, unsigned long msgCap, int *outLine, int *outCol);
|
|
|
|
|
|
2025-09-13 23:50:01 +02:00
|
|
|
#endif
|