Skip to content

Literal

xtay2 edited this page Mar 15, 2023 · 7 revisions

Introduction

The Literal represents a terminal string in an EBNF which is a symbol that cannot be further decomposed into smaller sections. To initialise it, call the constructor with a literal String. It gets used for all kinds of symbols and keywords.

Constructors

  1. Literal(char literal):
    • Converts the char to a string
    • Calls constructor 3.
  2. Literal(Function<String, TerminalToken> tokenFactory, char literal):
    • Converts the char to a string
    • Calls constructor 4.
  3. Literal(String literal):
    • Strips the literal
    • tokenize() Produces a TerminalToken when matched
  4. Literal(Function<String, TerminalToken> tokenFactory, String literal):
    • Strips the literal
    • tokenize() calls the tokenFactory when matched

Examples

new Literal("abc");

Matches

"abc"
" abc "
"   abc"

Fails

"ab c"
"ab"
"Hello"
Clone this wiki locally