- */
-public abstract class Node {
-
- public static final int UNDEFINED = 0;
- /**
- * 作为文档树的根的文档对象提供对整个 OTPL 文档的访问。
- */
- public static final int DOCUMENT = 1;
- /**
- * 表示一个独立的节点,它不能含有子节点。
- */
- public static final int SPAN = 2;
- /**
- * 表示一个块节点,它必须使用一对{node}{/node}
来指示完整的块。
- */
- public static final int BLOCK = 3;
- /**
- * 表示文本节点。 它是一个特殊的 SPAN 节点,唯一不同是因为它不能被语法解析。
- */
- public static final int TEXT = 4;
-
- /**
- * 表示块节点的结束。
- */
- public static final int END_BLOCK = 5;
-
- private Block parent;
- private Node prev;
- private Node next;
-
- /**
- * 获取一个值,以指示当前节点是否是块结点。
- *
- * @return
- */
- public abstract boolean isBlock();
-
- /**
- * 获取一个值,以指示当前节点是否是文本结点。
- *
- * @return
- */
- public abstract boolean isText();
-
- /**
- * 获取一个值,以指示当前文档的根类型。
- *
- * @return
- */
- public abstract boolean isDocument();
-
- /**
- * 获取一个值,以指示当前文档的根类型。
- *
- * @return
- */
- public abstract boolean isEndBlock();
-
- /**
- * 获取当前节点的名称。
- *
- * @return
- */
- public abstract String getName();
-
- /**
- * 获取当前节点的类型。
- *
- * @return
- */
- public abstract int getNodeType();
-
- /**
- * 获取该节点(对于可以具有父级的节点)的父级。
- *
- * @return
- */
- public Block getParent() {
- return parent;
- }
-
- /**
- * 获取紧接在该节点之后的节点。
- *
- * @return
- */
- public final Node getNext() {
- return next;
- }
-
- /**
- * 获取紧接在该节点之前的节点。
- *
- * @return
- */
- public final Node getPrev() {
- return prev;
- }
-
- /**
- * 获取所属的文档。
- *
- * @return
- */
- public abstract Document getOwnerDocument();
-
- /**
- * 获取编译器
- *
- * @return
- */
- public abstract Compiler getCompiler();
-
- /**
- * 关联节点。
- *
- * 注意:该方法只应在append方法中调用。
- *
- * @param parent 父级
- * @param prev 上个节点
- */
- public final void associate(Block parent, Node prev) {
- this.parent = parent;
- this.prev = prev;
- if (prev != null) {
- prev.next = this;
- }
- }
-
- /**
- * 获取行号
- * @return
- */
- public abstract int getLineNumber();
-
- /**
- * 获取未解析的源码
- * @return
- */
- public abstract CharSequence getSource();
-
- /**
- * 一个临时标记
- */
- public boolean marked;
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Parser.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Parser.java
deleted file mode 100644
index abc9141..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Parser.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl;
-
-import com.diosay.otpl.lexers.BodyLexer;
-import com.diosay.otpl.lexers.BreakLexer;
-import com.diosay.otpl.lexers.ContinueLexer;
-import com.diosay.otpl.lexers.EachLexer;
-import com.diosay.otpl.lexers.ElifLexer;
-import com.diosay.otpl.lexers.ElseLexer;
-import com.diosay.otpl.lexers.ForLexer;
-import com.diosay.otpl.lexers.IfLexer;
-import com.diosay.otpl.lexers.IncludeLexer;
-import com.diosay.otpl.lexers.LayoutLexer;
-import com.diosay.otpl.lexers.PlaceLexer;
-import com.diosay.otpl.lexers.PrintLexer;
-import com.diosay.otpl.lexers.SectionLexer;
-import com.diosay.otpl.lexers.TextLexer;
-import com.diosay.otpl.lexers.VariableLexer;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.*;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-/**
- * 实现OTPL解析器与DOM编译器
- *
- * @author jun
- */
-public class Parser extends Compiler {
-
- int line;
- Document document;
- boolean inLiteral = false;
- boolean inComment = false;
-
- /**
- * 打开文件,并尝试移除UTF BOM。
- *
- * @param file
- * @return
- * @throws FileNotFoundException
- * @throws IOException
- */
- public static BufferedReader open(String file) throws FileNotFoundException, IOException {
- FileInputStream input = new FileInputStream(file);
- String encoding = "UTF-8";
- byte bom[] = new byte[4];
-
- int removed;
- try {
- input.read(bom, 0, bom.length);
- } catch (Throwable ex) {
- //ignored
- }
-
- if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00)
- && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
- encoding = "UTF-32BE";
- removed = 4;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)
- && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
- encoding = "UTF-32LE";
- removed = 4;
- } else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB)
- && (bom[2] == (byte) 0xBF)) {
- encoding = "UTF-8";
- removed = 3;
- } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
- encoding = "UTF-16BE";
- removed = 2;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
- encoding = "UTF-16LE";
- removed = 2;
- } else {
- removed = 0;
- }
- input.close();
- input = new FileInputStream(file);
- if (removed > 0) {
- input.read(bom, 0, removed);
- }
- return new BufferedReader(new InputStreamReader(input, encoding));
- }
-
- /**
- * 解析一个OTPL流,并构建一个 Document。
- *
- * @param input 输入流。
- * @param basedir 用于查找源文件的根目录。
- * @param encoding 用于解析源文件的编码。
- * @param sourceFile 全限定路径源文件,可空。
- * @return
- */
- public static Document parsexxxxx(BufferedReader reader, String basedir, String sourceFile) throws Exception {
-
- String line;
- StringBuilder sb;
- Parser parser = new Parser();
- parser.line = 0; //reset
- parser.document = new Document(parser, sourceFile);
- parser.regsisterLexer(new IfLexer());
- int index;
- int end;
- int[] arr;
- while ((line = reader.readLine()) != null) {
- parser.line++;
- sb = new StringBuilder(line);
- sb.append('\r').append('\n');
- end = sb.length();
- index = 0;
-
- do {
-
- if ((arr = StringUtil.findSegment(sb, "{{", "}}", index, end)) != null) {
-
- } else if ((arr = StringUtil.findSegment(sb, "", index, end)) != null) {
-
- } else {
- break;
- }
-
- if (arr[0] - index - 2 != 0) {
- parser.onText(sb, index, arr[0] - 2);
- }
- parser.onMarkup(sb, arr[0], arr[1]);
- index = arr[1] + 2;
-
- } while (true);
-
- if (index < end) {
- parser.onText(sb, index, end);
- }
- }
- return null;
- }
-
- /**
- * 解析一个OTPL流,并构建一个 Document。
- *
- * @param input 输入流。
- * @param basedir 用于查找源文件的根目录。
- * @param encoding 用于解析源文件的编码。
- * @param sourceFile 全限定路径源文件,可空。
- * @return
- */
- public Document parse(BufferedReader reader, String sourceFile) throws Exception {
-
- String line;
- StringBuilder sb;
- this.line = 0; //reset
- this.document = new Document(this, sourceFile);
- this.regsisterLexer(new IfLexer());
- this.regsisterLexer(new ElifLexer());
- this.regsisterLexer(new ElseLexer());
- this.regsisterLexer(new EachLexer());
- this.regsisterLexer(new PrintLexer());
- this.regsisterLexer(new TextLexer());
- this.regsisterLexer(new BodyLexer());
- this.regsisterLexer(new LayoutLexer());
- this.regsisterLexer(new SectionLexer());
- this.regsisterLexer(new PlaceLexer());
- this.regsisterLexer(new ForLexer());
- this.regsisterLexer(new VariableLexer());
- this.regsisterLexer(new BreakLexer());
- this.regsisterLexer(new ContinueLexer());
- this.regsisterLexer(new IncludeLexer());
- int index;
- int end;
- int[] arr;
- while ((line = reader.readLine()) != null) {
- this.line++;
- sb = new StringBuilder(line);
- sb.append('\r').append('\n');
- end = sb.length();
- index = 0;
-
- do {
-
- if ((arr = StringUtil.findSegment(sb, "{{", "}}", index, end)) != null) {
- boolean lft = false;
- boolean rgt = false;
- int tmp = 0;
- int tmp2 = 0;
- for (int i = arr[0] - 3; i >= index; i--) {
- if (StringUtil.isWhitespace(sb.charAt(i))) {
- continue;
- } else if (i - 3 >= index && sb.charAt(i - 3) == '<' && sb.charAt(i - 2) == '!' && sb.charAt(i - 1) == '-' && sb.charAt(i) == '-') {
- //
- rgt = true;
- tmp2 = i + 2;
-
- for (; tmp2 < end; tmp2++) {
- if (!(StringUtil.isWhitespace(sb.charAt(tmp2)) || sb.charAt(tmp2) == '\r' || sb.charAt(tmp2) == '\n')) {
- break;
- }
- }
- break;
- } else {
- break;
- }
- }
- }
-
- if (lft && rgt) {
- if (tmp - index > 0) {
- this.onText(sb, index, tmp);
- }
- this.onMarkup(sb, arr[0], arr[1]);
- index = tmp2 + 1;
- } else {
- if (arr[0] - index - 2 != 0) {
- this.onText(sb, index, arr[0] - 2);
- }
- this.onMarkup(sb, arr[0], arr[1]);
- index = arr[1] + 2;
- }
- } else {
- break;
- }
-
- } while (true);
-
- if (index < end) {
- this.onText(sb, index, end);
- }
- }
- return this.document;
- }
-
- /**
- * 当发现文本时。
- */
- protected void onText(CharSequence source, int start, int end) {
- if(inComment){
- return;
- }
- Text text = new Text(this.document, this.line);
- text.setCompiler((Compiler) lexers.get("text"));
- text.setSource(source, start, end);
- this.document.append(text);
- //System.out.println(source.subSequence(index, end).toString());
- }
-
- protected void reportError(String msg) {
- throw new mano.InvalidOperationException("行 " + this.line + " 有语法错误:" + msg);
- }
-
- /**
- * 注册一个词条。
- */
- public void regsisterLexer(Lexer lexer) {
- lexers.put(lexer.getToken(), lexer);
- }
-
- private HashMap lexers = new HashMap<>();
-
- /**
- * 当解析到标记时。
- */
- protected void onMarkup(CharSequence source, int start, int end) {
- start = StringUtil.trimLeftWhitespace(source, start, end);//移除开始的线性空白
- int tmp;
- if ((tmp = StringUtil.findKeyword(source, "/literal", start, end)) != -1
- && !StringUtil.isAlphanumeric(source, tmp + 1, end)) { //原样输出结束
- if (!inComment) {
- if (!inLiteral) {
- reportError("错误的原样结束标签");
- inLiteral = true; //修正错误继续解析
- }
- inLiteral = false;
- }
-
- } else if (inLiteral) {
- this.onText(source, start - 2, end + 2);
- } else if ((tmp = StringUtil.findKeyword(source, "*/", start, end)) != -1) { //块注释结束
- this.inComment = false;
- } else if ((tmp = StringUtil.findKeyword(source, "/*", start, end)) != -1) {//块注释开始
- this.inComment = true;
- } else if (inComment || (tmp = StringUtil.findKeyword(source, "//", start, end)) != -1) { //当前为注释中
- //ignored
- } else if ((tmp = StringUtil.findKeyword(source, "literal", start, end)) != -1
- && !StringUtil.isAlphanumeric(source, tmp + 1, end)) { //原样输出开始
- inLiteral = true;
- } else {
- final int tmpstart = start;
- final int tmpend = end;
- if (!lexers.values().stream().anyMatch(lexer -> {
- if (!lexer.isBlock()) {
- return false;
- }
- int tmp2;
- if ((tmp2 = StringUtil.findKeyword(source, "/" + lexer.getToken(), tmpstart, tmpend)) != -1
- && StringUtil.isEnd(source, tmp2 + 1, tmpend)) {
- document.append(document.createEndBlock(source.subSequence(tmpstart + 1, tmp2).toString(), line));
- //System.out.println("find end=====" + source.subSequence(tmpstart, tmp2));
- return true;
- }
- return false;
- })) {
- tmp = StringUtil.findIdentifier(source, start, end);
- if (tmp != -1 && this.tryLex(source.subSequence(start, tmp).toString(), source, tmp, end)) {
- //nothing
- } else { //打印
- Lexer lexer = lexers.get("print");
- if (lexer == null) {
- reportError("print 词条未定义");
- }
- lexer.parse(document, source, start, end, line);
- //System.out.println(source.subSequence(start, end));
- }
- }
- }
- }
-
- protected boolean tryLex(String token, CharSequence source, int start, int end) {
- if (lexers.values().stream().anyMatch(lexer -> {
-
- if (!lexer.getToken().equalsIgnoreCase(token)) {
- return false;
- }
- lexer.parse(document, source, start, end, line);
- return true;
- })) {
- return true;
- }
- //reportError("词条 " + token + " 未定义");
- //System.out.println("TOKEN====" + token);
- return false;
- }
-
- /**
- * 编译dom
- *
- * @param node
- * @param list
- */
- @Override
- public void compile(Node node, ArrayList list) {
-
- Document dom = (Document) node;
-
- //TODO
- for (Node sub : dom.blocks) {
- sub.getCompiler().compile(sub, list);
- }
-
- list.add(new EndHeader());
-
- if (dom.layout != null) {
- dom.layout.getCompiler().compile(dom.layout, list);
- }
-
- for (Node sub : dom.children) {
- sub.getCompiler().compile(sub, list);
- }
- }
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Span.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Span.java
deleted file mode 100644
index 07af675..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Span.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl;
-
-/**
- * 表示一个单节点。
- *
- * @author jun
- */
-public class Span extends Node {
-
- private String name;
-
- public Span(String name) {
- this.name = name;
- }
-
- @Override
- public final boolean isBlock() {
- return false;
- }
-
- @Override
- public final boolean isText() {
- return false;
- }
-
- @Override
- public final boolean isDocument() {
- return false;
- }
-
- @Override
- public final boolean isEndBlock() {
- return false;
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public int getNodeType() {
- return Node.SPAN;
- }
-
- @Override
- public Document getOwnerDocument() {
- return dom;
- }
-
- @Override
- public Compiler getCompiler() {
- return compiler;
- }
-
- private Compiler compiler;
- private Document dom;
- private CharSequence source;
- private int start;
- private int end;
- private int line;
-
- /**
- * 设置编译器
- *
- * @param compiler
- */
- public void setCompiler(Compiler compiler) {
- this.compiler = compiler;
- }
-
- /**
- * 设置行号
- *
- * @param line
- */
- public void setLineNumber(int line) {
- this.line = line;
- }
-
- /**
- * 设置源码
- *
- * @param source
- * @param start
- * @param end
- */
- public void setSource(CharSequence source, int start, int end) {
- for (; start < end && start < source.length(); start++) {
- if (!StringUtil.isWhitespace(source.charAt(start))) {
- break;
- }
- }
- this.source = source.subSequence(start, end);
- }
-
- @Override
- public int getLineNumber() {
- return this.line;
- }
-
- @Override
- public CharSequence getSource() {
- return this.source;
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/StringUtil.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/StringUtil.java
deleted file mode 100644
index 3f82b0c..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/StringUtil.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl;
-
-/**
- * 字符串工具类。
- *
- * @author jun
- */
-public class StringUtil {
-
- /**
- * 判断是否是数字。
- *
- * @param c
- * @return
- */
- public static boolean isDigital(char c) {
- return (c >= 48 && c <= 57);
- }
-
- /**
- * 判断是否是字母
- *
- * @param c
- * @return
- */
- public static boolean isLetter(char c) {
- return (c >= 65 && c <= 90 || c >= 97 && c <= 122);
- }
-
- /**
- * 判断是否是字母或数字
- *
- * @param c
- * @return
- */
- public static boolean isAlphanumeric(char c) {
- return isDigital(c) || isLetter(c);
- }
-
- /**
- * 判断索引处是否是字母或数字。
- *
- * @param source
- * @param start
- * @param end
- * @return
- */
- public static boolean isAlphanumeric(CharSequence source, int start, int end) {
- if (start >= end || start >= source.length()) {
- return false;
- }
- return isAlphanumeric(source.charAt(start));
- }
-
- /**
- * 是否是空白字符
- *
- * @param c
- * @return
- */
- public static boolean isWhitespace(char c) {
- return (c == ' ' || c == '\t');
- }
-
- /**
- * 是否是空白字符
- *
- * @param c
- * @return
- */
- public static int trimLeftWhitespace(CharSequence source, int start, int end) {
- if (source == null || start < 0 || start >= end || start >= source.length()) {//标准
- return start;
- }
- for (; start < end && start < source.length(); start++) {
- if (!isWhitespace(source.charAt(start))) {
- return start;
- }
- }
- return start;
- }
-
- public static int findIdentifier(CharSequence source, int start, int end) {
- if (source == null || start < 0 || start > source.length() || !isLetter(source.charAt(start))) {
- return -1;
- }
- int ori = start;
- for (; start < end && start < source.length(); start++) {
- if (!isAlphanumeric(source.charAt(start))) {
- break;
- }
- }
- return ori == start ? -1 : start;
- }
-
- public static int parseNumber(CharSequence source, int start, int end) {
- if (source == null || start < 0 || start > source.length()) {
- return -1;
- }
- int ori = start;
- for (; start < end && start < source.length(); start++) {
- if (!isDigital(source.charAt(start))) {
- //bounds
- break;
- }
- }
- return ori == start ? -1 : start;
- }
-
- /**
- * 查找双引号字符串
- *
- * @param source
- * @param start
- * @param end
- * @return
- */
- public static int findString(CharSequence source, int start, int end) {
- if (source == null || start < 0 || start > source.length()) {
- return -1;
- }
-
- for (; start < end && start < source.length(); start++) {
- if ('\\' == source.charAt(start) && start + 1 < end && '"' == source.charAt(start + 1)) {
-
- } else if ('"' == source.charAt(start)) {
- return start;
- }
- }
- return -1;
- }
-
- /**
- * 查找单引号字符串
- *
- * @param source
- * @param start
- * @param end
- * @return
- */
- public static int findStringEx(CharSequence source, int start, int end) {
- if (source == null || start < 0 || start > source.length()) {
- return -1;
- }
-
- for (; start < end && start < source.length(); start++) {
- if ('\\' == source.charAt(start) && start + 1 < end && '\'' == source.charAt(start + 1)) {
-
- } else if ('\'' == source.charAt(start)) {
- return start;
- }
- }
- return -1;
- }
-
- /**
- * 查找一个片段。
- *
- * @param source
- * @param left
- * @param right
- * @param start
- * @param end
- * @param ignores 主要用途是忽略内部字符串。
- * @return 成功返回结束的索引对,否则返回 null.
- */
- public static int[] findSegment(CharSequence source, CharSequence left, CharSequence right, int start, int end) {
-
- if (source == null || left == null || right == null || start < 0 || end < 0 || end - start > source.length() || left.length() == 0 || right.length() == 0) {
- return null;
- }
- boolean like = left.equals(right);
- int index = -1;
- int matches = 0;
- for (; start < end && start < source.length(); start++) {
- if (source.charAt(start) == '\\') {//转义
- start++;
- } else if (!like && source.charAt(start) == left.charAt(0)) {//确定开始
- boolean tmp = true;
- for (int i = 0; i < left.length(); i++) {
- if (i + start > end || source.charAt(start + i) != left.charAt(i)) {
- tmp = false;
- break;
- }
- }
- if (tmp) {
- if (index == -1) {
- index = start + left.length();
- }
- start += left.length();
- matches++;
- }
- } else if (source.charAt(start) == right.charAt(0)) {//确定结束
- boolean tmp = true;
- for (int i = 0; i < right.length(); i++) {
- if (i + start > end || source.charAt(start + i) != right.charAt(i)) {
- tmp = false;
- break;
- }
- }
- if (tmp) {
- if (like && index == -1) {
- index = start + left.length();
- }
- matches--;
- if (index > 0 && matches == 0) {
- return new int[]{index, start};
- }
- start += right.length();
- }
- }
- }
-
- return null;
- }
-
- /**
- * 查找子字符序列的首次出现位置。
- *
- * @param source
- * @param sub
- * @param start
- * @param end
- * @param ignores
- * @return 成功返回结束的索引,否则返回 -1.
- */
- public static int indexOf(CharSequence source, CharSequence sub, int start, int end, char... ignores) {
- if (source == null || sub == null || start < 0 || end < 0 || end - start > source.length() || sub.length() == 0) {
- return -1;
- }
- char c;
- boolean tmp;
- for (; start < end && start < source.length(); start++) {
- c = source.charAt(start);
-
- if (ignores != null) {
- tmp = false;
- for (int k = 0; k < ignores.length; k++) {//避免字符复制
- if (ignores[k] == c) {
- tmp = true;
- break;
- }
- }
- if (tmp) {
- continue;
- }
- }
- if ('\\' == c) {
- //nothing
- } else if (sub.charAt(0) == c) {
- tmp = true;
- for (int k = 1; k < sub.length(); k++) {
- if (k + start > end || source.charAt(start + k) != sub.charAt(k)) {
- tmp = false;
- break;
- }
- }
- if (tmp) {
- return start;
- }
- }
- }
- return -1;
- }
-
- public boolean inCharArray(char c, char... array) {
- if (array == null) {
- return false;
- }
- for (int k = 0; k < array.length; k++) {
- if (array[k] == c) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 判断start是否是索引的结束。
- *
- * @param c
- * @return
- */
- public static boolean isEnd(CharSequence source, int start, int end) {
- if (start >= end || start >= source.length()) {
- return true;
- }
- return false;
- }
-
- public static int findKeyword(CharSequence source, CharSequence key, int index, int end) {
- if (key == null || key.length() == 0 || source == null || source.length() == 0) {
- return -1;
- }
- boolean tmp = false;
- for (; index < end && index < source.length(); index++) { //移除空白字符
- if (!isWhitespace(source.charAt(index))) {
- break;
- }
- }
-
- for (; index < end && index < source.length(); index++) {
- if (source.charAt(index) == key.charAt(0)) {
- tmp = true;
- for (int i = 0; i < key.length(); i++) {
- if (index + i >= end || source.charAt(index + i) != key.charAt(i)) {
- tmp = false;
- break;
- }
- }
- if (tmp) {
- break;
- } else {
- index++;
- }
- } else {
- return -1;
- }
- }
- if (tmp) {
- return index + key.length();
- }
- return -1;
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Text.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Text.java
deleted file mode 100644
index ca51627..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Text.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl;
-
-/**
- * 纯文本。
- * @author jun
- */
-public class Text extends Node {
-
- public Text(Document dom,int line){
- this.dom=dom;
- this.line=line;
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public boolean isText() {
- return true;
- }
-
- @Override
- public boolean isDocument() {
- return false;
- }
-
- @Override
- public boolean isEndBlock() {
- return false;
- }
-
- @Override
- public String getName() {
- return "text";
- }
-
- @Override
- public int getNodeType() {
- return Node.TEXT;
- }
-
- @Override
- public Document getOwnerDocument() {
- return dom;
- }
-
- @Override
- public Compiler getCompiler() {
- return compiler;
- }
- private Compiler compiler;
- private Document dom;
- private CharSequence source;
- private int start;
- private int end;
- private int line;
- /**
- * 设置编译器
- *
- * @param compiler
- */
- public void setCompiler(Compiler compiler) {
- this.compiler=compiler;
- }
- /**
- * 设置行号
- * @param line
- */
- public void setLineNumber(int line){
- this.line=line;
- }
- /**
- * 设置源码
- * @param source
- * @param start
- * @param end
- */
- public void setSource(CharSequence source, int start, int end){
- this.source=source.subSequence(start, end);
- }
-
- @Override
- public int getLineNumber() {
- return this.line;
- }
-
- @Override
- public CharSequence getSource() {
- return this.source;
- }
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Token.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Token.java
deleted file mode 100644
index daecb12..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/Token.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl;
-
-import java.util.ArrayList;
-
-/**
- * 表示一个词法元素。
- * @author jun
- */
-public class Token extends ArrayList{
-
- public static final int ID = 1;
- public static final int REAL = 2;
- public static final int LONG = 3;
- public static final int STR = 4;
- public static final int BLK = 5;
-
- public static final int MUL = 6; // *
- public static final int DIV = 7; // /
- public static final int MOD = 8; // %
-
- public static final int ADD = 9; // +
- public static final int SUB = 10; // -
-
- public static final int ASSIGN = 11; // =
-
- public static final int OR = 12; // ||
- public static final int AND = 13; // &&
-
- public static final int GT = 14; // >
- public static final int GTE = 15; // >=
- public static final int LT = 16; // <
- public static final int LTE = 17; // <=
-
- public static final int EQ = 18; // ==
- public static final int NEQ = 19; // !=
-
- public static final int QM = 20; // ?
- public static final int DOT = 21; // .
- public static final int COMMA = 22; // ,
- public static final int COLON = 23; // :
- public static final int EM = 24; // !
- public static final int NC = 25; // ??
-
-
- public static final int OP = 26; // (
- public static final int CP = 27; // )
- public static final int OB = 28; // [
- public static final int CB = 29; // ]
-
- public static final int VL = 31; // |
-
-
- public int type;
- public String code;
- public int line;
- //public ArrayList children = new ArrayList<>();
-
- @Override
- public String toString(){
- return super.toString()+" type="+type+" code="+code;
- }
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BodyLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BodyLexer.java
deleted file mode 100644
index 8e09782..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BodyLexer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.Body;
-import com.diosay.otpl.runtime.opcodes.Layout;
-import java.util.ArrayList;
-
-/**
- *
- * @author jun
- */
-public class BodyLexer extends com.diosay.otpl.Compiler implements Lexer{
-
- @Override
- public void compile(Node node, ArrayList list) {
- //清理参数
- Body code = new Body();
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "body";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node=new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
-
- node.setSource("", 0, 0);
-
- dom.append(node);
-
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BreakLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BreakLexer.java
deleted file mode 100644
index bea9d0e..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/BreakLexer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.BreakDescriptor;
-import java.util.ArrayList;
-
-/**
- * 中断语句
- *
- * @author jun
- */
-public class BreakLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- BreakDescriptor code=new BreakDescriptor();
- code.blocked=true;
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "break";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource("", 0, 0);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ContinueLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ContinueLexer.java
deleted file mode 100644
index 41bb9e1..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ContinueLexer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.BreakDescriptor;
-import java.util.ArrayList;
-
-/**
- * 中断语句
- * @author jun
- */
-public class ContinueLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- list.add(new BreakDescriptor());
- }
-
- @Override
- public String getToken() {
- return "continue";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource("", 0, 0);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/EachLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/EachLexer.java
deleted file mode 100644
index c24d2c1..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/EachLexer.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.Token;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.Callvri;
-import com.diosay.otpl.runtime.opcodes.LoadVariable;
-import com.diosay.otpl.runtime.opcodes.SetVariable;
-import com.diosay.otpl.runtime.opcodes.SourceLineNumber;
-import java.util.ArrayList;
-
-/**
- * 列出集合元素
- *
- * @author jun
- */
-public class EachLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList rlist) {
- //
- /*
- for(Object item:list){
- break
- }
-
- loadItear
- stv n
- ldv n
- callvri hsnext
- brf ELSE
- BEGIN
- ldv n
- callvri current
- stv item
- ...
- ldv n
- callvri hsnext
- brf RET
- br BEGIN
- ELSE
- ...
- RET
-
-
- */
- //
-
- CharSequence source = node.getSource();
-
- if (source == null) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- int index = 0;
- index = StringUtil.trimLeftWhitespace(source, index, source.length());
-
- if (index tokens = this.scan(source, index2, source.length(), node.getLineNumber());
- this.grammar(tokens);
- if (tokens.size() != 1) {
- throw new UnsupportedOperationException("语法错误:each语句参数错误。");
- }
- rlist.add(new SourceLineNumber().setValue(node.getLineNumber()));
-
- for (Token sub : tokens) {
- this.visit(sub, rlist);
- }
- ArrayList list = new ArrayList<>();
- OpCode lbElse = OpCode.label();
- OpCode begin = OpCode.label();
- OpCode ret = OpCode.label();
- begin.tag = "each";
- begin.mark = randomName();
- ret.tag = begin.tag;
- ret.mark = begin.mark;
-
- SetVariable coll = new SetVariable().setName(randomName());
- //SetVariable var = new SetVariable().setName(name);
- list.add(new Callvri().setName("iterator").setArgLength(1));
- list.add(coll);
- list.add(new LoadVariable().setName(coll.getName()));
- list.add(new Callvri().setName("iterator$hasNext").setArgLength(1));
- list.add(OpCode.makeBreakFalse(lbElse));
- list.add(begin);
- list.add(new LoadVariable().setName(coll.getName()));
- list.add(new Callvri().setName("iterator$next").setArgLength(1));
- list.add(new SetVariable().setName(name));
- ((Block) node).children.stream().forEach((sub) -> {
- sub.getCompiler().compile(sub, list);
- });
- list.add(new LoadVariable().setName(coll.getName()));
- list.add(new Callvri().setName("iterator$hasNext").setArgLength(1));
- list.add(OpCode.makeBreakFalse(ret));
- list.add(OpCode.makeBreak(begin));
- list.add(lbElse);
- //else
- Node next = node.getNext();//is null
- if (next != null && "else".equals(next.getName())) {
- next.marked = true;
- ((Block) next).children.stream().forEach((sub) -> {
- sub.getCompiler().compile(sub, list);
- });
- list.add(OpCode.makeBreak(ret));
- }
- list.add(ret);
- this.adjustEach(list, 0, list.size());
- rlist.addAll(list);
- }
-
- @Override
- public String getToken() {
- return "each";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Block node = dom.createBlock(this.getToken());
- node.setCompiler(this);
- node.setSource(source, start, end);
- node.setLineNumber(line);
- node.setCloseName("else");
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElifLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElifLexer.java
deleted file mode 100644
index f85bc12..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElifLexer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.runtime.OpCode;
-import java.util.ArrayList;
-
-/**
- * 例外条件
- *
- * @author jun
- */
-public class ElifLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- //nothing
- }
-
- @Override
- public String getToken() {
- return "elif";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Block node = dom.createBlock(this.getToken());
- node.setCompiler(this);
- node.setSource(source, start, end);
- node.setLineNumber(line);
- node.setCloseName("if", "else","elif");
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElseLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElseLexer.java
deleted file mode 100644
index 11305ac..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ElseLexer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.runtime.OpCode;
-import java.util.ArrayList;
-
-/**
- * 条件例外
- * @author jun
- */
-public class ElseLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- //nothing
- }
-
- @Override
- public String getToken() {
- return "else";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Block node = dom.createBlock(this.getToken());
- node.setCompiler(this);
- node.setSource(source, start, end);
- node.setLineNumber(line);
- node.setCloseName("if","elif","for","each");
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ForLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ForLexer.java
deleted file mode 100644
index f9472a1..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/ForLexer.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.Token;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.*;
-import java.util.ArrayList;
-
-/**
- * for循环
- *
- * @author jun
- */
-public class ForLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList rlist) {
- if(node.marked){
- return;
- }
-
- //
- /*
- for(int i=0;i<10;i++){
- break
- }
-
- ldu 10
- ldu 0
- ldu 1
-
- stv max
- stv i
- stv step
-
- //stackmax 4
- ldv i
- ldv max
- ldu 0
- ldv step
- lt
- brf DOWN
- lt
- brf ELSE
- br BEGIN
- DOWN
- gt
- brf ELSE
- BEGIN
-
- ldv i
- ldv max
- ldu 0
- ldv step
- lt
- brf DOWN
- lt
- brf END
- br RUN
- DOWN
- gt
- brf RETURN
- RUN
- ...
-
- ldv i
- ldv step
- add
- br BEGIN
- ELSE
- ...
- END
-
- */
- //
- CharSequence source = node.getSource();
-
- if (source == null) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- int index = 0;
- index = StringUtil.trimLeftWhitespace(source, index, source.length());
-
- if (source.charAt(index) != ':') {
- throw new UnsupportedOperationException("语法错误:未知字符");
- }
- index++;
- int index2 = StringUtil.findIdentifier(source, index, source.length());
-
- if (index2 < 0) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- String name = source.subSequence(index, index2).toString();
-
- if (this.isKeyword(name)) {
- throw new UnsupportedOperationException("语法错误:变量名不能是关键词:" + name);
- }
- ArrayList tokens = this.scan(source, index2, source.length(), node.getLineNumber());
- this.grammar(tokens);
- if(tokens.size()!=1){
- throw new UnsupportedOperationException("语法错误:for语句参数错误。");
- }
- if(tokens.get(0).size()==0){
- Token token=new Token();
- token.code=",";
- token.type=Token.COMMA;
- tokens.add(token);
-
- token=new Token();
- token.code="0";
- token.type=Token.LONG;
- tokens.add(token);
-
- token=new Token();
- token.code=",";
- token.type=Token.COMMA;
- tokens.add(token);
-
- token=new Token();
- token.code="1";
- token.type=Token.LONG;
- tokens.add(token);
- this.grammar(tokens);
- }else if(tokens.get(0).size()==2){
- Token token=new Token();
- token.code=",";
- token.type=Token.COMMA;
- tokens.add(token);
-
- token=new Token();
- token.code="1";
- token.type=Token.LONG;
- tokens.add(token);
- this.grammar(tokens);
- }else if(tokens.get(0).size()==3){
-
- }else{
- throw new UnsupportedOperationException("语法错误:for语句参数错误。");
- }
- for (Token sub : tokens) {
- this.visit(sub, rlist);
- }
-
- rlist.add(new SourceLineNumber().setValue(node.getLineNumber()));
-
- ArrayList list=new ArrayList<>();
-
- //设置变量
- SetVariable max = new SetVariable().setName(randomName()); //stvar max
- SetVariable var = new SetVariable().setName(name); //stvar i
- SetVariable step = new SetVariable().setName(randomName()); //stvar step
- list.add(step);
- list.add(var);
- list.add(max);
-
-
- //定义标签
- OpCode begin = OpCode.label();
- begin.tag="for";
- begin.mark=randomName();
- OpCode end = OpCode.label();
- end.tag=begin.tag;
- end.mark=begin.mark;
- OpCode lbElse = OpCode.label();
- OpCode lbDown = OpCode.label();
- OpCode lbDown2 = OpCode.label();
- //获取变量
- list.add(new LoadVariable().setName(var.getName()));//ldv i
- list.add(new LoadVariable().setName(max.getName()));//ldv max
- list.add(new LoadVariable().setName(step.getName()));//ldv step
- list.add(new LoadLong().setValue(0));//ldr 0
-
- list.add(new Operator().setOperator(Operator.LE));//lt
- list.add(OpCode.makeBreakTrue(lbDown));//brf DOWN
- list.add(new Operator().setOperator(Operator.LE));//lt
- list.add(OpCode.makeBreakFalse(lbElse));//brf ELSE
- list.add(OpCode.makeBreak(begin));//br BEGIN
- list.add(lbDown);
- list.add(new Operator().setOperator(Operator.GT));//gt
- list.add(OpCode.makeBreakFalse(lbElse));//brf ELSE
- list.add(begin);
- //body
- for(Node sub:((Block)node).children){
- sub.getCompiler().compile(sub, list);
- }
- //加
- list.add(new LoadVariable().setName(var.getName()));//ldv i
- list.add(new LoadVariable().setName(step.getName()));//ldv step
- list.add(new Operator().setOperator(Operator.ADD));//add
- list.add(new SetVariable().setName(var.getName()));//stv i
- //获取变量
- list.add(new LoadVariable().setName(var.getName()));//ldv i
- list.add(new LoadVariable().setName(max.getName()));//ldv max
- list.add(new LoadVariable().setName(step.getName()));//ldv step
- list.add(new LoadLong().setValue(0));//ldr 0
-
- list.add(new Operator().setOperator(Operator.LE));//lt
- list.add(OpCode.makeBreakTrue(lbDown));//brf DOWN
- list.add(new Operator().setOperator(Operator.LE));//lt
- list.add(OpCode.makeBreakFalse(end));//brf END
- list.add(OpCode.makeBreak(begin));//br BEGIN
- list.add(lbDown2);
- list.add(new Operator().setOperator(Operator.GT));//gt
- list.add(OpCode.makeBreakFalse(end));//brf ELSE
- list.add(OpCode.makeBreak(begin));//br BEGIN
- list.add(lbElse);
-
- //else
- Node next=node.getNext();//is null
- if(next!=null && next.getName().equals("else")){
- next.marked=true;
- next.getCompiler().compile(next, list);
- }
-
- list.add(end);
-
- this.adjustFor(list, 0, list.size());
-
- rlist.addAll(list);
-
- }
-
- @Override
- public String getToken() {
- return "for";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Block node = dom.createBlock(this.getToken());
- node.setCloseName("else");
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IfLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IfLexer.java
deleted file mode 100644
index 6a810e9..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IfLexer.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.CompileException;
-import com.diosay.otpl.Compiler;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.runtime.OpCode;
-import java.util.ArrayList;
-
-/**
- * 解析与编译if语句
- *
- * @author jun
- */
-public class IfLexer extends Compiler implements Lexer {
-
- @Override
- public String getToken() {
- return "if";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- if (start >= end) {
- return;
- }
- Block node = dom.createBlock(this.getToken());
- node.setCompiler(this);
- node.setSource(source, start, end);
- node.setLineNumber(line);
- node.setCloseName("elif", "else");
- dom.append(node);
- }
-
- @Override
- public void compile(Node node, ArrayList list) {
-
- //
- /*
- if(3<2){
-
- }
-
- ldu 3
- ldu 2
- lt
- brf RET
- ...
- RET
-
- */
- //
- if (node == null || !node.isBlock() || !this.getToken().equalsIgnoreCase(node.getName())) {
- throw new IllegalArgumentException("node");
- }
-
- OpCode lbElse = OpCode.label();
- OpCode ret = OpCode.label();
- this.compile(node.getSource(), list, node.getLineNumber());
- list.add(OpCode.makeBreakFalse(lbElse));
-
- ((Block) node).children.stream().forEach((sub) -> {
- sub.getCompiler().compile(sub, list);
- });
- list.add(OpCode.makeBreak(ret));
- list.add(lbElse);
- do {
- Node next = node.getNext();
- if (next == null) {
- break;
- } else if ("elif".equals(next.getName())) {
-
- if (!("if".equals(next.getPrev().getName()) || "elif".equals(next.getPrev().getName()))) {
- throw new CompileException("语法错误");
- }
- OpCode lbElse2 = OpCode.label();
- this.compile(next.getSource(), list, next.getLineNumber());
- list.add(OpCode.makeBreakFalse(lbElse2));
- ((Block) next).children.stream().forEach((sub) -> {
- sub.getCompiler().compile(sub, list);
- });
- list.add(OpCode.makeBreak(ret));
- list.add(lbElse2);
- } else if ("else".equals(next.getName())) {
- if (!("if".equals(next.getPrev().getName()) || "elif".equals(next.getPrev().getName()))) {
- throw new CompileException("语法错误");
- }
- ((Block) next).children.stream().forEach((sub) -> {
- sub.getCompiler().compile(sub, list);
- });
- list.add(OpCode.makeBreak(ret));
- } else {
- break;
- }
- next.marked = true;
- node = next;
- } while (true);
- list.add(ret);
- }
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IncludeLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IncludeLexer.java
deleted file mode 100644
index 147e614..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/IncludeLexer.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Project. All rights reserved.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.Include;
-import com.diosay.otpl.runtime.opcodes.Layout;
-import java.util.ArrayList;
-
-/**
- * 包含
- *
- * @author junhwong
- */
-public class IncludeLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- int size = list.size();
- this.compile(node.getSource(), list, node.getLineNumber());
- if (list.size() == size) {
- throw new mano.InvalidOperationException("未设置布局文件名称.");
- }
- Include code = new Include();
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "include";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/LayoutLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/LayoutLexer.java
deleted file mode 100644
index 01f48b2..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/LayoutLexer.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.OpcodeType;
-import com.diosay.otpl.runtime.opcodes.Layout;
-import com.diosay.otpl.runtime.opcodes.Print;
-import java.util.ArrayList;
-
-/**
- * 布局
- * @author jun
- */
-public class LayoutLexer extends com.diosay.otpl.Compiler implements Lexer{
-
- @Override
- public void compile(Node node, ArrayList list) {
- int size=list.size();
- this.compile(node.getSource(), list,node.getLineNumber());
- if(list.size()==size){
- throw new mano.InvalidOperationException("未设置布局文件名称.");
- }
- Layout code = new Layout();
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "layout";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node=new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
-
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PlaceLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PlaceLexer.java
deleted file mode 100644
index afc97bc..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PlaceLexer.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.CallBlock;
-import java.util.ArrayList;
-
-/**
- *
- * @author jun
- */
-public class PlaceLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- CharSequence source = node.getSource();
-
- if (source == null) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- int index = 0;
- index = StringUtil.trimLeftWhitespace(source, index, source.length());
-
- if (source.charAt(index) != ':') {
- throw new UnsupportedOperationException("语法错误:未知字符");
- }
- index++;
- int index2 = StringUtil.findIdentifier(source, index, source.length());
-
- if (index2 < 0) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- String name = source.subSequence(index, index2).toString();
- CallBlock cb=new CallBlock();
- cb.setName(name);
- index = StringUtil.trimLeftWhitespace(source, index2, source.length());
- if (index < source.length()) {
-
- index2 = StringUtil.findIdentifier(source, index, source.length());
- if (index2 < 0) {
- throw new UnsupportedOperationException("语法错误:未知字符2");
- }
- String id = source.subSequence(index, index2).toString();
- if("true".equalsIgnoreCase(id) || "t".equalsIgnoreCase(id)){
- cb.required(true);
- }else if("false".equalsIgnoreCase(id) || "f".equalsIgnoreCase(id)){
- cb.required(true);
- }
- else{
- throw new UnsupportedOperationException("语法错误:不能识别的标识符:"+id);
- }
- }
- index = StringUtil.trimLeftWhitespace(source, index2, source.length());
- if (index != source.length()) {
- throw new UnsupportedOperationException("语法错误:未知字符2");
- }
- list.add(cb);
- }
-
- @Override
- public String getToken() {
- return "place";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PrintLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PrintLexer.java
deleted file mode 100644
index b659223..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/PrintLexer.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.LoadVariable;
-import com.diosay.otpl.runtime.opcodes.Print;
-import java.util.ArrayList;
-
-/**
- * 打印
- *
- * @author jun
- */
-public class PrintLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- CharSequence source = node.getSource();
- if (source == null || source.length() == 0) {
- return;
- }
- boolean filtrable = false;
- if ('@' == source.charAt(0)) {
- filtrable = true;
- }
-
- //TODO:格式化
- this.compile(filtrable ? source.subSequence(1, source.length() - 1) : source, list,node.getLineNumber());
-
-// LoadVariable var = new LoadVariable();
-// var.setName(source.subSequence(filtrable ? 1 : 0, source.length()).toString());
-// list.add(var);
-
- Print code = new Print();
- code.setFiltrable(filtrable);
-
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "print";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
-
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/SectionLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/SectionLexer.java
deleted file mode 100644
index 91fa3f9..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/SectionLexer.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Block;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.runtime.OpCode;
-import java.util.ArrayList;
-
-/**
- * 块定义词条
- *
- * @author jun
- */
-public class SectionLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- CharSequence source = node.getSource();
-
- if (source == null) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- int index = 0;
- index = StringUtil.trimLeftWhitespace(source, index, source.length());
-
- if (source.charAt(index) != ':') {
- throw new UnsupportedOperationException("语法错误:未知字符");
- }
- index++;
- int index2 = StringUtil.findIdentifier(source, index, source.length());
-
- if (index2 < 0) {
- throw new UnsupportedOperationException("语法错误:未设置名称");
- }
- String name = source.subSequence(index, index2).toString();
-
- index = StringUtil.trimLeftWhitespace(source, index2, source.length());
- if (index != source.length()) {
- throw new UnsupportedOperationException("语法错误:未知字符2");
- }
-
- OpCode begin = OpCode.label();
- OpCode end = OpCode.label();
- list.add(begin);
- Block bnode = (Block) node;
- for (Node sub : bnode.children) {
- sub.getCompiler().compile(sub, list);
- }
- com.diosay.otpl.runtime.opcodes.Block code = new com.diosay.otpl.runtime.opcodes.Block();
-
- code.setBegin(begin);
- code.setName(name);
-
- list.add(end);
- //list.add(OpCode.label(node.getLineNumber()));
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "section";
- }
-
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
-
- Block node = dom.createBlock(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/TextLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/TextLexer.java
deleted file mode 100644
index 9577dd0..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/TextLexer.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.Print;
-import com.diosay.otpl.runtime.opcodes.PrintString;
-import java.util.ArrayList;
-
-/**
- * 实现文本的编译。
- * @author jun
- */
-public class TextLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
- PrintString code=new PrintString();
- code.setString(node.getSource().toString());
- list.add(code);
- }
-
- @Override
- public String getToken() {
- return "text";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/VariableLexer.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/VariableLexer.java
deleted file mode 100644
index 030bd6d..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/lexers/VariableLexer.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.lexers;
-
-import com.diosay.otpl.CompileException;
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Lexer;
-import com.diosay.otpl.Node;
-import com.diosay.otpl.Span;
-import com.diosay.otpl.StringUtil;
-import com.diosay.otpl.Token;
-import com.diosay.otpl.runtime.OpCode;
-import com.diosay.otpl.runtime.opcodes.SetVariable;
-import java.util.ArrayList;
-
-/**
- * 设置变量的值
- *
- * @author jun
- */
-public class VariableLexer extends com.diosay.otpl.Compiler implements Lexer {
-
- @Override
- public void compile(Node node, ArrayList list) {
-
- CharSequence source = node.getSource();
-
- if (source == null) {
- throw new CompileException("语法错误:未设置变量名称");
- }
- int index = 0;
- index = StringUtil.trimLeftWhitespace(source, index, source.length());
-
- if (source.charAt(index) != ':') {
- throw new CompileException("语法错误:未知字符");
- }
- index++;
- int index2 = StringUtil.findIdentifier(source, index, source.length());
-
- if (index2 < 0) {
- throw new CompileException("语法错误:未设置变量名称。");
- }
- String name = source.subSequence(index, index2).toString();
-
- if (this.isKeyword(name)) {
- throw new UnsupportedOperationException("语法错误:变量名不能是关键词:" + name);
- }
- ArrayList tokens = this.scan(source, index2, source.length(), node.getLineNumber());
- this.grammar(tokens);
- if (tokens.size() != 1) {
- throw new UnsupportedOperationException("语法错误:变量值太多。");
- }
- for (Token sub : tokens) {
- this.visit(sub, list);
- }
- list.add(new SetVariable().setName(name));
-
- }
-
- @Override
- public String getToken() {
- return "var";
- }
-
- @Override
- public boolean isBlock() {
- return false;
- }
-
- @Override
- public void parse(Document dom, CharSequence source, int start, int end, int line) {
- Span node = new Span(this.getToken());
- node.setCompiler(this);
- node.setLineNumber(line);
- node.setSource(source, start, end);
- dom.append(node);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/BuiltinFunctionInterface.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/BuiltinFunctionInterface.java
deleted file mode 100644
index 252f8ae..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/BuiltinFunctionInterface.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.runtime;
-
-/**
- * 内建函数(BFI)。
- * @author jun
- */
-public interface BuiltinFunctionInterface {
-
- /**
- * 将对象转换为字符串串并合并。
- * @param args
- * @return
- */
- String str(Object[] args);
- Object iterator(Object obj);
- Object indexer(Object obj,Object[] args);
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/CodeLoader.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/CodeLoader.java
deleted file mode 100644
index 3935da1..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/CodeLoader.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.runtime;
-
-import com.diosay.otpl.runtime.opcodes.*;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import mano.util.Utility;
-
-/**
- * 操作码载入器
- *
- * @author jun
- */
-public class CodeLoader {
-
- private InputStream input;
- private String version;
- private Charset encoding;// = Charset.forName("utf-8");
- byte[] buf = new byte[8];
- private HashMap codes = new HashMap<>();
- private File source;
- public CodeLoader parent;
- public CodeLoader child;
- public int pageAddr;
-
- void close() {
- if (input != null) {
- try {
- input.close();
- } catch (IOException ex) {
- }
- }
- }
-
- public File getSource() {
- return source;
- }
-
- public boolean load(ExecutionContext context, InputStream in, boolean b, File source) throws IOException {
- encoding = context.inputEncoding();
- this.source = source;
- input = in;
-
- if (input.read(buf, 0, 8) != 8) { //head line
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件。");
- }
- version = new String(buf, 0, 7, encoding);//OTPL-01
-
- byte mode = buf[7];
- //create time //8
- if (input.read(buf, 0, 8) != 8) { //创建时间
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件。");
- }
- if (mode == 1) {//检查文件 改变
- if (input.read(buf, 0, 8) != 8) { //修改时间
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件。");
- }
- long modified = Utility.toLong(buf, 0);//8
- File file = new File(new String(loadString(), encoding));
- if (!file.exists() || !file.isFile() || modified != file.lastModified()) {
- close();
- return false;
- }
- }
- readToEhead();
-
- return startAddr != 0;
- }
-
- int startAddr = 0;
- int endAddr = -1;
-
- private void readToEhead() throws IOException {
- while (true) {
-
- OpCode code = loadCode();
-
- if (code == null) {
-
- } else if (code.getType() == OpcodeType.stblk) {
- codes.put(code.getAddress(), code);
- Block blk = (Block) code;
- this.blocks.put(blk.getName(), blk);
- } else if (code.getType() == OpcodeType.ehead) {
- codes.put(code.getAddress(), code);
- startAddr = code.getAddress();
- return;
- } else {
- codes.put(code.getAddress(), code);
- }
- }
- }
-
- private OpCode loadCode() throws IOException {
-
- int read = input.read(buf, 0, 5);
- if (read != 5) { //head line
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件:读取行头失败。");
- }
- int addr = Utility.toInt(buf, 0);
- OpcodeType type = OpcodeType.parse(buf, 4);
-
- if (type.equals(OpcodeType.abort)) {
- EndOfFile code = new EndOfFile();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.call)) {
- Call code = new Call();
- code.setAddress(addr);
- code.setArgLength(loadInt());
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.callvri)) {
- Callvri code = new Callvri();
- code.setAddress(addr);
- code.setArgLength(loadInt());
- code.setName(new String(loadString(), this.encoding));
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.doc)) {
- Layout code = new Layout();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- }else if (type.equals(OpcodeType.inc)) {
- Include code = new Include();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.body)) {
- Body code = new Body();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ehead)) {
- EndHeader code = new EndHeader();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.br)) {
- Break code = new Break();
- code.setAddress(addr);
- code.setBehavior(loadBytes(1)[0]);
- if (code.getBehavior() != Break.BREAK_EXIT) {
- code.setTarget(loadInt());
- }
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldu)) {
- LoadLong code = new LoadLong();
- code.setAddress(addr);
- code.setValue(loadLong());
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldm)) {
- LoadMember code = new LoadMember();
- code.setAddress(addr);
- code.setArgLength(loadInt());
- code.setName(new String(loadString(), this.encoding));
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldr)) {
- LoadReal code = new LoadReal();
- code.setAddress(addr);
- code.setValue(Double.parseDouble(new String(this.loadString(), this.encoding)));
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldstr)) {
- LoadString code = new LoadString();
- code.setAddress(addr);
- code.setContent(new String(this.loadString(), this.encoding));
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldv)) {
- LoadVariable code = new LoadVariable();
- code.setAddress(addr);
- code.setName(new String(this.loadString(), this.encoding));
- code.setLoader(this);
- return code;
- }
- else if (type.equals(OpcodeType.nop)) {
- Nop code = new Nop();
- code.setAddress(addr);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.pop)) {
- Pop code = new Pop();
- code.setAddress(addr);
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.prt)) {
- Print code = new Print();
- code.setAddress(addr);
-
- if (input.read(buf, 0, 1) != 1) {
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件,读取参数失败。");
- }
- code.setFiltrable(buf[0] == 1);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.stblk)) {
- Block code = new Block();
- code.setAddress(addr);
- code.setBeginAddress(this.loadInt());
- code.setName(new String(loadString(), this.encoding));
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.call_blk)) {
- CallBlock code = new CallBlock();
- code.setAddress(addr);
- code.setName(new String(loadString(), this.encoding));
- if (input.read(buf, 0, 1) != 1) { //长度
- close();
- throw new mano.InvalidOperationException("获取布尔值失败。");
- }
- code.required(buf[0] == 1);
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.stv)) {
- SetVariable code = new SetVariable();
- code.setAddress(addr);
-
- code.setName(new String(loadString(), this.encoding));
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ptstr)) {
- PrintString code = new PrintString();
- code.setAddress(addr);
-
- byte[] bytes = loadString();
- code.setBytes(bytes, 0, bytes.length);
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.op)) {
- Operator code = new Operator();
- code.setAddress(addr);
- code.setOperator(loadBytes(1)[0]);
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.peek)) {
- Peek code = new Peek();
- code.setAddress(addr);
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.ldc)) {
- LoadConst code = new LoadConst();
- code.setAddress(addr);
- code.setValue(loadBytes(1)[0]);
-
- code.setLoader(this);
- return code;
- } else if (type.equals(OpcodeType.sl)) {
- SourceLineNumber code = new SourceLineNumber();
- code.setAddress(addr);
- code.setValue(loadInt());
- code.setLoader(this);
- return code;
- } else {
- throw new java.lang.RuntimeException("OTPL操作码类型未定义:" + type);
- }
- }
-
- private byte[] loadString() throws IOException {
- if (input.read(buf, 0, 4) != 4) { //长度
- close();
- throw new mano.InvalidOperationException("获取字符串长度。");
- }
- int len = Utility.toInt(buf, 0);
- byte[] bytes = new byte[len];
- if (input.read(bytes) != len) {
- close();
- throw new mano.InvalidOperationException("无效的OTPL文件,读取字符串失败。");
- }
- return bytes;
- }
-
- private int loadInt() throws IOException {
- if (input.read(buf, 0, 4) != 4) { //长度
- close();
- throw new mano.InvalidOperationException("获取int失败。");
- }
- return Utility.toInt(buf, 0);
- }
-
- private byte[] loadBytes(int len) throws IOException {
- if (input.read(buf, 0, len) != len) { //长度
- close();
- throw new mano.InvalidOperationException("获取字节失败。");
- }
- return buf;
- }
-
- private long loadLong() throws IOException {
- if (input.read(buf, 0, 8) != 8) { //长度
- close();
- throw new mano.InvalidOperationException("获取int失败。");
- }
- return Utility.toLong(buf, 0);
- }
-
- /**
- * 读取一个操作码
- *
- * @param addr
- * @return
- */
- public OpCode loadCode(int addr) throws IOException {
- if (this.endAddr != -1 && addr > this.endAddr) {
- return null;
- }
- if (this.codes.containsKey(addr)) {
- return this.codes.get(addr);
- }
- while (true) {
- OpCode code = loadCode();
- if (code == null) {
- return null;
- }
- this.codes.put(code.getAddress(), code);
- if (code.getType().equals(OpcodeType.abort)) {
- this.endAddr = code.getAddress();
- this.close();
- }
- if (code.getAddress() == addr) {
- return code;
- }
- }
- }
- private HashMap blocks = new HashMap<>();
-
- /**
- * 获取一个块
- *
- * @param name
- * @return
- */
- public Block getBlock(String name) {
-
- Block result = null;
- if (this.child != null && this.child.blocks.containsKey(name)) {
- result = this.child.blocks.get(name);
- }
-
- if (result == null && this.blocks.containsKey(name)) {
- result = this.blocks.get(name);
- }
-
- return result != null ? result : (this.child != null ? this.child.getBlock(name) : null);
- }
-
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/ExecutionContext.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/ExecutionContext.java
deleted file mode 100644
index a0db342..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/ExecutionContext.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.runtime;
-
-import java.io.File;
-import java.nio.charset.Charset;
-
-/**
- * 表示一个执行上下文。
- * @author jun
- */
-public interface ExecutionContext {
-
- /**
- * 获取源文件的根目录。
- */
- String getBasedir();
-
- /**
- * 获取目标生成文件的临时目录。
- */
- String getTempdir();
-
- /**
- * 获取输出编译。
- * @return
- */
- Charset outputEncoding();
-
- /**
- * 获取输出编译。
- * @return
- */
- Charset inputEncoding();
-
- /**
- * 设置一个变量
- * @param key
- * @param value
- */
- void set(String key,Object value);
- /**
- * 获取一个变量
- * @param key
- * @return
- */
- Object get(String key);
-
- /**
- * 压入对象到栈顶
- * @param value
- */
- void push(Object value);
- /**
- * 从栈顶弹出一个对象,如果栈为空则返回 null
- * @return
- */
- Object pop();
-
- /**
- * 从栈顶取出一个对象,如果栈为空则返回 null
- * @return
- */
- Object peek();
-
- void write(boolean filtrable,Object obj);
-
- /**
- * 写入字序列。
- * @param filtrable
- * @param cs
- * @param start
- * @param end
- */
- void write(boolean filtrable,CharSequence cs, int start, int end);
-
- /**
- * 写入二进制。
- * @param filtrable
- * @param array
- * @param index
- * @param count
- */
- void write(boolean filtrable, byte[] array, int index, int count);
-
- /**
- * 清空变量、堆栈与重置相关运行时参数。
- */
- void reset();
-
- /**
- * 获取(或创建)一个新的解释器。
- * @return
- */
- Interpreter newInterpreter();
-
- /**
- * 释放一个解释器,以便其他使用。
- * @param interpreter
- */
- void freeInterpreter(Interpreter interpreter);
-
- /**
- * 根据源文件获取加载器。
- * @param source
- * @return
- */
- CodeLoader getLoader(File source,Interpreter interpreter) throws Exception;
-
- /**
- * 设置当前源代码行号。
- * @param line
- */
- void setCurrentSourceLine(int line);
-
- /**
- * 获取当前源代码行号。
- * @return
- */
- int getCurrentSourceLine();
-
- /**
- * 获取内置函数接口。
- * @return
- */
- BuiltinFunctionInterface calls();
-
- /**
- * 调用函数。
- * @param funcName
- * @param args
- * @return
- */
- Object call(String funcName,Object[] args);
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Filter.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Filter.java
deleted file mode 100644
index 60a4da5..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Filter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-
-package com.diosay.otpl.runtime;
-
-import java.nio.charset.Charset;
-
-/**
- * 一个写入过滤器,可以在写入时重定向输出或改变编码等。
- * @author jun
- */
-public interface Filter {
- /**
- * 写入二进制。
- * @param writer
- * @param original
- * @param array
- * @param index
- * @param count
- */
- void write(Writer writer,Charset original, byte[] array, int index, int count);
-}
diff --git a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Interpreter.java b/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Interpreter.java
deleted file mode 100644
index 71df32f..0000000
--- a/del/mano-server-projects/open-tpl/src/main/java/com/diosay/otpl/runtime/Interpreter.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * Copyright (C) 2014 The MANO Authors.
- * All rights reserved. Use is subject to license terms.
- *
- * See more http://mano.diosay.com/
- *
- */
-package com.diosay.otpl.runtime;
-
-import com.diosay.otpl.Document;
-import com.diosay.otpl.Parser;
-import com.diosay.otpl.runtime.opcodes.EndOfFile;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Stack;
-import mano.DateTime;
-import mano.util.Utility;
-
-/**
- * 实现的 OTPL 解释器
- *
- * @author jun
- */
-public class Interpreter implements Closeable {
-
- @Override
- public void close() throws IOException {
- //
- }
-
- static class TempExecutionContext implements ExecutionContext {
-
- private HashMap items = new HashMap<>();
- private Stack