SceneLang interpreter API

Documentation of SceneLang interpreter.

Contents

Public API

Raytracer.Interpreter.InputStreamType
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.SceneType
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.SceneMethod
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.SceneMethod
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.SourceLocationType
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.TokenType
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_operationsConstant
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.BadCharacterType
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.CommandType
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.InvalidExpressionType
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.InvalidKeywordType
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.InvalidNumberType
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.InvalidSizeType
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.InvalidSymbolType
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.InvalidTypeType
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.LiteralTypeType
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.RendererSettingsType
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.SettingRedefinitionType
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.UndefinedIdentifierType
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.UndefinedSettingType
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.UnfinishedExpressionType
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.WrongTokenTypeType
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.WrongValueTypeType
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.eofMethod
eof(stream::InputStream)

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

source
Base.isvalidMethod
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_kwargsMethod
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_colorMethod
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_constructorMethod
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_listMethod
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_rotationMethod
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_scalingMethod
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_transformationMethod
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_translationMethod
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_commandMethod
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