flx_compiler 0.3.0 copy "flx_compiler: ^0.3.0" to clipboard
flx_compiler: ^0.3.0 copied to clipboard

The flx compiler. Transpiles .flx DSL files into Flutter Dart source, and generates the route table from @page annotations.

flx

flxc #

The compiler for flx. Transpiles .flx into ordinary Flutter Dart, generates the route table, and reports Dart's own type errors against the .flx that produced them.

Command line #

dart pub global activate flxc

flxc build [dir]     # transpile + generate routes  (default: lib/pages)
flxc watch [dir]     # rebuild on change, survives syntax errors
flxc check [dir]     # transpile without writing — for CI
flxc analyze [dir]   # build, then report Dart's type errors on the .flx
flxc file.flx -o out.dart

Errors #

Diagnostics carry a location, a caret and a fix:

error: composable 'greeting' must start with a capital letter
  --> lib/pages/settings.flx:1:12
  |
1 | composable greeting {
  |            ^^^^^^^^
  = hint: it becomes a Dart class, so name it 'Greeting'

flxc analyze extends that to Dart's own errors, which otherwise land in generated files at line numbers corresponding to nothing you wrote. It works by occurrence — code generation emits user identifiers in source order and never reorders them, so the nth foo in the .dart is the nth foo in the .flx. That is a heuristic and reports itself as one: a unique name is certain, a mismatch is labelled located by name, and anything unmappable reports the generated location rather than guessing.

As a library #

import 'package:flx_compiler/flx_compiler.dart';

final source = Source('screen.flx', text);
final ast    = Parser.parse(source);   // throws FlxError
final dart   = CodeGenerator(ast, runtimeImport: 'package:flx_runtime/flx_runtime.dart')
    .generate();

The language server is built entirely on this API, which is the point: the editor and the build agree because they run the same lexer, parser and spans.

Errors are always FlxError, carrying a Span that renders with a caret and a hint. Anything else is a bug.

License #

BSD-3-Clause.

0
likes
140
points
152
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

The flx compiler. Transpiles .flx DSL files into Flutter Dart source, and generates the route table from @page annotations.

Repository (GitHub)
View/report issues

Topics

#flutter #dsl #codegen #compiler

License

BSD-3-Clause (license)

More

Packages that depend on flx_compiler