Skip to content

Commit

Permalink
improves processing xtag attributes, and add Puretext as a builtin type
Browse files Browse the repository at this point in the history
  • Loading branch information
tealang committed Jul 26, 2024
1 parent d03804f commit 2e9d9e8
Show file tree
Hide file tree
Showing 35 changed files with 656 additions and 325 deletions.
6 changes: 5 additions & 1 deletion compiler/__public.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function get_traces(int $trace_start = 0) {
'Tea\ParameterDoc' => 'ast/base/Docs.php',
'Tea\Identifiable' => 'ast/base/Identifiable.php',
'Tea\AccessingIdentifier' => 'ast/base/Identifiable.php',
'Tea\RuntimeIdentifier' => 'ast/base/Identifiable.php',
'Tea\PlainIdentifier' => 'ast/base/Identifiable.php',
'Tea\ConstantIdentifier' => 'ast/base/Identifiable.php',
'Tea\VariableIdentifier' => 'ast/base/Identifiable.php',
Expand All @@ -148,11 +149,14 @@ function get_traces(int $trace_start = 0) {
'Tea\NoneType' => 'ast/base/Types.php',
'Tea\AnyType' => 'ast/base/Types.php',
'Tea\ObjectType' => 'ast/base/Types.php',
'Tea\IScalarType' => 'ast/base/Types.php',
'Tea\IPureType' => 'ast/base/Types.php',
'Tea\BytesType' => 'ast/base/Types.php',
'Tea\StringType' => 'ast/base/Types.php',
'Tea\FloatType' => 'ast/base/Types.php',
'Tea\PuretextType' => 'ast/base/Types.php',
'Tea\IntType' => 'ast/base/Types.php',
'Tea\UIntType' => 'ast/base/Types.php',
'Tea\FloatType' => 'ast/base/Types.php',
'Tea\BoolType' => 'ast/base/Types.php',
'Tea\IterableType' => 'ast/base/Types.php',
'Tea\ArrayType' => 'ast/base/Types.php',
Expand Down
8 changes: 7 additions & 1 deletion compiler/ast/base/Identifiable.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function __construct(BaseExpression $master, string $name)
}
}

// use for rendering dist code
class RuntimeIdentifier extends Identifiable implements IType
{
const KIND = 'runtime_identifier';
}

class PlainIdentifier extends Identifiable implements IType
{
use ITypeTrait;
Expand All @@ -71,7 +77,7 @@ class PlainIdentifier extends Identifiable implements IType

/**
* is has any operation like accessing or call
* use for render the dist code
* use for rendering dist code
* @var bool
*/
public $is_calling;
Expand Down
47 changes: 34 additions & 13 deletions compiler/ast/base/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public function unite_type(IType $target): IType {
$united = $target->add_single_type($this);
}
else {
if ($this->is_same_with($target)) {
if ($this->is_same_with($target)
|| ($this instanceof StringType and $target instanceof PuretextType)) {
$united = $this;
}
else {
Expand Down Expand Up @@ -372,41 +373,53 @@ public function is_accept_single_type(IType $target) {
}
}

// class ScalarType extends BaseType {
interface IScalarType {}
interface IPureType {}

// class ScalarType extends BaseType implements IScalarType {
// const ACCEPT_TYPES = [_STRING, _INT, _UINT, _BOOL, _XVIEW];
// public $name = _SCALAR;
// }

class BytesType extends BaseType {
class BytesType extends BaseType implements IScalarType {
const ACCEPT_TYPES = [_STRING, _INT, _UINT, _XVIEW];
public $name = _BYTES;
}

class StringType extends BaseType {
const ACCEPT_TYPES = [_BYTES, _INT, _UINT, _XVIEW];
class StringType extends BaseType implements IScalarType {
const ACCEPT_TYPES = [_BYTES, _INT, _UINT, _PURETEXT, _XVIEW];
public $name = _STRING;
}

class FloatType extends BaseType {
class PuretextType extends StringType implements IPureType {
const ACCEPT_TYPES = [_INT, _UINT];
public $name = _FLOAT;
public $name = _PURETEXT;

public function is_same_or_based_with(IType $target) {
return $this->symbol === $target->symbol || TypeFactory::$_string->symbol === $target->symbol;
}
}

class IntType extends BaseType {
class IntType extends BaseType implements IScalarType, IPureType {
const ACCEPT_TYPES = [_UINT];
public $name = _INT;
}

class UIntType extends BaseType {

class UIntType extends IntType {
const ACCEPT_TYPES = [];
public $name = _UINT;

public function is_same_or_based_with(IType $target) {
return $this->symbol === $target->symbol || TypeFactory::$_int->symbol === $target->symbol;
}
}

class BoolType extends BaseType {
class FloatType extends BaseType implements IScalarType, IPureType {
const ACCEPT_TYPES = [_INT, _UINT];
public $name = _FLOAT;
}

class BoolType extends BaseType implements IScalarType {
public $name = _BOOL;
}

Expand All @@ -422,8 +435,16 @@ class IterableType extends SingleGenericType {
// public $key_type;

public function is_same_or_based_with(IType $target) {
return ($this->symbol === $target->symbol || $target->symbol === TypeFactory::$_iterable->symbol)
&& $this->generic_type->is_same_or_based_with($target->generic_type);
if ($this->symbol !== $target->symbol and $target->symbol !== TypeFactory::$_iterable->symbol) {
return false;
}

if ($this->generic_type === null or $target->generic_type === null) {
return $this->generic_type === $target->generic_type
|| ($this->generic_type ?? $target->generic_type) instanceof AnyType;
}

return $this->generic_type->is_same_or_based_with($target->generic_type);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/expression/Interpolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Interpolation extends XTagElement

public $escaping;

public function __construct(BaseExpression $content, bool $escaping)
public function __construct(BaseExpression $content, bool $escaping = false)
{
if ($content instanceof Parentheses) {
$content = $content->expression;
Expand Down
18 changes: 13 additions & 5 deletions compiler/ast/expression/XTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ class XTag extends XTagElement
const KIND = 'xtag';

/**
* @var string | PlainIdentifier
* @var string
*/
public $name;

public $attributes;
/**
* fixed attribute map
* @array
*/
public $default_attributes = [];

/**
* activity attributes expression
* @BaseExpression
*/
public $activity_attributes;

/**
* @var XTagElement[]
Expand All @@ -37,11 +47,9 @@ class XTag extends XTagElement

public $closing_indents;

public function __construct(string $name, array $attributes = [], array $children = null)
public function __construct(string $name)
{
$this->name = $name;
$this->attributes = $attributes;
$this->children = $children;
}
}

Expand Down
Loading

0 comments on commit 2e9d9e8

Please sign in to comment.