Class Declaration

java.lang.Object
org.daiitech.naftah.builtin.lang.Declaration
Direct Known Subclasses:
DeclaredFunction, DeclaredImplementation, DeclaredParameter, DeclaredVariable

public abstract sealed class Declaration extends Object permits DeclaredVariable, DeclaredFunction<T>, DeclaredParameter, DeclaredImplementation
Represents a named declaration in the Naftah scripting language.

A Declaration is the common abstraction for all language constructs that may appear as named declarations within a lexical or semantic scope, including variables, functions, parameters, and implementations.

This sealed abstract class restricts extension to its permitted subclasses (DeclaredVariable, DeclaredFunction, DeclaredParameter, and DeclaredImplementation), preserving the integrity of the declaration model.

Each declaration records the depth at which it appears in the language’s scope hierarchy. The depth corresponds to the lexical nesting level of the surrounding context (for example, global scope, function body, or control-flow block).

This class is immutable: the depth of a declaration is assigned at construction time and cannot be modified.

Author:
Chakib Daii
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    The lexical or semantic depth at which this declaration was introduced.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Declaration(int depth)
    Creates a new declaration at the specified depth.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the depth of this declaration within the scope hierarchy.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • depth

      protected final int depth
      The lexical or semantic depth at which this declaration was introduced.

      Depth 0 typically represents the global or root scope. Incremental values represent deeper nested scopes.

  • Constructor Details

    • Declaration

      public Declaration(int depth)
      Creates a new declaration at the specified depth.
      Parameters:
      depth - the scope depth where this declaration appears
  • Method Details

    • getDepth

      public int getDepth()
      Returns the depth of this declaration within the scope hierarchy.
      Returns:
      the declaration depth