Debian Codegraph @

extensions/Math/src/WikiTexVC/Nodes/Lr.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\MMLmappings\BaseMethods;
8 use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\TexConstants\TexClass;
9 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmo;
10 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
11
12 class Lr extends TexNode {
13
14 /** @var string */
15 private $left;
16 /** @var string */
17 private $right;
18 /** @var TexArray */
19 private $arg;
20
21 public function __construct( string $left, string $right, TexArray $arg ) {
22 parent::__construct( $left, $right, $arg );
23 $this->left = $left;
24 $this->right = $right;
25 $this->arg = $arg;
26 }
27
28 /**
29 * @return string
30 */
31 public function getLeft(): string {
32 return $this->left;
33 }
34
35 /**
36 * @return string
37 */
38 public function getRight(): string {
39 return $this->right;
40 }
41
42 /**
43 * @return TexArray
44 */
45 public function getArg(): TexArray {
46 return $this->arg;
47 }
48
49 /** @inheritDoc */
50 public function inCurlies() {
51 return '{' . $this->render() . '}';
52 }
53
54 /** @inheritDoc */
55 public function render() {
56 return '\\left' . $this->left . $this->arg->render() . '\\right' . $this->right;
57 }
58
59 /** @inheritDoc */
60 public function renderMML( $arguments = [], &$state = [] ) {
61 // TBD set attributes for right AND left correctly
62 $rightAttrs = [];
63 if ( $this->right == "." ) {
64 $rightAttrs = [ "fence" => "true", "stretchy" => "true", "symmetric" => "true" ];
65 }
66
67 $bm = new BaseMethods();
68 $left = $bm->checkAndParseDelimiter( $this->left, $this, [], null, true,
69 TexClass::OPEN );
70 if ( !$left ) {
71 $moLeft = new MMLmo( TexClass::OPEN, [] );
72 $left = $moLeft->encapsulateRaw( $this->right );
73 }
74 $right = $bm->checkAndParseDelimiter( $this->right, $this, $rightAttrs, null, true,
75 TexClass::CLOSE );
76 if ( !$right ) {
77 $moRight = new MMLmo( TexClass::CLOSE, $rightAttrs );
78 $right = $moRight->encapsulateRaw( $this->right );
79 }
80 // Don't apply outer ' inside the LR structure
81 unset( $state['deriv'] );
82 $inner = $this->getArg()->renderMML( [], $state );
83 $mrow = new MMLmrow( TexClass::INNER );
84 return $mrow->encapsulateRaw(
85 $left . $inner .
86 $right
87 );
88 }
89
90 private function mmlTranslate( string $input ): string {
91 switch ( trim( $input ) ) {
92 case "\\vert":
93 return "|";
94 default:
95 return $input;
96 }
97 }
98
99 /** @inheritDoc */
100 public function containsFunc( $target, $args = null ) {
101 if ( $args == null ) {
102 $args = [ '\\left', '\\right', $this->arg ];
103 }
104 return parent::containsFunc( $target, $args );
105 }
106
107 /** @inheritDoc */
108 public function extractIdentifiers( $args = null ) {
109 if ( $args == null ) {
110 $args = [ $this->arg ];
111 }
112 return parent::extractIdentifiers( $args );
113 }
114
115 }