From 9484b3c0981605d43b6fbfef705210c85a436a82 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 17 Dec 2020 16:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++ composer.json | 10 ++++++- phpunit.xml.dist => phpunit.xml | 0 src/Grammar/Grammar.php | 15 ++++++++++ src/Grammar/GrammarInterface.php | 15 ++++++++++ src/Output/CnTextOutput.php | 21 +++++++++++++ src/Output/DiagramOutput.php | 15 ++++++++++ src/Output/HTMLOutput.php | 15 ++++++++++ src/Output/OutputInterface.php | 15 ++++++++++ src/Parser/Parser.php | 15 ++++++++++ src/Parser/ParserInterface.php | 15 ++++++++++ src/Reader/FileReader.php | 15 ++++++++++ src/Reader/ReaderInterface.php | 44 ++++++++++++++++++++++++++++ src/Reader/StreamReader.php | 15 ++++++++++ src/Token/Token.php | 22 ++++++++++++++ src/Token/TokenAnd.php | 15 ++++++++++ src/Token/TokenFactory.php | 19 ++++++++++++ src/Token/TokenInterface.php | 15 ++++++++++ src/Token/TokenType.php | 21 +++++++++++++ src/Tokenizer/Tokenizer.php | 15 ++++++++++ src/Tokenizer/TokenizerInterface.php | 15 ++++++++++ 21 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 README.md rename phpunit.xml.dist => phpunit.xml (100%) create mode 100644 src/Grammar/Grammar.php create mode 100644 src/Grammar/GrammarInterface.php create mode 100644 src/Output/CnTextOutput.php create mode 100644 src/Output/DiagramOutput.php create mode 100644 src/Output/HTMLOutput.php create mode 100644 src/Output/OutputInterface.php create mode 100644 src/Parser/Parser.php create mode 100644 src/Parser/ParserInterface.php create mode 100644 src/Reader/FileReader.php create mode 100644 src/Reader/ReaderInterface.php create mode 100644 src/Reader/StreamReader.php create mode 100644 src/Token/Token.php create mode 100644 src/Token/TokenAnd.php create mode 100644 src/Token/TokenFactory.php create mode 100644 src/Token/TokenInterface.php create mode 100644 src/Token/TokenType.php create mode 100644 src/Tokenizer/Tokenizer.php create mode 100644 src/Tokenizer/TokenizerInterface.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..c98a263 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Jerry-DSL + +一个 + +## src目录解析 + +- `Grammar` 语法解析器,验证语法及拆分语法 +- `Output` 输出器,将解析的内容输出(并不执行) +- `Parser` 解析器,使用`Grammar`将内容解析成`Tokenizer`用的东西 +- `Reader` 读取器,供`Tokenizer`读取使用 +- `Token` 所有的Token +- `Tokenizer` Token生成器,生成Token用的 diff --git a/composer.json b/composer.json index 28f42bd..faac855 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { - "name": "q792602257/jerry_dsl", + "name": "jerryyan/dsl", "description": "My DSL Thing", "license": "GPL-3.0-or-later", + "type": "library", "authors": [ { "name": "q792602257", @@ -9,5 +10,12 @@ } ], "require": { + "php": ">=7.1", + "ext-mbstring": "*" + }, + "autoload": { + "psr-4": { + "JerryYan\\DSL\\": "src" + } } } \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 100% rename from phpunit.xml.dist rename to phpunit.xml diff --git a/src/Grammar/Grammar.php b/src/Grammar/Grammar.php new file mode 100644 index 0000000..fcb279e --- /dev/null +++ b/src/Grammar/Grammar.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 14:13 + */ + + +namespace JerryYan\DSL\Grammar; + + +class Grammar extends GrammarInterface +{ + +} \ No newline at end of file diff --git a/src/Grammar/GrammarInterface.php b/src/Grammar/GrammarInterface.php new file mode 100644 index 0000000..79ff66a --- /dev/null +++ b/src/Grammar/GrammarInterface.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 14:11 + */ + + +namespace JerryYan\DSL\Grammar; + + +abstract class GrammarInterface +{ + +} \ No newline at end of file diff --git a/src/Output/CnTextOutput.php b/src/Output/CnTextOutput.php new file mode 100644 index 0000000..7eab8eb --- /dev/null +++ b/src/Output/CnTextOutput.php @@ -0,0 +1,21 @@ + + * @date 2020/12/17 15:33 + */ + + +namespace JerryYan\DSL\Output; + + +/** + * 又以中文形式重新输出一遍 + * @package JerryYan\DSL\Output + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 16:12 + */ +class CnTextOutput extends OutputInterface +{ + +} \ No newline at end of file diff --git a/src/Output/DiagramOutput.php b/src/Output/DiagramOutput.php new file mode 100644 index 0000000..0359eb4 --- /dev/null +++ b/src/Output/DiagramOutput.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:30 + */ + + +namespace JerryYan\DSL\Output; + + +class DiagramOutput extends OutputInterface +{ + +} \ No newline at end of file diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php new file mode 100644 index 0000000..2d16480 --- /dev/null +++ b/src/Output/HTMLOutput.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:09 + */ + + +namespace JerryYan\DSL\Output; + + +class HTMLOutput extends OutputInterface +{ + +} \ No newline at end of file diff --git a/src/Output/OutputInterface.php b/src/Output/OutputInterface.php new file mode 100644 index 0000000..7eeab86 --- /dev/null +++ b/src/Output/OutputInterface.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:08 + */ + + +namespace JerryYan\DSL\Output; + + +abstract class OutputInterface +{ + +} \ No newline at end of file diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php new file mode 100644 index 0000000..fa1d7f0 --- /dev/null +++ b/src/Parser/Parser.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:35 + */ + + +namespace JerryYan\DSL\Parser; + + +class Parser extends ParserInterface +{ + +} \ No newline at end of file diff --git a/src/Parser/ParserInterface.php b/src/Parser/ParserInterface.php new file mode 100644 index 0000000..aebafa1 --- /dev/null +++ b/src/Parser/ParserInterface.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:35 + */ + + +namespace JerryYan\DSL\Parser; + + +abstract class ParserInterface +{ + +} \ No newline at end of file diff --git a/src/Reader/FileReader.php b/src/Reader/FileReader.php new file mode 100644 index 0000000..044f8bd --- /dev/null +++ b/src/Reader/FileReader.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 14:58 + */ + + +namespace JerryYan\DSL\Reader; + + +class FileReader extends ReaderInterface +{ + +} \ No newline at end of file diff --git a/src/Reader/ReaderInterface.php b/src/Reader/ReaderInterface.php new file mode 100644 index 0000000..cfda073 --- /dev/null +++ b/src/Reader/ReaderInterface.php @@ -0,0 +1,44 @@ + + * @date 2020/12/17 14:58 + */ + + +namespace JerryYan\DSL\Reader; + + +/** + * 解析器需要使用到的读取类 + * @package JerryYan\DSL\Reader + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 15:37 + */ +abstract class ReaderInterface +{ + protected $currentLine = 0; + protected $currentPosition = 0; + protected $currentLinePosition = 0; + #abstract public function getNextChar(): ?string; + #abstract public function getCurrentToken(): ?string; + #abstract public function getNextToken(): ?string; + #abstract public function moveToNextToken(): ?string; + + /** + * 跳过当前行 + * @return bool + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 15:43 + */ + #abstract public function skipCurrentLine(): bool; + + /** + * 从当前位置跳到结束位置 + * @param string $end + * @return bool + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 15:43 + */ + #abstract public function skipUntil(string $end="*/"): bool; +} \ No newline at end of file diff --git a/src/Reader/StreamReader.php b/src/Reader/StreamReader.php new file mode 100644 index 0000000..e747621 --- /dev/null +++ b/src/Reader/StreamReader.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 14:58 + */ + + +namespace JerryYan\DSL\Reader; + + +class StreamReader extends ReaderInterface +{ + +} \ No newline at end of file diff --git a/src/Token/Token.php b/src/Token/Token.php new file mode 100644 index 0000000..023add4 --- /dev/null +++ b/src/Token/Token.php @@ -0,0 +1,22 @@ + + * @date 2020/12/17 14:51 + */ + + +namespace JerryYan\DSL\Token; + + +/** + * Token实体分类Enum + * @package JerryYan\DSL\Token + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 15:11 + */ +final class Token +{ + const AND = "And"; + const OR = "Or"; +} \ No newline at end of file diff --git a/src/Token/TokenAnd.php b/src/Token/TokenAnd.php new file mode 100644 index 0000000..19192ff --- /dev/null +++ b/src/Token/TokenAnd.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:20 + */ + + +namespace JerryYan\DSL\Token; + + +class TokenAnd +{ + +} \ No newline at end of file diff --git a/src/Token/TokenFactory.php b/src/Token/TokenFactory.php new file mode 100644 index 0000000..9fe4825 --- /dev/null +++ b/src/Token/TokenFactory.php @@ -0,0 +1,19 @@ + + * @date 2020/12/17 14:48 + */ + + +namespace JerryYan\DSL\Token; + + +class TokenFactory +{ + /** @var array Token类型及映射类 */ + #private $tokenMap = [ + # Token::AND => TokenAnd::class, + #]; + +} \ No newline at end of file diff --git a/src/Token/TokenInterface.php b/src/Token/TokenInterface.php new file mode 100644 index 0000000..87799c5 --- /dev/null +++ b/src/Token/TokenInterface.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 14:23 + */ + + +namespace JerryYan\DSL\Token; + + +abstract class TokenInterface +{ + +} \ No newline at end of file diff --git a/src/Token/TokenType.php b/src/Token/TokenType.php new file mode 100644 index 0000000..abea02f --- /dev/null +++ b/src/Token/TokenType.php @@ -0,0 +1,21 @@ + + * @date 2020/12/17 15:04 + */ + + +namespace JerryYan\DSL\Token; + + +/** + * Token分类Enum + * @package JerryYan\DSL\Token + * @author Jerry Yan <792602257@qq.com> + * @date 2020/12/17 15:04 + */ +final class TokenType +{ + +} \ No newline at end of file diff --git a/src/Tokenizer/Tokenizer.php b/src/Tokenizer/Tokenizer.php new file mode 100644 index 0000000..c7b1958 --- /dev/null +++ b/src/Tokenizer/Tokenizer.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:22 + */ + + +namespace JerryYan\DSL\Tokenizer; + + +class Tokenizer extends TokenizerInterface +{ + +} \ No newline at end of file diff --git a/src/Tokenizer/TokenizerInterface.php b/src/Tokenizer/TokenizerInterface.php new file mode 100644 index 0000000..729b11e --- /dev/null +++ b/src/Tokenizer/TokenizerInterface.php @@ -0,0 +1,15 @@ + + * @date 2020/12/17 15:22 + */ + + +namespace JerryYan\DSL\Tokenizer; + + +abstract class TokenizerInterface +{ + +} \ No newline at end of file