syntax library
Parse-time AST and parser for Project Fluent.
Imported by tools that walk or transform the source-level AST:
linters, IDE plugins, codegen (fluent_gen), formatters,
translation-memory exporters.
Apps that only format messages at runtime should import
package:fluent_bundle/fluent_bundle.dart instead. The two surfaces are
deliberately separate so apps don't ship the full parse-time AST in
their release binary.
Classes
- Attribute
-
.label = ...attached to a Message or Term. - CallArguments
-
Positional and named arguments to a
TermReferenceorFunctionReference. - Comment
- A comment line in the source. Three levels:
- Entry
- Anything that can appear at the top level of a Resource.
- Expression
-
Anything that can appear inside a
{ ... }placeable. - FluentNode
- Base type for every Fluent Syntax 1.0 AST node.
- FluentParser
- Recursive-descent parser for Fluent Syntax 1.0.
- FluentParserOptions
- Parser configuration.
- FunctionReference
-
A call to a built-in function:
NUMBER($n, style: "currency"). - Identifier
- An identifier — used for message names, term names (without leading dash), attribute names, variant keys, function names, and variable names.
- IdentifierKey
-
A variant key matching by identifier (e.g.
[one],[other],[masculine]). - InlineExpression
- An expression that can sit alone in a pattern or as a selector input.
- Junk
- Source text that failed to parse as an Entry but was preserved so the surrounding entries can still load.
- Literal
- A literal value inside a placeable: string or number.
- Message
-
A regular Fluent message:
id = value, optionally with attributes and a leading comment. - MessageReference
-
A reference to another message:
nameorname.attr. - NamedArgument
-
A
name: valueargument insideCallArguments. - NumberLiteral
-
A numeric literal:
{ 5 },{ 3.14 },{ -7 }. - NumberLiteralExpression
- A numeric literal used as a placeable expression.
- NumberLiteralKey
-
A variant key matching by number literal (e.g.
[1],[3.14]). - Pattern
- A pattern: the value of a Message, Term, or Attribute.
- PatternElement
-
One piece of a Pattern: either a literal text run, or a
{ ... }placeable. - Placeable
-
A
{ ... }placeable. Wraps an Expression and appears in two positions in the AST: - Resource
-
A complete parsed
.ftlfile. - SelectExpression
-
A pattern selection: chooses one of several
[key] patternvariants based on the value of selector. - Span
-
A position in the source text. Inclusive
start, exclusiveend. - StringLiteral
-
A double-quoted string literal:
{ "Hello" }. - StringLiteralExpression
- A double-quoted string literal used as a placeable expression.
- SyntaxNode
- A node that may carry source-position information.
- Term
-
A term:
-id = value, only callable from other patterns via{ -id }. Cannot be displayed directly to the user. - TermReference
-
A reference to a term:
-name,-name.attr, or-name(arg, key: value). - TextElement
- A literal text run inside a pattern.
- VariableReference
-
A reference to an externally-supplied argument:
$name. - Variant
-
One arm of a SelectExpression: a
[key] patternpair. - VariantKey
-
A variant's match key: an Identifier (CLDR plural category like
one/other, or any free-form name) or a NumberLiteral (numeric match).
Enums
- CommentLevel
-
How many
#marks introduced a comment.
Functions
-
unescapeFluentString(
String input) → String - Decodes escape sequences inside a Fluent string-literal value.
Exceptions / Errors
- CallbackParseError
- A spec error raised mid-production with its own code.
- ExpectedCharRangeError
- E0004 — a character in a specific range was expected.
- ExpectedMessageFieldError
- E0005 — a message needs a value or attributes.
- ExpectedTermFieldError
- E0006 — a term needs a value.
- ExpectedTokenError
-
E0003 — a specific token was expected (
=,}, …). - FluentParseError
- A failure during Fluent Syntax parsing.
- InvalidUnicodeEscapeSequenceError
-
E0026 — a malformed
\\uXXXX/\\UXXXXXXescape. - UnbalancedClosingBraceError
-
E0027 — a
}with no matching{. - UnknownEscapeSequenceError
- E0025 — a backslash escape the spec doesn't define.
- UnterminatedStringError
- E0020 — a string literal ran to end of line unterminated.