Skip to content

argv_parser.h#

Command-line arguments parser.

Authors#

TheSilvered


Structs#

Nst_CLArgs#

Synopsis:

typedef struct _Nst_CLArgs {
    bool print_tokens, print_ast, print_instructions, print_bytecode;
    bool force_execution;
    bool no_default;
    u8 opt_level;
    Nst_EncodingID encoding;
    i32 args_start;
    i32 argc;
    char **argv;
    char *command, *filename;
} Nst_CLArgs

Description:

A structure representing the command-line arguments of Nest.

Note

command and filename cannot both be set.

Fields:

  • print_tokens: whether the tokens of the program should be printed
  • print_ast: whether the AST of the program should be printed
  • print_instructions: whether the instructions of the program should be printed
  • print_bytecode: whether the bytecode of the program should be printed
  • force_execution: whether to execute the program when print_tokens, print_ast or print_bytecode are true
  • encoding: the encoding of the file to open, ignored if it is passed through the command
  • no_default: whether to initialize the program with default variables such as true, false, Int, Str etc...
  • opt_level: the optimization level of the program 0 through 3
  • command: the code to execute passed as a command line argument
  • filename: the file to execute
  • args_start: the index where the arguments for the Nest program start

Functions#

Nst_cl_args_init#

Synopsis:

void Nst_cl_args_init(Nst_CLArgs *args, int argc, char **argv)

Description:

Initialize a Nst_CLArgs struct with default values.

Parameters:

  • args: the struct to initialize
  • argc: the number of arguments passed to main
  • argv: the array of arguments passed to main

Nst_cl_args_parse#

Synopsis:

i32 Nst_cl_args_parse(Nst_CLArgs *cl_args)

Description:

Parse command-line arguments.

Parameters:

  • cl_args: the struct where to put the parsed arguments, it must be initialized with Nst_cl_args_init

Returns:

-1 on failure, 0 on success where the program can continue, 1 on success when the program should stop because an info message was printed.


Nst_supports_color#

Synopsis:

bool Nst_supports_color(void)

Returns:

true if ANSI escapes are supported on the current console and false otherwise.


_Nst_supports_color_override#

Synopsis:

void _Nst_supports_color_override(bool value)

Description:

Overrides the value returned by Nst_supports_color.


_Nst_wargv_to_argv#

Synopsis:

bool _Nst_wargv_to_argv(int argc, wchar_t **wargv, char ***argv)

Description:

WINDOWS ONLY Re-encode Unicode (UTF-16) arguments to UTF-8.

Parameters:

  • argc: the length of wargv
  • wargv: the arguments given
  • argv: the pointer where the re-encoded arguments are put

Returns:

true on success and false on failure. No error is set.


_Nst_console_mode_init#

Synopsis:

void _Nst_console_mode_init(void)

Description:

WINDOWS ONLY Initialize the console.