libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Macros | Functions | Variables
lexer.c File Reference
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <ctype.h>
#include "frontend/lexer/lexer.h"
#include "frontend/lexer/token.h"
#include "util/arena.h"
#include "error/error.h"
#include "util/mtrack.h"
#include "token_type_keyword.h"
#include "token_type_symbols_operators.h"

Go to the source code of this file.

Macros

#define ENUM(type, keyword)   {keyword, sizeof(keyword) - 1, type},
 
#define ENUM(type, _, token)   {token, sizeof(token) - 1, type},
 

Functions

bool ps_lexer_is_eof (void)
 Checks whether the lexer is at the end of input.
 
void ps_lexer_advance (void)
 Advances past one character in the lexer.
 
void ps_lexer_advance_n (usize n)
 Advances past the next n characters in the lexer, updating internal state as necessary.
 
void ps_add_token (enum ps_token_type type, usize length)
 
void ps_add_token_with_loc (enum ps_token_type type, usize length, struct ps_loc loc)
 
struct ps_token_arr * ps_lex (const struct ps_file_ctx *file_ctx)
 Lexes the given source code into tokens.
 

Variables

struct ps_lexer_state lexer
 

Macro Definition Documentation

◆ ENUM [1/2]

#define ENUM (   type,
  _,
  token 
)    {token, sizeof(token) - 1, type},

◆ ENUM [2/2]

#define ENUM (   type,
  keyword 
)    {keyword, sizeof(keyword) - 1, type},

Function Documentation

◆ ps_add_token()

void ps_add_token ( enum ps_token_type  type,
usize  length 
)
inline

Definition at line 477 of file lexer.c.

◆ ps_add_token_with_loc()

void ps_add_token_with_loc ( enum ps_token_type  type,
usize  length,
struct ps_loc  loc 
)

Definition at line 482 of file lexer.c.

◆ ps_lex()

struct ps_token_arr * ps_lex ( const struct ps_file_ctx file_ctx)

Lexes the given source code into tokens.

Parameters
file_ctxThe file contents and filename.

Definition at line 559 of file lexer.c.

◆ ps_lexer_advance()

void ps_lexer_advance ( void  )

Advances past one character in the lexer.

Additionally handles internal state updates. For example, encountering a newline causes the lexer to reset its column counter and increment its line counter.

Precondition
The lexer is not at the end of file.

Definition at line 230 of file lexer.c.

◆ ps_lexer_advance_n()

void ps_lexer_advance_n ( usize  n)
inline

Advances past the next n characters in the lexer, updating internal state as necessary.

See also
ps_lexer_advance()

Definition at line 272 of file lexer.c.

◆ ps_lexer_is_eof()

bool ps_lexer_is_eof ( void  )
inline

Checks whether the lexer is at the end of input.

Definition at line 55 of file lexer.c.

Variable Documentation

◆ lexer

struct ps_lexer_state lexer

Definition at line 13 of file lexer.c.