Skip to content

Token

Token structure produced my the tokenizer.

Properties

struct {
  token: Tag
  location: Location
}

Location

Properties

struct {
  start: usize
  end: usize
}

Tag

Properties

enum {
  identifier
  value
  value_int
  eof
  invalid
}

Location

Properties

struct {
  start: usize
  end: usize
}

Tag

Properties

enum {
  identifier
  value
  value_int
  eof
  invalid
}

Offset

Index used to know token starts and ends.

u32

TokenIndex

Index used to know token tags.

u32

TokenList

MultiArrayList used to generate the neccessary information for the parser to use.

std.MultiArrayList(struct {
    tag: Token.Tag,
    start: Offset,
    end: Offset,
})

Tokenizer

Tokenizer that will produce lexicar tokens so that the parser can consume and load it to the EnvMap.

Properties

struct {
  /// The source that will be used to produce tokens.
  buffer: [:0]const u8
  /// Current index into the source
  index: usize
}

Init

Sets the initial state.

Signature

pub fn init(source: [:0]const u8) Tokenizer

Next

Advances the tokenizer's state and produces a single token.

Signature

pub fn next(self: *Tokenizer) Token

ParserEnv

Parses the enviroment variables strings and loads them into a EnvMap.

Properties

struct {
  /// Slice of produced token tags from the tokenizer.
  token_tags: []const Token.Tag
  /// Slice of produced start indexes the tokenizer.
  starts: []const Offset
  /// Slice of produced end indexes from the tokenizer.
  ends: []const Offset
  /// The current index in any of the previous slices.
  token_index: TokenIndex
  /// The source that will be used to load values from.
  source: []const u8
  /// The enviroment map that will be used to load the variables to.
  env_map: *EnvMap
}

ParseAndLoad

Parses all token tags and loads the all into the EnvMap.

Signature

pub fn parseAndLoad(self: *ParserEnv) !void

ParseAndLoadOne

Parses a single line and load it to memory. IDENT -> VALUE/VALUE_INT

Signature

pub fn parseAndLoadOne(self: *ParserEnv) (Allocator.Error || error{UnexpectedToken})!void

ParseIdentifier

Parses the identifier token. Returns and error if the current token is not a identifier one.

Signature

pub fn parseIdentifier(self: *ParserEnv) error{UnexpectedToken}!TokenIndex

ParseIntValue

Parses the value_int token. Returns null if the current token is not a value_int one.

Signature

pub fn parseIntValue(self: *ParserEnv) ?TokenIndex

ParseValue

Parses the value or value_int token. Returns and error if the current token is not a value or value_int one.

Signature

pub fn parseValue(self: *ParserEnv) error{UnexpectedToken}!TokenIndex

ParseToEnviromentVariables

Parses and loads all possible enviroment variables from the provided source.

Can error if the parser encounters unexpected token values.

Signature

pub fn parseToEnviromentVariables(
    allocator: Allocator,
    source: [:0]const u8,
    env_map: *EnvMap,
) (Allocator.Error || error{UnexpectedToken})!void