Private API

This page lists non-exported (internal) symbols of CTParser.


From CTParser

@def

CTParser.@defMacro

Define an optimal control problem. One pass parsing of the definition. Can be used writing either ocp = @def begin ... end or @def ocp begin ... end. In the second case, setting log to true will display the parsing steps.

Example

ocp = @def begin
    tf ∈ R, variable
    t ∈ [ 0, tf ], time
    x ∈ R², state
    u ∈ R, control
    tf ≥ 0
    -1 ≤ u(t) ≤ 1
    q = x₁
    v = x₂
    q(0) == 1
    v(0) == 2
    q(tf) == 0
    v(tf) == 0
    0 ≤ q(t) ≤ 5,       (1)
    -2 ≤ v(t) ≤ 3,      (2)
    ẋ(t) == [ v(t), u(t) ]
    tf → min
end

@def ocp begin
    tf ∈ R, variable
    t ∈ [ 0, tf ], time
    x ∈ R², state
    u ∈ R, control
    tf ≥ 0
    -1 ≤ u(t) ≤ 1
    q = x₁
    v = x₂
    q(0) == 1
    v(0) == 2
    q(tf) == 0
    v(tf) == 0
    0 ≤ q(t) ≤ 5,       (1)
    -2 ≤ v(t) ≤ 3,      (2)
    ẋ(t) == [ v(t), u(t) ]
    tf → min
end true # final boolean to show parsing log

E_PREFIX

CTParser.E_PREFIXConstant

Prefix reference for the error-handling backend used in generated code.

This Ref stores the symbol of the module that defines the ParsingError type used by __throw and __wrap.

PREFIX_EXA

CTParser.PREFIX_EXAConstant

Prefix reference for the ExaModels backend used in generated code.

This Ref stores the symbol of the module that implements the ExaModels backend targeted by @def when backend = :exa.

PREFIX_FUN

CTParser.PREFIX_FUNConstant

Prefix reference for the functional backend used in generated code.

This Ref stores the symbol of the module that implements the functional backend targeted by @def when backend = :fun.

ParsingInfo

__init_aliases

CTParser.__init_aliasesFunction
__init_aliases(
;
    max_dim
) -> OrderedCollections.OrderedDict{Symbol, Union{Expr, Real, Symbol}}

Initialise the dictionary of textual aliases for the parser.

This includes mappings such as R₁, R₂, … for powers of R, and ASCII fallbacks like <=, >=, =>, etc.

__symgen

CTParser.__symgenFunction
__symgen(s...) -> Any

Generate a fresh symbol by concatenating the given components and a gensym() suffix.

This is used throughout the parser to create unique internal names that do not collide with user-defined identifiers.

__throw

CTParser.__throwFunction
__throw(mess, n, line) -> Expr

Helper to build a static ParsingError expression.

This is used for syntactic and semantic errors detected at macro expansion time. It formats the message with line information and wraps it in a throw(ParsingError(...)) expression using the current e_prefix.

__wrap

CTParser.__wrapFunction
__wrap(e, n, line) -> Expr

Wrap a block of generated code with line-aware error reporting.

The returned expression executes e inside a try/catch block and, in case of an exception, prints the originating line number and source text before rethrowing.

activate_backend

as_range

CTParser.as_rangeFunction
as_range(x) -> Any

Return x itself if it is a range, or a one-element array [x].

This is a normalisation helper used when interpreting constraint indices.

deactivate_backend

def_exa

CTParser.def_exaFunction
def_exa(e; log) -> Expr

Core computation used to discretise, parsing an expression towards an ExaModels.ExaModel.

def_fun

CTParser.def_funFunction
def_fun(e; log) -> Expr

Core computation of @def macro, parsing an expression towards a CTModels.Model.

e_prefix

CTParser.e_prefixFunction
e_prefix() -> Symbol

Return the current error-handling backend prefix.

e_prefix!

CTParser.e_prefix!Function
e_prefix!(p)

Set the error-handling backend prefix used in generated code.

is_active_backend

is_range

CTParser.is_rangeFunction
is_range(x) -> Union{Missing, Bool}

Return true if x represents a range.

This predicate is specialised for AbstractRange values and for expressions of the form i:j or i:p:j.

parse!

CTParser.parse!Function
parse!(p, p_ocp, e; log, backend) -> Any

Parse the expression e and update the ParsingInfo structure p.

Example

parse!(p, :p_ocp, :(v ∈ R, variable))

parsing

CTParser.parsingFunction
parsing(s, backend) -> Function

Call the primitive associated with symbol s (:alias, etc.) for the associated backend.

prefix_exa

CTParser.prefix_exaFunction
prefix_exa() -> Symbol

Return the current ExaModels backend prefix.

prefix_exa!

CTParser.prefix_exa!Function
prefix_exa!(p)

Set the ExaModels backend prefix used for generated code.

prefix_fun

CTParser.prefix_funFunction
prefix_fun() -> Symbol

Return the current functional backend prefix.

This is the symbol of the module that will be used for the functional backend when expanding @def with backend = :fun.

prefix_fun!

CTParser.prefix_fun!Function
prefix_fun!(p)

Set the functional backend prefix.

This updates PREFIX_FUN, thereby changing which module is used as the functional backend for code generated by @def.