更多Token类型
This commit is contained in:
parent
9610d0609d
commit
ca612f74f2
@ -15,8 +15,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.0",
|
||||
"mockery/mockery": "^1.4",
|
||||
"phpstan/phpstan": "^0.12.68"
|
||||
"mockery/mockery": "^1.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -10,20 +10,26 @@ namespace JerryYan\DSL\Token\Factory;
|
||||
|
||||
|
||||
use JerryYan\DSL\Token\Token;
|
||||
use JerryYan\DSL\Token\TokenLogicAnd;
|
||||
use JerryYan\DSL\Token\TokenDefine;
|
||||
use JerryYan\DSL\Token\TokenFake;
|
||||
use JerryYan\DSL\Token\TokenLogicAnd;
|
||||
use JerryYan\DSL\Token\TokenLogicEqual;
|
||||
use JerryYan\DSL\Token\TokenLogicFake;
|
||||
use JerryYan\DSL\Token\TokenLogicOr;
|
||||
use JerryYan\DSL\Token\TokenUseVariable;
|
||||
use JerryYan\DSL\Token\TokenVariable;
|
||||
|
||||
class DefaultFactory extends FactoryInterface
|
||||
{
|
||||
protected $tokenMap = [
|
||||
Token::FAKE => TokenFake::class,
|
||||
Token::LOGIC_AND => TokenLogicAnd::class,
|
||||
Token::LOGIC_OR => TokenLogicOr::class,
|
||||
Token::LOGIC_EQUAL => TokenLogicEqual::class,
|
||||
Token::LOGIC_FAKE => TokenLogicFake::class,
|
||||
Token::VARIABLE => TokenVariable::class,
|
||||
Token::DEFINE => TokenDefine::class,
|
||||
Token::USE_VARIABLE => TokenUseVariable::class,
|
||||
];
|
||||
|
||||
protected $undefinedTokenClass = TokenVariable::class;
|
||||
|
@ -22,23 +22,36 @@ final class Token
|
||||
const LOGIC_AND = "LOGIC_AND";
|
||||
const LOGIC_NOT = "LOGIC_NOT";
|
||||
const LOGIC_EQUAL = "LOGIC_EQUAL";
|
||||
const LOGIC_EQUAL_STRONG = "LOGIC_EQUAL_STRONG";
|
||||
const LOGIC_NOT_EQUAL = "LOGIC_NOT_EQUAL";
|
||||
const LOGIC_NOT_EQUAL_STRONG = "LOGIC_NOT_EQUAL_STRONG";
|
||||
const LOGIC_GREATER = "LOGIC_GREATER";
|
||||
const LOGIC_GREATER_EQUAL = "LOGIC_GREATER_EQUAL";
|
||||
const LOGIC_LESS = "LOGIC_LESS";
|
||||
const LOGIC_LESS_EQUAL = "LOGIC_LESS_EQUAL";
|
||||
const LOGIC_FAKE = "LOGIC_FAKE";
|
||||
// 变量相关
|
||||
const DEFINE = "DEFINE";
|
||||
const USE_VARIABLE = "USE_VARIABLE";
|
||||
const VARIABLE = "VARIABLE";
|
||||
const VAR_ASSIGN = "VAR_ASSIGN";
|
||||
const ASSIGN = "ASSIGN";
|
||||
const CALL = "CALL";
|
||||
const FAKE = "FAKE";
|
||||
// 运算符相关
|
||||
const OP_CONCAT = "Concat";
|
||||
const OP_CONCAT = "OP_CONCAT";
|
||||
const OP_CONCAT_EQUAL = "OP_CONCAT_EQUAL";
|
||||
const OP_PLUS = "OP_PLUS";
|
||||
const OP_PLUS_EQUAL = "OP_PLUS_EQUAL";
|
||||
const OP_MINUS = "OP_MINUS";
|
||||
const OP_MINUS_EQUAL = "OP_MINUS_EQUAL";
|
||||
const OP_MULTIPLY = "OP_MULTIPLY";
|
||||
const OP_MULTIPLY_EQUAL = "OP_MULTIPLY_EQUAL";
|
||||
const OP_DIVIDE = "OP_DIVIDE";
|
||||
const OP_DIVIDE_EQUAL = "OP_DIVIDE_EQUAL";
|
||||
const OP_MOD = "OP_MOD";
|
||||
const OP_MOD_EQUAL = "OP_MOD_EQUAL";
|
||||
const OP_POW = "OP_POW";
|
||||
const OP_POW_EQUAL = "OP_POW_EQUAL";
|
||||
// 逻辑运算相关
|
||||
const OP_OR = "OP_OR";
|
||||
const OP_AND = "OP_AND";
|
||||
|
17
src/Token/TokenFake.php
Normal file
17
src/Token/TokenFake.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @filename TokenFake.php
|
||||
* @author Jerry Yan <792602257@qq.com>
|
||||
* @date 2021/1/22 16:45
|
||||
*/
|
||||
|
||||
|
||||
namespace JerryYan\DSL\Token;
|
||||
|
||||
|
||||
class TokenFake extends TokenInterface
|
||||
{
|
||||
public static $alias = [
|
||||
'然后', '之后'
|
||||
];
|
||||
}
|
@ -11,5 +11,7 @@ namespace JerryYan\DSL\Token;
|
||||
|
||||
class TokenLogicEqual extends TokenInterface
|
||||
{
|
||||
|
||||
public static $alias = [
|
||||
'等于'
|
||||
];
|
||||
}
|
17
src/Token/TokenLogicFake.php
Normal file
17
src/Token/TokenLogicFake.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @filename TokenLogicFake.php
|
||||
* @author Jerry Yan <792602257@qq.com>
|
||||
* @date 2021/1/22 16:56
|
||||
*/
|
||||
|
||||
|
||||
namespace JerryYan\DSL\Token;
|
||||
|
||||
|
||||
class TokenLogicFake extends TokenInterface
|
||||
{
|
||||
public static $alias = [
|
||||
'当', '的时候', '时'
|
||||
];
|
||||
}
|
@ -12,6 +12,6 @@ namespace JerryYan\DSL\Token;
|
||||
class TokenLogicOr extends TokenInterface
|
||||
{
|
||||
public static $alias = [
|
||||
'或者'
|
||||
'或', '或者'
|
||||
];
|
||||
}
|
17
src/Token/TokenUseVariable.php
Normal file
17
src/Token/TokenUseVariable.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @filename TokenDefine.php
|
||||
* @author Jerry Yan <792602257@qq.com>
|
||||
* @date 2021/1/22 9:41
|
||||
*/
|
||||
|
||||
|
||||
namespace JerryYan\DSL\Token;
|
||||
|
||||
|
||||
class TokenUseVariable extends TokenInterface
|
||||
{
|
||||
public static $alias = [
|
||||
'把', '将'
|
||||
];
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
namespace JerryYan\DSL\Test\Token;
|
||||
|
||||
use JerryYan\DSL\Token\TokenLogicAnd;
|
||||
use JerryYan\DSL\Token\TokenDefine;
|
||||
use JerryYan\DSL\Token\TokenLogicEqual;
|
||||
use JerryYan\DSL\Token\TokenUseVariable;
|
||||
use JerryYan\DSL\Token\TokenInterface;
|
||||
use JerryYan\DSL\Token\TokenLogicOr;
|
||||
use JerryYan\DSL\Token\TokenUndefined;
|
||||
@ -20,7 +21,8 @@ class TokenInterfaceTest extends TestCase
|
||||
/** @var class-string<TokenInterface>[] TokenClass */
|
||||
private $tokenTypes = [
|
||||
TokenLogicAnd::class,
|
||||
TokenDefine::class,
|
||||
TokenLogicEqual::class,
|
||||
TokenUseVariable::class,
|
||||
TokenLogicOr::class,
|
||||
TokenUndefined::class,
|
||||
TokenVariable::class,
|
||||
|
@ -11,6 +11,7 @@ use JerryYan\DSL\Reader\StringReader;
|
||||
use JerryYan\DSL\Token\Factory\DefaultFactory;
|
||||
use JerryYan\DSL\Token\TokenLogicAnd;
|
||||
use JerryYan\DSL\Token\TokenInterface;
|
||||
use JerryYan\DSL\Token\TokenLogicFake;
|
||||
use JerryYan\DSL\Token\TokenLogicOr;
|
||||
use JerryYan\DSL\Token\TokenVariable;
|
||||
use JerryYan\DSL\Tokenizer\Tokenizer;
|
||||
@ -20,9 +21,10 @@ class TokenizerTest extends TestCase
|
||||
{
|
||||
protected $tokenizer;
|
||||
protected $reader;
|
||||
private $text = "这个 和 那个 或者 那个 和 这个";
|
||||
private $text = "当 这个 和 那个 或者 那个 和 这个 的时候";
|
||||
/** @var class-string<TokenInterface>[] 预期的类型 */
|
||||
private $textTokenType = [
|
||||
TokenLogicFake::class,
|
||||
TokenVariable::class,
|
||||
TokenLogicAnd::class,
|
||||
TokenVariable::class,
|
||||
@ -30,6 +32,7 @@ class TokenizerTest extends TestCase
|
||||
TokenVariable::class,
|
||||
TokenLogicAnd::class,
|
||||
TokenVariable::class,
|
||||
TokenLogicFake::class,
|
||||
];
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user