Skip to content

Lexer — Tokens

tokenize(source) scans a FEEL source string and returns a flat Token[] array. The final token is always EOF.

Token shape

ts
interface Token {
  type: TokenType;
  value: string;   // raw matched text ('' for EOF)
  start: number;   // inclusive byte offset
  end: number;     // exclusive byte offset
}

Token types

TokenTypeExampleNotes
Number42, 3.14, .5, 1e3Raw string — converted to Decimal by the evaluator
String"hello"Includes surrounding quotes
Booleantrue, false
Nullnull
Namescore, MonthlyIdentifier fragment
Temporal@"2024-06-15"At-sign + quoted string
Plus+
Minus-
Star*
Slash/
StarStar**Exponentiation
Pipe|>Pipeline operator
Eq=
Neq!=
Lt<
Gt>
Lte<=
Gte>=
Andand
Oror
Notnot
Ifif
Thenthen
Elseelse
Forfor
Inin
Returnreturn
Somesome
Everyevery
Satisfiessatisfies
Functionfunction
Externalexternal
InstanceOfinstanceFollowed by of
Betweenbetween
Letlet
LParen(
RParen)
LBracket[
RBracket]
LBrace{
RBrace}
Comma,
Colon:
Dot.
DotDot..Range separator
Question?Wildcard / pipeline placeholder
At@Temporal prefix
Arrow->
EOF(end)value is ''

Usage

ts
import { tokenize, TokenType } from '@veridtools/feel-parser';

const tokens = tokenize('score >= 700');

for (const tok of tokens) {
  if (tok.type === TokenType.EOF) break;
  console.log(tok.type, JSON.stringify(tok.value));
}
// Name   "score"
// Gte    ">="
// Number "700"

Whitespace

Whitespace is skipped during tokenization — tokens only represent meaningful FEEL symbols. Use start/end offsets to reconstruct positions in the original source if needed.

Released under the MIT License.