Created
September 10, 2023 18:37
-
-
Save ryangjchandler/6d2e864112732b97508b3fc918da0fbd to your computer and use it in GitHub Desktop.
Syntax Highlighting Kitchen Sink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sample; | |
class SampleClass implements SampleInterface | |
{ | |
public string $public; | |
protected SampleClass $protected; | |
private SampleClass $private; | |
public static string $static; | |
public function __construct() | |
{ | |
// | |
} | |
public function sampleSample() | |
{ | |
} | |
final public static function sample(string $sample): void | |
{ | |
} | |
} | |
interface SampleInterface | |
{ | |
public function __construct() | |
{ | |
// | |
} | |
} | |
enum SampleEnum: int | |
{ | |
case Sample = 0; | |
} | |
function sample() | |
{ | |
} | |
if (true) { | |
} elseif (false) { | |
} else { | |
} | |
foreach ([] as $foo => $bar) { | |
} | |
for ($i = 0; $i < 10; $i += 1) { | |
} | |
while (true) { | |
} | |
do { | |
} while (true); | |
$numbers = [1, 2, 3, 4, 5]; | |
$string = 'Hello!'; | |
$true = true; | |
$false = false; | |
$null = null; | |
const SAMPLE = 'sample'; | |
sample(); | |
match (true) { | |
sample() => null, | |
default => SAMPLE, | |
}; | |
switch (sample()) { | |
case SAMPLE: | |
break; | |
case sample(): | |
break; | |
default: | |
break; | |
} | |
$string = '<span></span>'; | |
$object = new SampleClass(); | |
$object->public; | |
$object->sampleSample(); | |
SampleClass::$static; | |
SampleClass::sample(sample: SAMPLE); | |
?> | |
<h1> | |
Hello, world! | |
</h1> |
deleugpn
commented
Sep 10, 2023
•
Missing the global
keyword and $var::class
.
trait HasSomething{
use CanDoSoemthing, HasNothing;
}
Hello, I saw your tweet and here's a file from a project I'm currently working on. It's written in Typescript.
import Type from './type'
const asciitree = require('ascii-tree')
export default class Node {
type: Type
value: string | number
children: Node[]
parent: Node | null
constructor(type: Type, value: string | number) {
this.type = type
this.value = type === Type.Number ? Number(value) : value
this.children = []
this.parent = null
}
setParent(parent: Node | null) {
this.parent = parent
}
addChild(child: Node) {
this.children.push(child)
child.setParent(this)
return child
}
replaceChild(search: Node, replace: Node) {
let index = this.children.indexOf(search)
this.children[index] = replace
search.setParent(null)
replace.setParent(this)
}
toString(indent: number = 1) {
let string =
'#'.repeat(indent) +
this.value.toString() +
(this.parent ? ` [${this.parent.value.toString()}]` : ' [null]') +
'\r\n'
this.children.forEach(child => (string += child.toString(indent + 1)))
return indent === 1 ? asciitree.generate(string) : string
}
root(): Node {
return this.parent === null ? this : this.parent.root()
}
insertBetween(parent: Node, child: Node) {
parent.replaceChild(child, this)
this.addChild(child)
}
setChildren(children: Node[]) {
this.children = children
}
clone(): Node {
let node = new Node(this.type, this.value)
this.children.forEach(child => node.addChild(child.clone()))
return node
}
equals(node: Node): boolean {
if (!node) return false
if (this.type !== node.type || this.value !== node.value) return false
return (
!this.children.map((child, index) => child.equals(node.children[index])).includes(false) &&
!node.children.map((child, index) => child.equals(this.children[index])).includes(false)
)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment