Skip to content

Commit 9ff1a00

Browse files
committed
Improve packages readme
1 parent 5795166 commit 9ff1a00

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

README.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,53 @@
1414

1515
---
1616

17-
Reference implementation for TypeLang Printer.
17+
## About
1818

19-
## Resources
19+
The reference printer for **TypeLang**. It renders `TypeLang\Type\*` AST nodes
20+
back into their string representation.
2021

21-
- [Documentation](https://typelang.dev)
22+
Two printers are provided:
23+
24+
- `NativeTypePrinter` — outputs a valid, native PHP type declaration.
25+
- `PrettyTypePrinter` — outputs the full PHPStan/Psalm-style type, formatted
26+
across multiple lines.
27+
28+
Full documentation is available at [typelang.dev](https://typelang.dev).
2229

2330
## Installation
2431

25-
TypeLang Printer is available as Composer repository and can be installed
26-
using the following command in a root of your project:
32+
Install the package via [Composer](https://getcomposer.org):
2733

2834
```sh
2935
composer require type-lang/printer
3036
```
3137

32-
## Quick Start
38+
**Requirements:**
39+
- PHP 8.4+
40+
41+
## Usage
42+
43+
Parse a type into an AST (using [`type-lang/parser`](https://packagist.org/packages/type-lang/parser)),
44+
then print it back with either printer:
3345

3446
```php
35-
$parser = new \TypeLang\Parser\TypeParser();
36-
$type = $parser->parseType(<<<'PHP'
47+
$parser = new TypeLang\Parser\TypeParser();
48+
49+
$type = $parser->parse(<<<'PHP'
3750
array{
38-
field1: (callable(Example,int):mixed),
51+
field1: (callable(Example, int): mixed),
3952
field2: list<Some>,
40-
field3: iterable<array-key, array{int, non-empty-string}>,
41-
Some::CONST_*,
42-
"\njson_flags": \JSON_*,
4353
...
4454
}
4555
PHP);
4656

47-
// Print Statement
48-
49-
$native = new \TypeLang\Printer\NativeTypePrinter();
50-
echo $native->print($type);
51-
52-
// Expected Output:
57+
echo new TypeLang\Printer\NativeTypePrinter()->print($type);
5358
// array
5459

55-
$phpdoc = new \TypeLang\Printer\PrettyTypePrinter();
56-
echo $phpdoc->print($type);
57-
58-
// Expected Output:
60+
echo new TypeLang\Printer\PrettyTypePrinter()->print($type);
5961
// array{
6062
// field1: callable(Example, int): mixed,
6163
// field2: list<Some>,
62-
// field3: iterable<array-key, array{
63-
// int,
64-
// non-empty-string
65-
// }>,
66-
// Some::CONST_*,
67-
// "\njson_flags": \JSON_*,
6864
// ...
6965
// }
7066
```

0 commit comments

Comments
 (0)