Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax Overview

SchemaScript files use the .scsc extension. The language is block-based and whitespace-insensitive (outside of strings). A schema file contains a mix of top-level directives and model definitions.

Structure of a .scsc File

A typical schema file follows this structure:

// 1. Imports
import scsc/base

// 2. Global metadata
[version] = 1

// 3. Mapping configuration
[map] = {
  api = {
    strategy = MappingStrategy::snakeCase
  }
}

// 4. Generator configuration
[generate] = {
  [ts.types] = {
    output = 'output/ts/'
  }
}

// 5. Constants
const pk_t = uint64

// 6. Namespaces
ns Visibility {
  const public
  const private
}

// 7. Type aliases
[type] = {
  pub MessageType = 'text'|'image'|'video'
  position = { x: int, y: int }
}

// 8. Model definitions
User {
  id: pk_t
  name: string
  email: string?
  visibility: Visibility::public
}

// 9. Models with generics and inheritance
private SingleResponse<T> {
  error?: string
  data: T
}

UserResponse: SingleResponse<User> {}

Message {
  id: pk_t
  type: MessageType
  text: string?
  author: User?
  tags: string[]
  metadata: map<string, string>

  @map.api(modified_at)
  updatedAt: int
}

Top-Level Constructs

ConstructSyntaxPurpose
Importimport path/to/fileInclude another .scsc file
Comment// textLine comment
Metadata[key] = valueSchema-level configuration
Namespacens Name { ... }Group constants
Constantconst name = valueDefine a constant
Type block[type] = { ... }Define type aliases
ModelName { ... }Define a data model

Conventions

  • File extension: .scsc
  • Entry point: SCHEMA.scsc in the project root (used by scsc build)
  • Standard library: import scsc/base for built-in types
  • No semicolons: Statements are newline-separated
  • No commas: Properties and metadata entries are newline-separated (commas are not used)