packages/bison-parser/src/Ast/Declaration/InitialAction.php
1<?php
2
3declare(strict_types=1);
4
5namespace BisonParser\Ast\Declaration;
6
7use BisonParser\Ast\Location;
8
9/**
10 * An `%initial-action` directive and its code.
11 *
12 * @visibility public
13 *
14 * @example Reading the initial action
15 * $file = (new \BisonParser\Parser())->parse("%initial-action { @\$.begin.filename = 0; }\n%%\ns: 'a';\n");
16 * $file->declarations[0]->code // => ' @$.begin.filename = 0; '
17 */
18final class InitialAction implements Declaration
19{
20 /**
21 * @param string $code The code without its braces
22 * @param Location $location Where the directive is written
23 */
24 public function __construct(
25 public readonly string $code,
26 public readonly Location $location,
27 ) {
28 }
29
30 /**
31 * Answers where the declaration begins.
32 *
33 * @return Location Line and column of the percent sign
34 */
35 public function location(): Location
36 {
37 return $this->location;
38 }
39}
40