---
title: types | CodeWeaver Docs
description: API reference for codeweaver.semantic.types
url: "https://docs.knitli.com/api/semantic/types"
type: static
generatedAt: "2026-04-17T17:21:09.620Z"
---

# types
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/semantic/types.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F&text=types)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F&text=types)[Share on Bluesky](https://bsky.app/intent/compose?text=types%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F&title=types)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F&t=types)[Share on Email](mailto:?subject=types&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F)[Share on WhatsApp](https://wa.me/?text=types%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fsemantic%2Ftypes%2F&text=types)
# `codeweaver.semantic.types`
[Section titled “codeweaver.semantic.types”](#codeweaversemantictypes)
Common internal types for semantic analysis.

Overview:

 - Data transfer objects (DTOs) for parsing node types files. These are intermediate structures used during parsing and conversion before converting to CodeWeaver’s internal representation (CompositeThing, Token, Category, Direct and Positional Connections).

## Class: `ChildTypeDTO`
[Section titled “Class: ChildTypeDTO”](#class-childtypedto)
NamedTuple for a child type object in the node types file.

Note: This is an intermediate structure used during parsing and conversion. It is not part of the final internal representation.

Attributes: multiple: Whether multiple children of this type are allowed required: Whether at least one child of this type is required types: List of type objects for the allowed child types

## Class: `ConnectionClass`
[Section titled “Class: ConnectionClass”](#class-connectionclass)
Classification of connections between Things in a parse tree.

Tree-Sitter mapping:

 - DIRECT -> fields: Named semantic relationship **with a Role**
 - POSITIONAL -> children: Ordered structural relationship without semantic naming

## Class: `ConnectionConstraint`
[Section titled “Class: ConnectionConstraint”](#class-connectionconstraint)
Flags for Connection constraints.

### Method: `from_cardinality`
[Section titled “Method: from_cardinality”](#method-from_cardinality)

**

```
from_cardinality()
```

Create ConnectionConstraint from cardinality tuple.

## Class: `NodeTypeDTO`
[Section titled “Class: NodeTypeDTO”](#class-nodetypedto)
BasedModel for a single node type object in the node types file. This is the main structure we need to parse and convert into our internal representation. All subordinate structures (subtypes, fields, children) are represented using the SimpleNodeTypeDTO and ChildTypeDTO NamedTuples defined above.

Attributes: node: Name of the node type (alias for `type`) named: Whether the node type is named (true) or anonymous (false) root: Whether the node type is the root of the parse tree fields: Mapping of field names to child type objects children: Child type object for positional children subtypes: List of subtype objects if this is an abstract node type extra: Whether this node type can appear anywhere in the parse tree

## Class: `SemanticMetadata`
[Section titled “Class: SemanticMetadata”](#class-semanticmetadata)
Metadata associated with the semantics of a code chunk.

### Method: `from_node`
[Section titled “Method: from_node”](#method-from_node)

**

```
from_node()
```

Create a SemanticMetadata instance from an AST node.

### Method: `from_parent_meta`
[Section titled “Method: from_parent_meta”](#method-from_parent_meta)

**

```
from_parent_meta()
```

Create a SemanticMetadata instance from a parent SemanticMetadata instance.

### Method: `serialize_for_cli`
[Section titled “Method: serialize_for_cli”](#method-serialize_for_cli)

**

```
serialize_for_cli()
```

Serialize the SemanticMetadata for CLI output.

## Class: `SimpleNodeTypeDTO`
[Section titled “Class: SimpleNodeTypeDTO”](#class-simplenodetypedto)
TypedDict for a simple node type object in the node types file (objects with no attributes besides `type` and `named`). While these appear in the node-types file at the top level (all Tokens are of this form unless only ‘extra’ is present without fields [majority of extra cases, which are rare themselves]), they also appear nested within `subtypes`, `fields`, and `children`. We only use it for nested objects, not top-level ones.

Note: This is an intermediate structure used during parsing and conversion. It is not part of the final internal representation.

Attributes: node: Name of the node type (alias for `type`) named: Whether the node type is named (true) or anonymous (false)

## Class: `ThingKind`
[Section titled “Class: ThingKind”](#class-thingkind)
Classification of Thing types in a parse tree. Things are concrete nodes, that is, what actually exists in the parse tree.

Tree-Sitter mapping:

 - TOKEN -> nodes with no fields/children (leaf nodes): Leaf Thing with no structural children
 - COMPOSITE -> nodes with fields/children (non-leaf nodes): Non-leaf Thing with structural children

A TOKEN represents keywords, identifiers, literals, and punctuation — what you literally see in the source code. A COMPOSITE node represents complex structures like functions, classes, and expressions, which have direct and/or positional connections to child Things.

## Class: `TokenPurpose`
[Section titled “Class: TokenPurpose”](#class-tokenpurpose)
Classification of Token purpose or semantic use.

 - KEYWORD: keywords
 - OPERATOR: operators
 - IDENTIFIER: variable/function/type names
 - LITERAL: string/number/boolean literals
 - PUNCTUATION: whitespace, punctuation, formatting tokens
 - COMMENT: comments

A Token can be classified by its purpose, indicating whether it carries semantic or structural meaning versus being mere formatting trivia. This classification helps in filtering Tokens during semantic analysis while preserving them for formatting purposes.

### Method: `from_node_dto`
[Section titled “Method: from_node_dto”](#method-from_node_dto)

**

```
from_node_dto()
```

Create TokenPurpose from NodeTypeDTO.