ClassDirectives.php.old

<?php

namespace Tlf\Lexer\Php;

trait ClassDirectives {

    protected $_class_directives = [

        'php_class_code'=>[
            'is'=>[
                ':separator',
                ':use_trait',
                ':modifier',
                // ':php_close',
                // ':php8_attribute',

            ],
        ],

        'use_trait'=>[
            'start'=>[
                'match'=>'use ',
                'buffer.clear'=>true,
            ],
            'stop'=>[
                'match' => ';',
                'rewind'=>1,
                'this:captureUseTrait',
                'forward'=>1,
                'buffer.clear'=>true,
            ],
        ],

        'class'=>[
            'stop'=>[
                'stop',
                'rewind 1',
            ],
            'start'=>[
                'match'=>'/^class[^a-zA-Z0-9_]$/',
                'rewind'=>1,
                'previous.append'=>'class.declaration',
                'ast.new'=>[
                    '_type'=>'class',
                    '_addto'=>'class',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'namespace'=>'_lexer:previous namespace.name',
                ],
                'buffer.clear'=>true,
                'then :separator'=>
                [
                    'start'=>[
                        'rewind'=>1,
                        'previous.append'=>'class.declaration',
                        'forward 1',
                    ],
                    'stop'=>[
                        'rewind 1',
                        'previous.append'=>'class.declaration',
                        'directive.pop 1',
                        'then :varchars'=>[
                            'start'=>[
                                'rewind'=>1,
                                'buffer.notin keyword',
                                'ast.set'=>'name',
                                'previous.append'=>'class.declaration',
                                'buffer.clear'=>true,
                                'stop',
                                'directive.pop 1',
                                'then :separator' =>[
                                    'start'=>[
                                        // 'rewind'=>1,
                                        'previous.append'=>'class.declaration',
                                        // 'forward'=>1,
                                    ],
                                ],
                                // 'then :class_implements',
                                // 'then :class_extends',
                                'then :block'=>[
                                    'start'=>[
                                        'rewind'=>1,
                                        'this:handleClassDeclaration',
                                        'forward 1',
                                        'buffer.clear'=>true,
                                        'then :php_class_code',
                                        'then :block.stop'=>[
                                            'start'=>[
                                                'directive.pop 1',
                                                'rewind'=>1,
                                            ],
                                        ],
                                    ],
                                    'stop'=>[
                                        'buffer.clear'=>true,
                                        'directive.pop 1',
                                        'stop',
                                    ]
                                ],
                            ],
                        ],
                        'then :separator'=>[],
                    ],
                ]
            ]
        ],


    // close the directive
    ];

}