glados-0.1.0.0
Stabilitystable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Parser.Lexer

Description

This module defines the basic building blocks for the parser, including: - Space consumers (handling whitespace and comments) - Lexeme wrappers - Symbol and keyword parsers - Reserved words management

Synopsis

Documentation

type Parser = Parsec Void Text Source #

The standard Parser type for this project.

It uses Void as the custom error component (no custom errors) and DT.Text as the input stream type.

sc :: Parser () Source #

Space Consumer.

Consumes whitespace and ignores comments. Supported comment styles:

  • Line comments starting with //
  • Block comments enclosed in * ... *

lexeme :: Parser a -> Parser a Source #

Wrapper for lexemes.

Consumes trailing whitespace after parsing the given parser p. This is essential for the "trailing whitespace" convention used in this parser.

symbol :: Text -> Parser Text Source #

Parse a fixed string as a symbol.

Consumes the string exactly as matches, followed by whitespace.

pKeyword :: Text -> Parser Text Source #

Parse a specific keyword.

Ensures that the keyword is not followed by an alphanumeric character to prevent partial matches (e.g., matching "if" inside "ifelse").

pIdentifier :: Parser Text Source #

Parse a valid identifier.

An identifier must start with a letter or underscore, followed by alphanumeric characters or underscores.

It fails if the parsed identifier is one of the reservedWords.

parens :: Parser a -> Parser a Source #

Parse content between parentheses (...).

braces :: Parser a -> Parser a Source #

Parse content between braces {...}.

semicolon :: Parser Text Source #

Parse a semicolon ; symbol.

comma :: Parser Text Source #

Parse a comma , symbol.

colon :: Parser Text Source #

Parse a colon : symbol.

withPos :: Parser Ast -> Parser Ast Source #

Wraps a parser with position information.

Captures the current source position (line, column) before running the parser p, and wraps the resulting AST node in an APos constructor. This allows error reporting to pinpoint the exact location of semantic errors later.

param Parser Ast The parser to wrap. return Parser Ast A parser that returns an APos node containing the original result.