N4L API
Parser
SemanticSpacetime.N4LState — Type
N4LStateMutable state for the N4L parser/compiler. Each parse session gets its own state object to avoid global mutable state.
SemanticSpacetime.N4LResult — Type
N4LResultResult of parsing N4L input.
Fields
errors::Vector{String}: parse errors encounteredwarnings::Vector{String}: parse warnings encounterednd::NodeDirectory: the node directory populated by the parserstate::N4LState: the final parser state
SemanticSpacetime.N4LParseError — Type
N4LParseError <: ExceptionException thrown when the N4L parser encounters an unrecoverable error.
Fields
message::String: description of the parse error
SemanticSpacetime.parse_n4l — Function
parse_n4l(input::String; verbose=false, config_dir=nothing, load_config=true) -> N4LResultParse N4L text and return the result. This is the main entry point.
input: N4L source textverbose: print diagnostic outputconfig_dir: path to SSTconfig directory (auto-detected if not given)load_config: whether to load SSTconfig arrow definitions
SemanticSpacetime.parse_n4l_file — Function
parse_n4l_file(filename::String; verbose=false, config_dir=nothing, load_config=true) -> N4LResultParse an N4L file and return the result.
SemanticSpacetime.parse_config_file — Function
parse_config_file(filename::String; st::N4LState=N4LState()) -> N4LStateParse a single config file and register its arrows.
SemanticSpacetime.find_config_dir — Function
find_config_dir(search_paths=nothing) -> Union{String, Nothing}Search for the SSTconfig directory. Checks:
- SSTCONFIGPATH environment variable
- ./SSTconfig, ../SSTconfig, ../../SSTconfig
- Custom search_paths if provided
SemanticSpacetime.read_config_files — Function
read_config_files(config_dir::String) -> Vector{String}Return the list of config file paths from an SSTconfig directory.
SemanticSpacetime.has_errors — Function
has_errors(r::N4LResult) -> BoolReturn true if the parse result contains any errors.
SemanticSpacetime.has_warnings — Function
has_warnings(r::N4LResult) -> BoolReturn true if the parse result contains any warnings.
SemanticSpacetime.ROLE_EVENT — Constant
N4L line role: an event or item declaration.
SemanticSpacetime.ROLE_RELATION — Constant
N4L line role: a relation (arrow) between items.
SemanticSpacetime.ROLE_SECTION — Constant
N4L line role: a section/chapter declaration.
SemanticSpacetime.ROLE_CONTEXT — Constant
N4L line role: a context assignment.
SemanticSpacetime.ROLE_CONTEXT_ADD — Constant
N4L line role: add to the current context.
SemanticSpacetime.ROLE_CONTEXT_SUBTRACT — Constant
N4L line role: subtract from the current context.
SemanticSpacetime.ROLE_BLANK_LINE — Constant
N4L line role: a blank line (separator).
SemanticSpacetime.ROLE_LINE_ALIAS — Constant
N4L line role: a line alias definition (@label).
SemanticSpacetime.ROLE_LOOKUP — Constant
N4L line role: a lookup/back-reference ($label.n).
SemanticSpacetime.ROLE_COMPOSITION — Constant
N4L line role: a composition (multi-part relation).
SemanticSpacetime.ROLE_RESULT — Constant
N4L line role: a result/output declaration.
Compiler
SemanticSpacetime.N4LCompileResult — Type
N4LCompileResultSummary of a compile operation.
SemanticSpacetime.compile_n4l! — Function
compile_n4l!(store::MemoryStore, result::N4LResult) -> N4LCompileResultTransfer parsed N4L nodes and edges from the parse result's NodeDirectory into the given store. Returns a summary of what was created.
SemanticSpacetime.compile_n4l_file! — Function
compile_n4l_file!(store::MemoryStore, filepath::String;
config_dir=nothing, verbose=false) -> N4LCompileResultParse an N4L file and compile the result into the store.
SemanticSpacetime.compile_n4l_string! — Function
compile_n4l_string!(store::MemoryStore, text::String;
config_dir=nothing, verbose=false) -> N4LCompileResultParse an N4L string and compile the result into the store.
Validation and Summary
SemanticSpacetime.N4LValidationResult — Type
N4LValidationResultResult of validating N4L input without compiling to a store.
SemanticSpacetime.validate_n4l — Function
validate_n4l(text::String; config_dir=nothing, verbose=false) -> N4LValidationResultParse N4L text and report validation results without creating a store.
SemanticSpacetime.validate_n4l_file — Function
validate_n4l_file(filepath::String; config_dir=nothing, verbose=false) -> N4LValidationResultParse an N4L file and report validation results without creating a store.
SemanticSpacetime.n4l_summary — Function
n4l_summary(result::N4LResult; io::IO=stdout)Print a human-readable summary of the parsed N4L result.
n4l_summary(cr::N4LCompileResult; io::IO=stdout)Print a human-readable summary of a compile result.
Provenance
SemanticSpacetime.Provenance — Type
ProvenanceMetadata tracking the origin of a node or link.
SemanticSpacetime.set_provenance! — Function
set_provenance!(store::MemoryStore, nptr::NodePtr, prov::Provenance)Attach provenance metadata to a node via EXPRESS annotation nodes. Creates annotation nodes linked via the note arrow.
SemanticSpacetime.get_provenance — Function
get_provenance(store::MemoryStore, nptr::NodePtr) -> Union{Provenance, Nothing}Retrieve provenance metadata from a node's EXPRESS annotations.
SemanticSpacetime.compile_n4l_with_provenance! — Function
compile_n4l_with_provenance!(store::MemoryStore, text::String;
source::String="<string>", author::String="", config_dir=nothing) -> N4LCompileResultLike compilen4lstring! but attaches provenance to every created node.
Macros
SemanticSpacetime.@n4l_str — Macro
n4l"..."Parse an N4L string literal at runtime, returning an N4LResult. Uses the default SSTconfig if available, otherwise parses without config.
Examples
result = n4l"-section\n\n apple (contains) fruit\n"
result = n4l"""
-vocabulary
apple (contains) fruit
banana (contains) fruit
"""n4l"..."config_dirParse an N4L string literal with a specific config directory.
Example
result = n4l"""
-section
apple (contains) fruit
""""/path/to/SSTconfig"SemanticSpacetime.@sst — Macro
@sst [store] begin ... endCreate a MemoryStore and execute a block of operations on it, returning the store. If a variable name is given, it is bound within the block; otherwise the store is accessible as s.
Examples
# Implicit variable `s`
store = @sst begin
v1 = vertex!(s, "apple", "fruits")
v2 = vertex!(s, "banana", "fruits")
edge!(s, v1, "contains", v2)
end
# Explicit variable name
store = @sst g begin
a = vertex!(g, "hello", "greetings")
b = vertex!(g, "world", "greetings")
edge!(g, a, "note", b)
endSemanticSpacetime.@compile — Macro
@compile text
@compile store text
@compile text config_dir=pathCompile an N4L string into a MemoryStore. If no store is provided, a new one is created. Returns (store, compile_result).
Examples
# New store
store, result = @compile """
-section
apple (contains) fruit
"""
# Into existing store
store = MemoryStore()
_, result = @compile store """
-section
banana (contains) fruit
"""SemanticSpacetime.@graph — Macro
@graph store begin
"node1" -arrow-> "node2"
...
endBuild a graph declaratively. Each line in the block should be a call to vertex! or edge!, or use the DSL helpers.
Example
store = MemoryStore()
@graph store begin
a = vertex!("apple", "fruits")
b = vertex!("banana", "fruits")
c = vertex!("fruit", "fruits")
edge!(a, "contains", c)
edge!(b, "contains", c)
endInside @graph, vertex! and edge! calls automatically use the store.