BooleanToken
interface| Package | @formscript/lexer |
|---|---|
| Specification | 3, 3.3, 3.5, 3.6, 3.7, 20 |
| Depends on | ast, errors |
@formscript/lexer
Source text → tokens, per §3 of the specification.
Usage
import { tokenize } from '@formscript/lexer';
const { tokens, diagnostics } = tokenize(source, { file: 'application.forms' });
tokenize never throws. Every problem it finds is a diagnostic:
if (diagnostics.length > 0) {
for (const d of diagnostics) {
console.error(`${d.code} ${d.location?.line}:${d.location?.column} ${d.message}`);
}
}
What it handles
- UTF-8 input, with a byte offset on every span.
- All three comment forms of §3.3 (
#,//,/* … */). - Identifiers, the hard keywords of §3.5 and the soft keywords of §20.
- Every literal kind of §3.6: integers, decimals, strings with the full escape
set, booleans,
null,inapplicable, dates, datetimes and durations. - The punctuation of §3.7, longest-match first.
Notes
- A leading
-is punctuation, not part of a numeric literal. The grammar'sunaryproduction handles the sign, so-1anda - 1are the same token stream. - The duration literal follows the ISO 8601 form of §3.6, including
P1Y2M3DandPT30M, and the short form (30d,6mo,2y). When a short form ends inmand is followed byo, the longer unit wins.
Public API
22 exported symbols.
DateTimeToken
interfaceDateToken
interfaceDurationToken
interfaceEofToken
interfaceHARD_KEYWORDS
re-exportIdentifierToken
interfaceInapplicableToken
interfaceKeywordToken
interface
A hard keyword (§3.5). Soft keywords are lexed as identifiers.
LexLocation
interface
A diagnostic location that also carries the 0-based source offset.
LexOptions
interfaceLexResult
interfaceNullToken
interfaceNumberToken
interfacePunctuation
typePUNCTUATION
re-exportPunctuationToken
interfaceStringToken
interfaceToken
typeTokenBase
interfacetokenize
re-exportTokenKind
type