lux/macro/syntax

Types

Syntax

A Lux AST syntax parser.

(type: (Syntax a)
  (-> (lux;List lux;AST) (lux/data/error;Error [(lux;List lux;AST) a])))

Macros

syntax:

## A more advanced way to define macros than macro:.
## The inputs to the macro can be parsed in complex ways through the use of syntax parsers.
## The macro body is also (implicitly) run in the Monad<Lux>, to save some typing.
## Also, the compiler state can be accessed through the *compiler* binding.
(syntax: #export (object [#let [imports (class-imports *compiler*)]]
                   [#let [class-vars (list)]]
                   [super (opt (super-class-decl^ imports class-vars))]
                   [interfaces (tuple (some (super-class-decl^ imports class-vars)))]
                   [constructor-args (constructor-args^ imports class-vars)]
                   [methods (some (overriden-method-def^ imports))])
  (let [def-code ($_ Text/append "anon-class:"
                     (spaced (list (super-class-decl$ (lux;defaultobject-super-class super))
                                   (with-brackets (spaced (map super-class-decl$ interfaces)))
                                   (with-brackets (spaced (map constructor-arg$ constructor-args)))
                                   (with-brackets (spaced (map (method-def$ id) methods))))))]
    (wrap (list (` (lux;_lux_proc["jvm" (~ (lux/macro/ast;textdef-code))] []))))))

Structs

Applicative<Syntax>

(lux/control/applicative;Applicative Syntax)

Functor<Syntax>

(lux/control/functor;Functor Syntax)

Monad<Syntax>

(lux/control/monad;Monad Syntax)

Values

(alt p1 p2)

Heterogeneous alternative combinator.

(All [a b] (-> (Syntax a) (Syntax b) (Syntax (| a b))))

any

Just returns the next input without applying any logic.

(Syntax lux;AST)

(assert message test)

Fails with the given message if the test is false.

(-> lux;Text lux;Bool (Syntax lux;Unit))

(at-least n p)

Parse at least N times.

(All [a] (-> lux;Nat (Syntax a) (Syntax (lux;List a))))

(at-most n p)

Parse at most N times.

(All [a] (-> lux;Nat (Syntax a) (Syntax (lux;List a))))

(between from to p)

Parse between N and M times.

(All [a] (-> lux;Nat lux;Nat (Syntax a) (Syntax (lux;List a))))

bool

Parses the next bool input AST.

(Syntax lux;Bool)

(bool! v)

Ensures the given bool is the next input AST.

(-> lux;Bool (Syntax lux;Unit))

(bool? v)

Asks if the given bool is the next input AST.

(-> lux;Bool (Syntax lux;Bool))

char

Parses the next char input AST.

(Syntax lux;Char)

(char! v)

Ensures the given char is the next input AST.

(-> lux;Char (Syntax lux;Unit))

(char? v)

Asks if the given char is the next input AST.

(-> lux;Char (Syntax lux;Bool))

(default value parser)

If the given parser fails, returns the default value.

(All [a] (-> a (Syntax a) (Syntax a)))

(either pl pr)

Homogeneous alternative combinator.

(All [a] (-> (Syntax a) (Syntax a) (Syntax a)))

end

Ensures there are no more inputs.

(Syntax lux;Unit)

end?

Checks whether there are no more inputs.

(Syntax lux;Bool)

(exactly n p)

Parse exactly N times.

(All [a] (-> lux;Nat (Syntax a) (Syntax (lux;List a))))

(fail message)

(All [a] (-> lux;Text (Syntax a)))

(form p)

Parse inside the contents of a form as if they were the input ASTs.

(All [a] (-> (Syntax a) (Syntax a)))

frac

Parses the next frac input AST.

(Syntax lux;Frac)

(frac! v)

Ensures the given frac is the next input AST.

(-> lux;Frac (Syntax lux;Unit))

(frac? v)

Asks if the given frac is the next input AST.

(-> lux;Frac (Syntax lux;Bool))

int

Parses the next int input AST.

(Syntax lux;Int)

(int! v)

Ensures the given int is the next input AST.

(-> lux;Int (Syntax lux;Unit))

(int? v)

Asks if the given int is the next input AST.

(-> lux;Int (Syntax lux;Bool))

(local local-inputs syntax)

Run a syntax parser with the given list of inputs, instead of the real ones.

(All [a] (-> (lux;List lux;AST) (Syntax a) (Syntax a)))

local-symbol

Parse a local symbol (a symbol that has no module prefix).

(Syntax lux;Text)

local-tag

Parse a local tag (a tag that has no module prefix).

(Syntax lux;Text)

(many p)

1-or-more combinator.

(All [a] (-> (Syntax a) (Syntax (lux;List a))))

nat

Parses the next nat input AST.

(Syntax lux;Nat)

(nat! v)

Ensures the given nat is the next input AST.

(-> lux;Nat (Syntax lux;Unit))

(nat? v)

Asks if the given nat is the next input AST.

(-> lux;Nat (Syntax lux;Bool))

neg-int

(Syntax lux;Int)

(not p)

(All [a] (-> (Syntax a) (Syntax lux;Unit)))

(on compiler action)

Run a Lux operation as if it was a Syntax parser.

(All [a] (-> lux;Compiler (lux;Lux a) (Syntax a)))

(opt p)

Optionality combinator.

(All [a] (-> (Syntax a) (Syntax (lux;Maybe a))))

pos-int

(Syntax lux;Int)

real

Parses the next real input AST.

(Syntax lux;Real)

(real! v)

Ensures the given real is the next input AST.

(-> lux;Real (Syntax lux;Unit))

(real? v)

Asks if the given real is the next input AST.

(-> lux;Real (Syntax lux;Bool))

(record p)

Parse inside the contents of a record as if they were the input ASTs.

(All [a] (-> (Syntax a) (Syntax a)))

(run tokens p)

(All [a] (-> (lux;List lux;AST) (Syntax a) (lux/data/error;Error [(lux;List lux;AST) a])))

(sep-by sep p)

Parsers instances of 'p' that are separated by instances of 'sep'.

(All [a b] (-> (Syntax b) (Syntax a) (Syntax (lux;List a))))

(seq p1 p2)

Sequencing combinator.

(All [a b] (-> (Syntax a) (Syntax b) (Syntax [a b])))

(some p)

0-or-more combinator.

(All [a] (-> (Syntax a) (Syntax (lux;List a))))

symbol

Parses the next symbol input AST.

(Syntax lux;Ident)

(symbol! v)

Ensures the given symbol is the next input AST.

(-> lux;Ident (Syntax lux;Unit))

(symbol? v)

Asks if the given symbol is the next input AST.

(-> lux;Ident (Syntax lux;Bool))

tag

Parses the next tag input AST.

(Syntax lux;Ident)

(tag! v)

Ensures the given tag is the next input AST.

(-> lux;Ident (Syntax lux;Unit))

(tag? v)

Asks if the given tag is the next input AST.

(-> lux;Ident (Syntax lux;Bool))

text

Parses the next text input AST.

(Syntax lux;Text)

(text! v)

Ensures the given text is the next input AST.

(-> lux;Text (Syntax lux;Unit))

(text? v)

Asks if the given text is the next input AST.

(-> lux;Text (Syntax lux;Bool))

(tuple p)

Parse inside the contents of a tuple as if they were the input ASTs.

(All [a] (-> (Syntax a) (Syntax a)))