SceneLang interpreter API

Documentation of SceneLang interpreter.

Contents

Public API

Raytracer.Interpreter.InputStream — Type
InputStream

Type wrapping the IO from the source code of a SceneLang script.

Fields

  • stream::IO: IO stream from the source code
  • location::SourceLocation: a SourceLocation that keeps track of the reading position in the source file
  • saved_char::Union{Char, Nothing}: stores a character from unread_char! or nothing
  • saved_location::SourceLocation: a SourceLocation storing the previous reading position
  • saved_token::Union{Token, Nothing}: stores an unreaded Token
  • tabulations::Int: how many columns a <tab> character is worth
source
Raytracer.Interpreter.Scene — Type
Scene

A mutable struct containing all the significant elements of a renderable scene and all the declared variables of the SceneLang script.

Fields

source
Raytracer.Interpreter.Scene — Method
Scene(variables::Vector{Pair{Type{<:TokenValue}, Vector{Pair{Symbol, Token}}}};
      world::World = World(),
      lights::Lights = Lights(),
      image::ImageOrNot = nothing,
      camera::CameraOrNot = nothing,
      renderer::RendererOrNot = nothing,
      tracer::TracerOrNot = nothing,
      time = 0f0)

Constructor for a Scene instance.

Slightly more convenient than the default constructor to manually construct in a Julia code.

source
Raytracer.Interpreter.Scene — Method
Scene(; variables::IdTable = IdTable(),
        world::World = World(),
        lights::Lights = Lights(),
        image::ImageOrNot = nothing,
        camera::CameraOrNot = nothing,
        renderer::RendererOrNot = nothing,
        tracer::TracerOrNot = nothing,
        time::Float32 = 0f0)

Constructor for a Scene instance.

source
Raytracer.Interpreter.SourceLocation — Type
SourceLocation

Represents a position in a file at a certain line and column.

Fields

  • file_name::String: the input file name
  • line_num::Int: line position
  • col_num::Int: column position
source
Raytracer.Interpreter.Token — Type
Token{T <: TokenValue}

Type representing a language token of a SceneLang script.

Fields

  • loc::SourceLocation: a SourceLocation representing the position in the script at which the token starts,
  • value::T: a TokenValue representing the value of the token (see TokenValue)
  • length::Int: length of the input token.
source

Private API

Raytracer.Interpreter.valid_operations — Constant
valid_operations

A dictionary storing the operation Symbol and a function ::Int -> ::Bool that return true when the number of arguments is under a threshold.

For example the pair :+ => ( ::Int) -> true indicates that the operation + is valid with any number of arguments, while the pair :floor => (n::Int) -> n == 1 indicates that the operation floor is valid only if it has one argument.

See also: Raytracer.isvalid

source
Raytracer.Interpreter.BadCharacter — Type
BadCharacter <: InterpreterException

There is an invalid character in the SceneLang script.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.Command — Type
Command

Enum type listing all commands of SceneLang.

Instances

  • Raytracer.Interpreter.USING
  • Raytracer.Interpreter.SET
  • Raytracer.Interpreter.UNSET
  • Raytracer.Interpreter.SPAWN
  • Raytracer.Interpreter.DUMP
  • Raytracer.Interpreter.LOAD
  • Raytracer.Interpreter.ROTATE
  • Raytracer.Interpreter.TRANSLATE
  • Raytracer.Interpreter.SCALE
  • Raytracer.Interpreter.UNITE
  • Raytracer.Interpreter.INTERSECT
  • Raytracer.Interpreter.DIFF
  • Raytracer.Interpreter.FUSE
  • Raytracer.Interpreter.TIME
source
Raytracer.Interpreter.InvalidExpression — Type
InvalidExpression <: InterpreterException

The given expression contains invalid elements. Capabilities are restrained to contain malicious code injection.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.InvalidKeyword — Type
InvalidKeyword <: InterpreterException

The given keyword is not valid in the given context.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.InvalidNumber — Type
InvalidNumber <: InterpreterException

The token has an invalid numerical format.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.InvalidSize — Type
InvalidSize <: InterpreterException

The given collection has an invalid size in the given context.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.InvalidSymbol — Type
InvalidSymbol <: InterpreterException

The given symbol is not valid in the given context.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.InvalidType — Type
InvalidType <: InterpreterException

The given type does not exist.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.LiteralType — Type
LiteralType

Enum type listing all main types of SceneLang.

Instances

  • Raytracer.Interpreter.ColorType
  • Raytracer.Interpreter.PointType
  • Raytracer.Interpreter.ListType
  • Raytracer.Interpreter.TransformationType
  • Raytracer.Interpreter.MaterialType
  • Raytracer.Interpreter.BrdfType
  • Raytracer.Interpreter.PigmentType
  • Raytracer.Interpreter.ShapeType
  • Raytracer.Interpreter.LightType
  • Raytracer.Interpreter.ImageType
  • Raytracer.Interpreter.RendererType
  • Raytracer.Interpreter.CameraType
  • Raytracer.Interpreter.PcgType
  • Raytracer.Interpreter.TracerType
source
Raytracer.Interpreter.RendererSettings — Type
RendererSettings

Struct containing a renderer type and a NamedTuple of the named arguments needed for its construction.

Since a Renderer type cannot be directly stored into a Scene due to it needing at least the World argument, we can use this struct to store everything else, ready to be constructed.

source
Raytracer.Interpreter.SettingRedefinition — Type
SettingRedefinition <: InterpreterException

A rendering setting is being defined multiple times.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.UndefinedIdentifier — Type
UndefinedIdentifier <: InterpreterException

The given identifier has not been defined in the script.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.UndefinedSetting — Type
UndefinedSetting <: InterpreterException

One or more necessary rendering settings have not been set up in the SceneLang script.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.UnfinishedExpression — Type
UnfinishedExpression <: InterpreterException

A special environment (e.g. a string, mathematical expression, list...) has been opened and not closed.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.WrongTokenType — Type
WrongTokenType <: InterpreterException

The given value is of a different type than expected by the syntax.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Raytracer.Interpreter.WrongValueType — Type
WrongValueType <: InterpreterException

The given value has a different type than expected by the syntax.

See also: InterpreterException

Fields

  • location::SourceLocation: location of the error
  • msg::AbstractString: descriptive error message
  • len::Int: how many characters are involved in the error
source
Base.eof — Method
eof(stream::InputStream)

Check if the stream has reached the end-of-file.

source
Base.isvalid — Method
Raytracer.isvalid(expr::Expr, str_len::Int, token_location::SourceLocation)

Return true if the given expression is valid in a SceneLang script, else throw an appropriate exception using str_len and token_location.

See also: valid_operations

source
Raytracer.Interpreter.generate_kwargs — Method
function generate_kwargs(stream::InputStream, scene::Scene, kw::NamedTuple)

Return a Dict{Symbol, Any} as instructed by the given kw NamedTuple.

The argument kw pairs all the keywords a constructor need with the parsing functions they need. This function parses keywords and/or values until it reaches the end of the constructor. The arguments may also be positional, but positional arguments must not follow keyword arguments. If a keyword is used more than once an exception is thrown.

source
Raytracer.Interpreter.parse_color — Method
parse_color(stream::InputStream, scene::Scene)

Return a RGB{Float32} value from either a named constructor, a symbolic constructor, an appropriate MathExpression, or an appropriate Identifier.

If the constructor has not exactly three arguments an exception will be thrown.

source
Raytracer.Interpreter.parse_constructor — Method
parse_constructor(stream::InputStream, scene::Scene)

Return a Tuple{Any, IdTableKey} containing the result of the construction and its type.

If the expression from the stream is not a valid constructor an exception is thrown.

source
Raytracer.Interpreter.parse_list — Method
parse_list(stream::InputStream, scene::Scene, list_length::Int)

Return a SVector{list_length, Float32} value from either a named constructor, a symbolic constructor or an appropriate Identifier.

If the list is not exactly list_length long an exception will be thrown.

source
Raytracer.Interpreter.parse_rotation — Method
parse_rotation(stream::InputStream, scene::Scene)

Return a Transformation value from the ROTATE Command.

The argument of this command is a sequence of keyword arguments, with keywords representing the three axes of rotation .X, .Y, and .Z, followed by a number representing the rotation angle in degrees. Each of these keyword arguments are separated by a * operator which behaves as a concatenation of rotation following the usual rules of matrix multiplication (i.e. the rightmost rotation will be the first to be applied)

See also: parse_transformation_from_command

source
Raytracer.Interpreter.parse_scaling — Method
parse_scaling(stream::InputStream, scene::Scene)

Return a Transformation value from the SCALE Command.

The arguments of this command are a sequence of keyword arguments, with keywords representing the three axes of scaling .X, .Y, and .Z, followed by a number representing the scaling factor. Each of these keyword arguments are separated by a ,. The order of these arguments is indifferent since, in our euclidean space, scalings are commutative transformations.

An alternate form of this command sees only one numeric argument, without parenthesis, and indicates uniform scaling in all directions.

See also: parse_transformation_from_command

source
Raytracer.Interpreter.parse_transformation — Method
parse_transformation(stream::InputStream, scene::Scene)

Return a Transformation value from either a named constructor, a construction command, or an appropriate Identifier.

If the constructor/command/identifier is followed by an * operator the transformations will be concatenated following the usual matrix multiplication rules (i.e. the rightmost transformation will be applied first).

See also: parse_explicit_transformation, parse_transformation_from_command

source
Raytracer.Interpreter.parse_translation — Method
parse_translation(stream::InputStream, scene::Scene)

Return a Transformation value from the TRANSLATE Command.

The arguments of this command are a sequence of keyword arguments, with keywords representing the three axes of translation .X, .Y, and .Z, followed by a number representing the displacement. Each of these keyword arguments are separated by a ,. The order of these arguments is indifferent since, in our euclidean space, translations are commutative transformations.

See also: parse_transformation_from_command

source
Raytracer.Interpreter.parse_using_command — Method
parse_using_command(stream::InputStream, scene::Scene)

Set the given CameraType, ImageType or RendererType to the scene.camera, scene.image, or scene.renderer respectively.

Can only be used once per type in a SceneLang script.

See also: Scene

source

Index