OpenResty Fanlang™ User Manual
fanlang - A Perl 6 dialect for implementing other DSLs
Table of Contents
$ cat a.fan my $who = "world"; say "hello, $who!" $ fan a.fan hello, world!
Fanlang is a optimizing compiler that converts a dialect of Perl 6 into standalone Lua code targeting OpenResty.
The motivation behind the fanlang compiler are:
We want to be much more productive when writing OpenResty-based software that is not performance sensitive, like a DSL compiler. Perl 6 (or even Perl 5) is much more expressive and much more powerful than Lua, especially for text processing tasks and implementing transcompilers. But Lua has its own strength in performance and simplicity. So we write fanlang that compiles Perl 6 into Lua for OpenResty.
We want the compiling speed or compiler performance to be (much) faster than the counterparts implemented in Perl 5.
Perl 6 features that will never be implemented
- Perl 6 regexes (we use Perl 5 regexes and our own fanlang rule syntax).
Language features incompatible to Perl 6
Fanlang does not support the builtin Perl 6 class
Seq yet. In cases where Rakudo returns a
Seq object, fanlang
List object instead.
Fanlang uses Perl 5 compatible regexes by default in its regexes. This means that the Perl 6 regex adverb
is always in effect in fanlang code. Also, whitespace characters are not significant t in fanlang’s
Perl 5 compatible regexes, unless the regex adverb
:s is specified.
Fanlang uses its own grammar rule syntax inspired by Parse::RecDescent and Pegex.
The “actions” class fed into Grammar objects’
parse() method can inherit from the builtin class
provide useful methods like
get-line() for fetching the current line number in the input being parsed.
FANLANG_DEBUG=1 system environment variable is specified, the fanlang grammar engine will generate
tracing output for debugging parsers written in fanlang.
When an error happens in the
slurp() builtin or a Grammar object’s
parse() method, the corresponding builtin
fanlang routine will not throw an exception like Perl 6, instead, it returns Nil and sets the special variable
$! to the error string.
.gist() output for some primitive values, like
True, are in all lower case, that is,
their gist outputs are
The global variable
@*ARGS() is not allowed to used in any fan source that is imported by
test-regex(regex) subroutine accepts a fanlang string and checks whether it is a valid Perl compatible regex.
True if yes; returns
Nil and sets
$! to the error string otherwise.
Accepts an arbitrary fanlang value as the sole argument. Returns
True when the value is a “primitive value”, e.g.,
a boolean, a number, a string, or just
False otherwise. Neither objects, types, arrays, nor hashes are
considered “primitive values”.
Accepts a fanlang string as a file name. Returns
True when the file exists;
This read-only attribute returns the bare name of the current Attribute object, without the sigil and twigil parts.
Yichun Zhang (agentzh) <firstname.lastname@example.org>
Copyright & Licenses
Copyright (C) 2016-2021, OpenResty Inc. All rights reserved.
This software is proprietary and must not be redistributed or shared at all.