Skip to content

Instantly share code, notes, and snippets.

@IMSoP
Created June 7, 2020 14:47
Show Gist options
  • Save IMSoP/a98e33c71f72f9a2c0a44c912540cc94 to your computer and use it in GitHub Desktop.
Save IMSoP/a98e33c71f72f9a2c0a44c912540cc94 to your computer and use it in GitHub Desktop.
<?php
enum Token {
case identifier(string $name) = self(true);
case whitespace = self(true);
case comment(string $comment) = self(false);
public function __construct(public bool $isSignificant);
}
<?php
abstract class Token {
public function __construct(public bool $isSignificant);
}
class identifier extends Token {
public function __construct(public string $name) {
parent::__construct(true);
}
}
class whitespace extends Token {
public function __construct() {
parent::__construct(true);
}
}
class comment extends Token {
public function __construct(public string $comment) {
parent::__construct(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment