1<?php
2/**
3 * Comment Syntax plugin for DokuWiki; cstyle syntax component
4 *
5 * A "comment" does not appear in the page, but visible when you edit the page.
6 * Supports both C style multi-line comments and one-line C++ style comments
7 *
8 * NOTE:
9 * One-line comments preceded by two slashes (//), may interfere with the markup
10 * for italics. The use of italic formatting markup will be restricted so that
11 * it can not go over next line.
12 *
13 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
14 * @author     Satoshi Sahara <sahara.satoshi@gmail.com>
15 */
16class syntax_plugin_commentsyntax_cstyle extends DokuWiki_Syntax_Plugin
17{
18    /** syntax type */
19    public function getType()
20    {
21        return 'protected';
22    }
23
24    /** sort number used to determine priority of this mode */
25    public function getSort()
26    {
27        return 8; // precedence of Doku_Parser_Mode_listblock priority (=10)
28    }
29
30    /**
31     * Connect lookup pattern to lexer
32     */
33    protected $mode, $pattern;
34
35    public function preConnect()
36    {
37        // syntax mode, drop 'syntax_' from class name
38        $this->mode = substr(__CLASS__, 7);
39        // syntax pattern
40        $this->pattern = [
41            1 => '[ \t]*\n?/\*(?=.*?\*/)',
42            4 => '\*/',
43            5 => '\s//(?:[^/\n]*|[^/\n]*/[^/\n]*)(?=\n)',
44        ];
45    }
46
47    public function accepts($mode)
48    {   // plugin may accept its own entry syntax
49        if ($this->getConf('use_cstyle_nest') && $mode == $this->mode) return true;
50        return parent::accepts($mode);
51    }
52
53
54    public function connectTo($mode)
55    {
56        $this->Lexer->addEntryPattern($this->pattern[1], $mode, $this->mode);
57
58        if ($this->getConf('use_oneline_style')) {
59            $this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode);
60        }
61    }
62
63    public function postConnect()
64    {
65        $this->Lexer->addExitPattern($this->pattern[4], $this->mode);
66    }
67
68    /**
69     * Handle the match
70     */
71    public function handle($match, $state, $pos, Doku_Handler $handler)
72    {
73        return false;
74    }
75
76    /**
77     * Create output
78     */
79    public function render($format, Doku_Renderer $renderer, $data)
80    {
81        return true;
82    }
83}
84