Native classes — the catalogue

Every pattern in the standard library that needs Java backing is bound to a class under src/main/java/org/modelingvalue/nelumbo/. This page catalogues the shipped native classes, grouped by structural role, with a note on what each one does and how it returns its results.

Read this alongside native-api.md (which describes the API surface) and ../guides/native-cookbook.md (which walks through implementing new ones). This page is the "what's already there" reference.


Package layout

org.modelingvalue.nelumbo.*           base classes and engine
    Node                              base class for AST nodes (values)
    Predicate           (in .logic)   base class for Boolean-producing natives
    CompoundPredicate   (in .logic)   predicate holding sub-predicates
    BinaryPredicate     (in .logic)   two-argument predicate with reduction logic
    Quantifier          (in .logic)   base for E[] and A[]
    InferContext, InferResult         context and result types for infer()

org.modelingvalue.nelumbo.lang        top-level statement forms declared by lang.nl
    Import, Type, Variable, Functor, Transform, Namespace, Parenthesized

org.modelingvalue.nelumbo.patterns    pattern meta-grammar declared by lang.nl
    TokenTextPattern, AlternationPattern, RepetitionPattern,
    OptionalPattern, SequencePattern, NodeTypePattern

org.modelingvalue.nelumbo.logic       Boolean, connectives, quantifiers, equality,
                                       plus the fact/<=>/? statement forms
    NBoolean, Not, And, Or, NIs, Equal, ExistentialQuantifier,
    UniversalQuantifier, Fact, Rule, Query

org.modelingvalue.nelumbo.integers    integer arithmetic
    NInteger, Integers

org.modelingvalue.nelumbo.rationals   exact rational arithmetic
    Rational, Rationals

org.modelingvalue.nelumbo.strings     string operations
    NString, Strings

org.modelingvalue.nelumbo.collections container literals + set-builder + operations
    NSet, NList, SetBuilder, BuildSet, Collections

org.modelingvalue.nelumbo.datetime    ISO 8601 dates, times, date-times, durations
    NDate, NTime, NDateTime, NPeriod, Add, Multiply,
    GreaterThan, IsoDuration

The lang and patterns packages are the natives that back the patterns declared in lang.nl. They implement the bootstrap layer — without them, the hand-coded parser could read lang.nl but no @-bound class would exist to handle the patterns it declares.


Roles

Shipped natives fall into five structural roles. Reading this classification first makes the per-class notes below easier to follow.

Role Base class What it does Example
Constant / literal Node (or Predicate for NBoolean) Parses a source literal into a value object NInteger, NString, Rational, NBoolean
Three-arg functional relation Predicate Relation with one output and one or more inputs; binds the missing one Integers#add/#mult, Rationals#iir, Strings#string_concat/#integer_string
Comparison predicate Predicate Two-arg relation that decides true/false when both sides are known Integers#gt / Rationals#gt, datetime.GreaterThan, Equal, Strings#string_length
Logical connective BinaryPredicate / CompoundPredicate Combines sub-predicate results according to a truth table And, Or, Not
Quantifier Quantifier (extends CompoundPredicate) Evaluates a sub-predicate under many bindings and aggregates ExistentialQuantifier, UniversalQuantifier, BuildSet
Container Node Literal collection of elements NSet, NList

org.modelingvalue.nelumbo.logic

NBoolean

Not

And, Or

NIs

Equal

ExistentialQuantifier, UniversalQuantifier


org.modelingvalue.nelumbo.integers

NInteger

Integers

One class hosts all three integer primitives as @NelumboMethods: add, mult, and gt.


org.modelingvalue.nelumbo.rationals

Rational

Rationals

One class hosts the rational primitives as @NelumboMethods: add, mult, gt, and iir.


org.modelingvalue.nelumbo.strings

NString

Strings

One class hosts all three string primitives as @NelumboMethods: string_concat, string_length, and integer_string.


org.modelingvalue.nelumbo.collections

NSet

NList

SetBuilder

BuildSet

Collections


org.modelingvalue.nelumbo.datetime

NDate, NTime, NDateTime, NPeriod

IsoDuration

Add

Multiply

GreaterThan


Cross-reference — by .nl binding site

This table lets you go from a line in an .nl file to the Java class that implements it.

.nl file Pattern @ binding
lang.nl Namespace ::= ... and RootNamespace ::= { ... } nelumbo.lang.Namespace
lang.nl Pattern ::= <NAME> | <STRING> | <OPERATOR> | ... (literal tokens) nelumbo.patterns.TokenTextPattern
lang.nl Pattern ::= <(> ... <|> ... <)> nelumbo.patterns.AlternationPattern
lang.nl Pattern ::= <(> ... <,> ... <)+/*> nelumbo.patterns.RepetitionPattern
lang.nl Pattern ::= <(> ... <)?> nelumbo.patterns.OptionalPattern
lang.nl Pattern ::= <LEFT> ... <RIGHT> nelumbo.patterns.SequencePattern
lang.nl Pattern ::= "<" (vis/hid)? <Type> (#N)? ">" nelumbo.patterns.NodeTypePattern
lang.nl Root ::= "import" ... nelumbo.lang.Import
lang.nl Root ::= <Root> ::> <RootNamespace> nelumbo.lang.Transform
lang.nl Root ::= (hidden)? <Type> <NAME>, ... nelumbo.lang.Variable
lang.nl Root ::= <NAME> ... :: <Type>, ... nelumbo.lang.Type
lang.nl Root ::= (private)? <Type> ::= <Pattern>+, ... nelumbo.lang.Functor
lang.nl P ::= (<P>) (generic parenthesisation) nelumbo.lang.Parenthesized
logic.nl true, false, unknown NBoolean
logic.nl !<Boolean> Not
logic.nl <Boolean> & <Boolean> And
logic.nl <Boolean> | <Boolean> Or
logic.nl E[...](...) ExistentialQuantifier
logic.nl A[...](...) UniversalQuantifier
logic.nl <Object> = <Object> NIs
logic.nl eq(<Literal>,<Literal>) (private) Equal
logic.nl Root ::= "fact" ... nelumbo.logic.Fact
logic.nl Root ::= <Boolean> "<=>" ... nelumbo.logic.Rule
logic.nl Root ::= <Boolean> ? (Binding Binding)? nelumbo.logic.Query
integers.nl <(> - <)?> <[> <NUMBER> <(> "#" ... <)?> <]> NInteger
integers.nl add(<Integer>,<Integer>,<Integer>) (private) integers.Integers (add)
integers.nl mult(<Integer>,<Integer>,<Integer>) (private) integers.Integers (mult)
integers.nl gt(<Integer>,<Integer>) (private) integers.Integers (gt)
rationals.nl <(> - <)?> <[> <NUMBER> . <NUMBER> <]> rationals.Rational
rationals.nl add(<Rational>,<Rational>,<Rational>) (private) rationals.Rationals (add)
rationals.nl mult(<Rational>,<Rational>,<Rational>) (private) rationals.Rationals (mult)
rationals.nl gt(<Rational>,<Rational>) (private) rationals.Rationals (gt)
rationals.nl iir(<Integer>,<Integer>,<Rational>) (private) rationals.Rationals (iir)
strings.nl <STRING> NString
strings.nl string_concat(<String>,<String>,<String>) (private) strings.Strings (string_concat)
strings.nl string_length(<String>,<Integer>) (private) strings.Strings (string_length)
strings.nl integer_string(<Integer>,<String>) (private) strings.Strings (integer_string)
collections.nl Set<E> ::= { ... } NSet
collections.nl Set<E> ::= { [ <E> ] ( <Boolean> ) } SetBuilder
collections.nl build(<E>,<Boolean>,<Set<E>>) (private) BuildSet
collections.nl List<E> ::= [ ... ] NList
datetime.nl Date ::= <[> <NUMBER> - <NUMBER> - <NUMBER> <]> datetime.NDate
datetime.nl Time ::= <[> <NUMBER> : <NUMBER> ... <]> datetime.NTime
datetime.nl DateTime ::= <[> <Date> T <Time#50> ... <]> datetime.NDateTime
datetime.nl Period ::= <[> P ... <]> datetime.NPeriod
datetime.nl datetime_add/date_add/time_add(...) (private) datetime.Add (infer)
datetime.nl period_add(<Period>,<Period>,<Period>) (private) datetime.Add (period_add)
datetime.nl period_multiply(<Period>,<Integer>,<Period>) (private) datetime.Multiply (period_multiply)
datetime.nl <DateTime|Date|Time|Period> > <...> datetime.GreaterThan

The natives back roughly twice as many language-level patterns once you count the Nelumbo-defined derivations (<, <=, >=, - unary, - binary, /, |x|, ->, <->, !=, str, int, len, r).


What is not native

A few constructs that might look like they should be native are actually pure Nelumbo definitions:

Looking at the stdlib with this lens — what is native and what is not — is one of the best ways to understand Nelumbo's design philosophy. The Java surface is deliberately minimal; the rest is the meta-language at work.


See also