GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - php-type-language/types: [READ ONLY] 📦 An AST nodes of the TypeLang

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT


The AST node classes (TypeLang\Type\*) for TypeLang — a declarative type language inspired by static analyzers like PHPStan and Psalm.

These plain, dependency-free DTOs are the shared vocabulary of the TypeLang ecosystem: the parser produces them, the printer renders them, and the reader builds them from Reflection.

Full documentation is available at typelang.dev.

Installation

Install the package via Composer:

composer require type-lang/types

Requirements:

  • PHP 8.1+

Usage

A type is a tree of typed nodes instead of a string, so tools can inspect and change it without parsing text. You usually get the tree from the parser, but it can be built by hand as well. Every node also keeps the $offset of its token in the source.

// Example<string, int, *>|null
$type = new UnionTypeNode([
    new NamedTypeNode(
        name: new Name('Example'),
        arguments: new TemplateListNode([
            new TypedTemplateArgumentNode(
                new NamedTypeNode(new Name('string')),
            ),
            new TypedTemplateArgumentNode(
                new NamedTypeNode(new Name('int')),
            ),
            new WildcardTemplateArgumentNode()
        ]),
    ),
    new NullLiteralNode(),
]);

// Read the tree
$type[0]->name->value;                    // 'array'
$type[0]->arguments[1]->value->name->value; // 'int'

// Change it: the tree is mutable, names and literals are immutable values
$type[0]->name = new Name('iterable');

The package covers the full type grammar: unions and intersections, generics, shapes, callables, conditional types, class constants and their masks, and literals. See the documentation for the node reference.

About

[READ ONLY] 📦 An AST nodes of the TypeLang

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.