Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
parser.h File Reference

Public API for parsing Fun source into bytecode. More...

#include "bytecode.h"
Include dependency graph for parser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Bytecodeparse_file_to_bytecode (const char *path)
 Parse a .fun source file and compile it into a bytecode chunk.
Bytecodeparse_string_to_bytecode (const char *source)
 Parse source from a provided string buffer (REPL/tests helper).
int parser_last_error (char *msgBuf, unsigned long msgCap, int *outLine, int *outCol)
 Retrieve information about the last parser error, if any.

Detailed Description

Public API for parsing Fun source into bytecode.

Definition in file parser.h.

Function Documentation

◆ parse_file_to_bytecode()

Bytecode * parse_file_to_bytecode(const char *path)

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.

Parameters
pathFilesystem path to the .fun source file. Must be a null-terminated UTF-8 string.
Returns
Newly allocated Bytecode instance on success, or NULL on error.

Parse a .fun source file and compile it into a bytecode chunk.

Reads the file, preprocesses includes (tracking original file paths), resets the global error state, and compiles to Bytecode while attaching source metadata (name, source_file).

Parameters
pathFilesystem path to the source file.
Returns
Bytecode pointer on success; NULL on I/O or parse error.

Definition at line 7529 of file parser.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_string_to_bytecode()

Bytecode * parse_string_to_bytecode(const char *source)

Parse source from a provided string buffer (REPL/tests helper).

Parameters
sourceNull-terminated Fun program text.
Returns
Newly allocated Bytecode instance on success, or NULL on error.

Parse source from a provided string buffer (REPL/tests helper).

Suitable for REPL or tests. Performs include preprocessing with no base path, compiles, and attaches generic source metadata.

Parameters
sourceNUL-terminated source code string.
Returns
Bytecode pointer on success; NULL on parse error.

Definition at line 7714 of file parser.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parser_last_error()

int parser_last_error(char *msgBuf,
unsigned longmsgCap,
int *outLine,
int *outCol )

Retrieve information about the last parser error, if any.

Parameters
msgBufOutput buffer to receive a human-readable error message.
msgCapCapacity of msgBuf in bytes.
outLineOptional output: 1-based line number where the error occurred.
outColOptional output: 1-based column number where the error occurred.
Returns
1 if an error was present and fields were populated, 0 if there is no recorded error.

Retrieve information about the last parser error, if any.

Copies the error message into msgBuf (truncated to msgCap-1), and returns the one-based line and column where available. If no error is pending, returns 0 and leaves outputs unchanged.

Parameters
msgBufDestination buffer for the error message (may be NULL).
msgCapCapacity of msgBuf in bytes.
outLineOptional out param for one-based line number.
outColOptional out param for one-based column number.
Returns
1 if an error was available and copied, 0 otherwise.

Definition at line 7770 of file parser.c.

Here is the caller graph for this function: