Debian Codegraph @

extensions/Math/src/WikiTexVC/Nodes/Fun1.php

raw symbols SCIP
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
6
7 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmo;
8 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmover;
9 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
10 use MediaWiki\Extension\Math\WikiTexVC\TexUtil;
11
12 class Fun1 extends TexNode {
13
14 /** @var string */
15 protected $fname;
16 /** @var TexNode */
17 protected $arg;
18 /** @var TexUtil */
19 private $tu;
20
21 public function __construct( string $fname, TexNode $arg ) {
22 parent::__construct( $fname, $arg );
23 $this->fname = $fname;
24 $this->arg = $arg;
25 $this->tu = TexUtil::getInstance();
26 }
27
28 /**
29 * @return string
30 */
31 public function getFname(): string {
32 return $this->fname;
33 }
34
35 /**
36 * @return TexNode
37 */
38 public function getArg(): TexNode {
39 return $this->arg;
40 }
41
42 /** @inheritDoc */
43 public function inCurlies() {
44 return $this->render();
45 }
46
47 /** @inheritDoc */
48 public function render() {
49 return '{' . $this->fname . ' ' . $this->arg->inCurlies() . '}';
50 }
51
52 /** @inheritDoc */
53 public function renderMML( $arguments = [], &$state = [] ) {
54 return $this->parseToMML( $this->fname, $arguments, null );
55 }
56
57 public function createMover( string $inner, array $moArgs = [] ): string {
58 $mrow = new MMLmrow();
59 $mo = new MMLmo( "", $moArgs );
60 $mover = new MMLmover();
61 $ret = $mrow->encapsulateRaw(
62 $mrow->encapsulateRaw(
63 $mover->encapsulateRaw(
64 $this->args[1]->renderMML() .
65 $mo->encapsulateRaw( $inner )
66 )
67 )
68 );
69 return $ret;
70 }
71
72 /** @inheritDoc */
73 public function extractIdentifiers( $args = null ) {
74 if ( $args == null ) {
75 $args = [ $this->arg ];
76 }
77 $letterMods = array_keys( $this->tu->getBaseElements()['is_letter_mod'] );
78 if ( in_array( $this->fname, $letterMods, true ) ) {
79 $ident = $this->arg->getModIdent();
80 if ( !isset( $ident[0] ) ) {
81 return parent::extractIdentifiers( $args );
82 }
83 // in difference to javascript code: taking first element of array here.
84 return [ $this->fname . '{' . $ident[0] . '}' ];
85
86 } elseif ( array_key_exists( $this->fname, $this->tu->getBaseElements()['ignore_identifier'] ) ) {
87 return [];
88 }
89
90 return parent::extractIdentifiers( $args );
91 }
92
93 /** @inheritDoc */
94 public function extractSubscripts() {
95 return $this->getSubs( $this->arg->extractSubscripts() );
96 }
97
98 /** @inheritDoc */
99 public function getModIdent() {
100 return $this->getSubs( $this->arg->getModIdent() );
101 }
102
103 private function getSubs( array $subs ): array {
104 $letterMods = array_keys( $this->tu->getBaseElements()['is_letter_mod'] );
105
106 if ( isset( $subs[0] ) && in_array( $this->fname, $letterMods, true ) ) {
107 // in difference to javascript code: taking first element of array here.
108 return [ $this->fname . '{' . $subs[0] . '}' ];
109 }
110 return [];
111 }
112
113 }