Literals

class Literals(integerLiteral: Regex? = Regex("""[-+]?[0-9_]+"""), floatingLiteral: Regex? = Regex("""[-+]?[0-9_]*\.[0-9_]+(?:[eE][-+]?[0-9_]+)?"""), singleLineString: Set<String> = setOf("\"", "\'"), escapeSequences: List<Pair<Regex, (String) -> Char>> = emptyList())(source)

A configuration class to lex literals. There are only three types of literals the lexer manages.

  1. Integer literals are normally lexed with a pure stream of numbers with underscores.

  2. Floating literals are normally lexed with a forced decimal point with optional exponentiation.

  3. String literals are normally lexed exact strings till it finds the original match.

Additionally, escape sequences are required to input special characters inside string literals.

Author

Nishant Aanjaney Jalan

Since

0.1.0

Parameters

integerLiteral

a regex that detects an integer literal.

floatingLiteral

a regex that detects a floating point number literal.

singleLineString

a set of strings that denote the start and end enclosing strings. The lexer will throw a LexicalException when a string literal is not terminated in the same line.

escapeSequences

a list of regex that matches an escape sequence. On match, it will return a Char based on the string matched.

Constructors

Link copied to clipboard
constructor(integerLiteral: Regex? = Regex("""[-+]?[0-9_]+"""), floatingLiteral: Regex? = Regex("""[-+]?[0-9_]*\.[0-9_]+(?:[eE][-+]?[0-9_]+)?"""), singleLineString: Set<String> = setOf("\"", "\'"), escapeSequences: List<Pair<Regex, (String) -> Char>> = emptyList())

creates a configuration of literals for the lexer.