DocblockGrammar.defunct.php

<?php

namespace Tlf\Lexer;

/**
 * I ran into a lot of issues while writing this grammar, so I took a completely different approach.
 *
 * I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.
 *
 * Be sure to read the notes in ` I ran into a lot of issues while writing this grammar, so I took a completely different approach.
 *
 * I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.
 *
 * Be sure to read the notes in `.dev` folder before developing this further!
 */
class DocblockGrammar_Defunct extends Grammar {

    protected $directives = [
        '/*'=>[
            'start'=>[
                'match'=>'/\\/\*/',
                'buffer.clear',
                'ast.new'=>[
                    '_type'=>'docblock',
                    '_addto'=>false,
                    // '_setHead'=>false,
                    '_setPrevious'=>'docblock',
                ],
                'then :@',
                'then :\n',
                'then :*',
                'then :!*',
                'then :*/'=>[
                    'start'=>[
                        'rewind 2',
                        'ast.append description',
                        'buffer.clear',
                    ],
                ],
            ],
            'stop'=>[
                'match'=> '*/',
                // 'stop',
                // 'directive.pop 1',
                'lexer:popHead'
            ]
        ],
        '*/'=>[
            'start'=>[
                'match'=>'*/',
                'directive.pop 1',
                'rewind 1',
            ]
        ],
        '\n'=>[
            'start'=>[
                'match'=>'/(\r|\n)/',
                'then :*',
                'then :!*',
            ],
        ],
        '*'=>[
            'start'=>[
                'match'=>"/\*[^\/]/",
                // 'rewind 1',
                'rewind 2',
                'buffer.clearNext 1',
                'buffer.appendChar'=>' ',
                'forward 1',
                'stop',
            ]
        ],
        '!*'=>[
            'start'=>[
                'match'=>'/[^\s\*]$/',
                'rewind 1',
                'buffer.clear',
                'then :\n' =>[
                    'start'=>[
                        // 'rewind 1',
                        'ast.append description',
                        'buffer.clear',
                        // 'forward 1',
                    ]
                ],
                'then :@',
                'then :*/'=>[
                    'start'=>[
                        'rewind 2',
                        'ast.append description',
                        'buffer.clear'
                    ],
                ],
            ],
            'stop'=>[
                'match'=>'*/',
                'rewind 1',
            ],
        ],
        '@'=>[
            'start'=>[
                'match'=>'@',
            ]
        ]

    ];

    public function onGrammarAdded($lexer){
    }
    public function onLexerStart($lexer, $ast, $token){
    }
    public function onLexerEnd($lexer, $ast, $token){

    }
}