108 Star 857 Fork 300

GVPcanonical-entropy/nop-entropy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
XLangAST.xjava 21.37 KB
一键复制 编辑 原始数据 按行查看 历史
canonical-entropy 提交于 2024-08-16 23:33 . 增加JavaToXLangTransformer
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
package io.nop.xlang.ast;
import io.nop.api.core.annotations.meta.PropMeta;
import io.nop.api.core.beans.TreeBean;
import java.util.List;
import java.util.Set;
public class XLangAST {
enum PropertyKind {
init,
get,
set
}
enum VariableKind {
CONST,
LET,
}
enum XLangClassKind {
}
enum XLangOperator {
}
enum XLangOutputMode {
}
abstract class XLangASTNode {
}
abstract class Expression {
}
abstract class Statement extends Expression {
}
interface IdentifierOrPattern {
}
abstract class ModuleDeclaration extends Statement {
}
abstract class Declaration extends Statement {
}
class CompilationUnit{
@PropMeta(mandatory=true)
String packageName;
List<Statement> statements;
}
class Program extends Expression {
String sourceType; //: "script" | "module";
@PropMeta(mandatory = true)
List<XLangASTNode> body; //: [ Statement | ModuleDeclaration ];
}
class Identifier extends Expression implements IdentifierOrPattern {
@PropMeta(mandatory = true)
String name;
}
class Literal extends Expression {
Object value;
}
class TemplateStringLiteral extends Literal {
}
class RegExpLiteral extends Literal {
String pattern;
String flags;
}
class BlockStatement extends Statement {
@PropMeta(mandatory = true)
List<Expression> body;
}
class EmptyStatement extends Statement {
}
class ReturnStatement extends Statement {
Expression argument;
}
class BreakStatement extends Statement {
}
class ContinueStatement extends Statement {
}
class IfStatement extends Statement {
Expression test;
Expression consequent;
Expression alternate;
boolean ternaryExpr;
}
// class TernaryExpression extends Expression {
// Expression test;
// Expression consequent;
// Expression alternate;
// }
class SwitchStatement extends Statement {
@PropMeta(mandatory = true)
Expression discriminant;
boolean asExpr;
List<SwitchCase> cases;
Expression defaultCase;
}
class SwitchCase {
@PropMeta(mandatory = true)
Expression test;
Expression consequent;
boolean fallthrough;
}
class ThrowStatement extends Statement {
@PropMeta(mandatory = true)
Expression argument;
}
class TryStatement extends Statement {
@PropMeta(mandatory = true)
Expression block;
CatchClause catchHandler;
Expression finalizer;
}
class CatchClause {
@PropMeta(mandatory = true)
Identifier name;
NamedTypeNode varType;
@PropMeta(mandatory = true)
Expression body;
}
class WhileStatement extends Statement {
@PropMeta(mandatory = true)
Expression test;
@PropMeta(mandatory = true)
Expression body;
}
class DoWhileStatement extends Statement {
@PropMeta(mandatory = true)
Expression body;
@PropMeta(mandatory = true)
Expression test;
}
class VariableDeclarator {
XLangASTNode id; // IdentifierOrPattern
NamedTypeNode varType;
Expression init;
}
class VariableDeclaration extends Declaration {
@PropMeta(mandatory = true)
VariableKind kind; // kind: "var";
@PropMeta(mandatory = true, minItems = 1)
List<VariableDeclarator> declarators;
}
class ForStatement extends Statement {
Expression init; // init:VariableDeclaration |Expression |null;
Expression test;
Expression update;
@PropMeta(mandatory = true)
Expression body;
}
class ForOfStatement extends Statement {
Identifier index;
@PropMeta(mandatory = true)
Expression left; //: VariableDeclaration | Pattern;
@PropMeta(mandatory = true)
Expression right;
@PropMeta(mandatory = true)
Expression body;
}
class ForRangeStatement extends Statement {
Identifier var;
Identifier index;
@PropMeta(mandatory = true)
Expression begin;
@PropMeta(mandatory = true)
Expression end;
@PropMeta(mandatory = true)
Expression step;
@PropMeta(mandatory = true)
Expression body;
}
class ForInStatement extends Statement {
Identifier index;
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
@PropMeta(mandatory = true)
Expression body;
}
// class WithStatement extends Statement {
// Expression object;
// Expression body;
// }
class DeleteStatement extends Statement {
@PropMeta(mandatory = true)
Expression argument;
}
abstract class OptionalExpression extends Expression {
boolean optional;
}
class ChainExpression extends OptionalExpression {
@PropMeta(mandatory = true)
Expression expr;
String target;
boolean notEmpty;
}
class ThisExpression extends Expression {
}
class SuperExpression extends Expression {
}
class TemplateStringExpression extends Expression {
@PropMeta(mandatory = true)
Identifier id;
@PropMeta(mandatory = true)
TemplateStringLiteral value;
}
class ArrayExpression extends Expression {
// spread element is not expression
List<XLangASTNode> elements;
}
class ObjectExpression extends Expression {
List<XLangASTNode> properties;
}
class PropertyAssignment extends Expression {
@PropMeta(mandatory = true)
Expression key; //: Literal | Identifier | Expression;
@PropMeta(mandatory = true)
Expression value; //: Expression;
PropertyKind kind; //"init" | "get" | "set";
boolean method;
boolean shorthand;
boolean computed;
}
class ParameterDeclaration {
Decorators decorators;
@PropMeta(mandatory = true)
XLangASTNode name; // IdentifierOrPattern
NamedTypeNode type;
Expression initializer;
boolean implicit;
}
class FunctionDeclaration extends DecoratedDeclaration {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
List<ParameterDeclaration> params; //:[Pattern ];
NamedTypeNode returnType;
boolean resultOptional;
@PropMeta(mandatory = true)
Expression body;
int modifiers;
}
class ArrowFunctionExpression extends Expression {
@PropMeta(mandatory = true)
List<ParameterDeclaration> params; //:[Pattern ];
NamedTypeNode returnType;
@PropMeta(mandatory = true)
Expression body; // : FunctionBody | Expression;
}
/*
enum UnaryOperator {
"-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
}*/
class UnaryExpression extends Expression {
//type: "UnaryExpression";
@PropMeta(mandatory = true)
XLangOperator operator; //: UnaryOperator;
//prefix: boolean;
@PropMeta(mandatory = true)
Expression argument; //: Expression;
}
class UpdateExpression extends Expression {
//type: "UpdateExpression";
@PropMeta(mandatory = true)
XLangOperator operator;
@PropMeta(mandatory = true)
Expression argument;
boolean prefix;
}
/*
enum BinaryOperator {
"==" | "!=" | "===" | "!=="
| "<" | "<=" | ">" | ">="
| "<<" | ">>" | ">>>"
| "+" | "-" | "*" | "/" | "%"
| "|" | "^" | "&" | "in"
| "instanceof"
}
enum LogicalOperator {
"||" | "&&" | "??"
}
Nullish Coalescing
*/
class BinaryExpression extends Expression {
//type: "BinaryExpression";
@PropMeta(mandatory = true)
XLangOperator operator; //: BinaryOperator;
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
}
class InExpression extends Expression {
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
}
class ExpressionStatement extends Statement {
@PropMeta(mandatory = true)
Expression expression;
}
/**
* enum AssignmentOperator {
* "=" | "+=" | "-=" | "*=" | "/=" | "%="
* | "<<=" | ">>=" | ">>>="
* | "|=" | "^=" | "&="
* }
*/
class AssignmentExpression extends Statement {
//type: "AssignmentExpression";
@PropMeta(mandatory = true)
XLangOperator operator; //: AssignmentOperator;
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
}
class LogicalExpression extends Expression {
//type: "LogicalExpression";
@PropMeta(mandatory = true)
XLangOperator operator;
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
}
class MemberExpression extends OptionalExpression {
//type: "MemberExpression";
@PropMeta(mandatory = true)
Expression object;
@PropMeta(mandatory = true)
Expression property;
boolean computed; // computed true 对应于a[b], 而为false时,对应a.b, bIdentifier
}
class EvalExpression extends Expression {
String lang;
Literal source;
}
class CallExpression extends OptionalExpression {
String xplLibPath;
//type: "CallExpression";
@PropMeta(mandatory = true)
Expression callee;
@PropMeta(mandatory = true)
List<Expression> arguments;
}
class NewExpression extends Expression {
//type: "NewExpression";
@PropMeta(mandatory = true)
NamedTypeNode callee;
List<Expression> arguments;
}
class SpreadElement {
@PropMeta(mandatory = true)
Expression argument;
}
//
// // a ternary ?/: expression.
// class ConditionalExpression extends Expression {
// Expression test;
// Expression alternate;
// Expression consequent;
// }
// for(x=1,y=2;;)这种通过逗号分隔的表达式
class SequenceExpression extends Expression {
//type: "SequenceExpression";
@PropMeta(mandatory = true)
List<Expression> expressions;
}
class ConcatExpression extends Expression {
//type: "SequenceExpression";
@PropMeta(mandatory = true)
List<Expression> expressions;
}
class TemplateExpression extends Expression{
String prefix;
String postfix;
@PropMeta(mandatory = true)
List<Expression> expressions;
}
class BraceExpression extends Expression {
@PropMeta(mandatory = true)
Expression expr;
}
class ObjectBinding implements IdentifierOrPattern {
List<PropertyBinding> properties;
RestBinding restBinding;
}
class PropertyBinding {
String propName;
@PropMeta(mandatory = true)
Identifier identifier;
Expression initializer;
}
class RestBinding {
@PropMeta(mandatory = true)
Identifier identifier;
Expression initializer;
}
class ArrayBinding implements IdentifierOrPattern {
List<ArrayElementBinding> elements;
RestBinding restBinding;
}
class ArrayElementBinding {
@PropMeta(mandatory = true)
Identifier identifier;
Expression initializer;
}
abstract class ModuleSpecifier {
}
// export const foo = 1;
class ExportDeclaration extends Declaration {
@PropMeta(mandatory = true)
Declaration declaration;
}
// export {foo} from "mod";
class ExportNamedDeclaration extends ModuleDeclaration {
@PropMeta(mandatory = true)
List<ExportSpecifier> specifiers;
@PropMeta(mandatory = true)
Literal source;
}
// export * from "mod"
class ExportAllDeclaration extends ModuleDeclaration {
@PropMeta(mandatory = true)
Literal source;
}
// export {bar as foo}
class ExportSpecifier extends ModuleSpecifier {
Identifier local;
@PropMeta(mandatory = true)
Identifier exported;
}
class ImportDeclaration extends ModuleDeclaration {
//type: "ImportDeclaration";
@PropMeta(mandatory = true, minItems = 1)
List<ModuleSpecifier> specifiers; // [ ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier ];
@PropMeta(mandatory = true)
Literal source;
}
// import java.util.List as JavaList;
// import "/nop/core/c.xlib";
class ImportAsDeclaration extends ModuleDeclaration {
@PropMeta(mandatory = true)
XLangASTNode source;
Identifier local;
boolean staticImport;
}
//import {foo as bar} from "mod"
class ImportSpecifier extends ModuleSpecifier {
//type: "ImportSpecifier";
Identifier local;
@PropMeta(mandatory = true)
Identifier imported;
}
// import foo from "mod.js"
class ImportDefaultSpecifier extends ModuleSpecifier {
//type: "ImportDefaultSpecifier";
Identifier local;
}
// import * as foo from "mod.js"
class ImportNamespaceSpecifier extends ModuleSpecifier {
//type: "ImportNamespaceSpecifier";
@PropMeta(mandatory = true)
Identifier local;
}
// [...obj]
class AwaitExpression extends Expression {
//type: "AwaitExpression";
@PropMeta(mandatory = true)
Expression argument;
}
class Decorators {
List<Decorator> decorators;
}
class QualifiedName {
@PropMeta(mandatory = true)
String name;
QualifiedName next;
}
class Decorator {
QualifiedName name;
MetaObject value;
}
class MetaObject {
List<MetaProperty> properties;
}
class MetaProperty {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
XLangASTNode value;
}
class MetaArray {
List<XLangASTNode> elements;
}
class UsingStatement extends Statement {
@PropMeta(mandatory = true)
VariableDeclaration vars; //: VariableDeclaration | Pattern;
@PropMeta(mandatory = true)
Expression body;
}
// class XplNodeExpression extends Expression {
// @PropMetaAnnotation(mandatory = true)
// String tagName;
//
// @PropMetaAnnotation(mandatory = true)
// List<XplAttrExpression> attrs;
// }
//
// class XplAttrExpression {
// @PropMetaAnnotation(mandatory = true)
// String name;
//
// @PropMetaAnnotation(mandatory = true)
// Expression value;
// }
class MacroExpression extends Expression {
@PropMeta(mandatory = true)
Expression expr;
}
// 忽略表达式的返回值,通过scope.output输出
abstract class OutputExpression extends Expression {
}
enum XLangEscapeMode {
}
class TextOutputExpression extends OutputExpression {
String text;
}
class EscapeOutputExpression extends OutputExpression {
@PropMeta(mandatory = true)
XLangEscapeMode escapeMode;
@PropMeta(mandatory = true)
Expression text;
}
class CollectOutputExpression extends Expression {
boolean singleNode;
@PropMeta(mandatory = true)
XLangOutputMode outputMode;
@PropMeta(mandatory = true)
Expression body;
}
abstract class FilterOpExpression extends Expression {
String op;
String errorCode;
String label;
}
class CompareOpExpression extends FilterOpExpression {
@PropMeta(mandatory = true)
Expression left;
@PropMeta(mandatory = true)
Expression right;
}
class AssertOpExpression extends FilterOpExpression {
@PropMeta(mandatory = true)
Expression value;
}
class BetweenOpExpression extends FilterOpExpression {
@PropMeta(mandatory = true)
Expression value;
Expression min;
Expression max;
boolean excludeMin;
boolean excludeMax;
}
class GenNodeExpression extends OutputExpression {
Expression tagName;
Expression extAttrs;
List<GenNodeAttrExpression> attrs;
Expression body;
// textNodebody属性有效
boolean textNode;
}
class GenNodeAttrExpression extends OutputExpression {
@PropMeta(mandatory = true)
String name;
@PropMeta(mandatory = true)
Expression value;
}
class OutputXmlAttrExpression extends OutputExpression {
@PropMeta(mandatory = true)
String name;
@PropMeta(mandatory = true)
Expression value;
}
class OutputXmlExtAttrsExpression extends OutputExpression {
@PropMeta(mandatory = true)
Set<String> excludeNames;
@PropMeta(mandatory = true)
Expression extAttrs;
}
class TypeOfExpression extends Expression {
@PropMeta(mandatory = true)
Expression argument;
}
class InstanceOfExpression extends Expression {
@PropMeta(mandatory = true)
Expression value;
NamedTypeNode refType;
}
class CastExpression extends Expression {
@PropMeta(mandatory = true)
Expression value;
@PropMeta(mandatory = true)
NamedTypeNode asType;
}
abstract class TypeNode {
boolean notNull;
}
abstract class NamedTypeNode extends TypeNode {
}
class ArrayTypeNode extends NamedTypeNode {
@PropMeta(mandatory = true)
NamedTypeNode componentType;
}
class ParameterizedTypeNode extends NamedTypeNode {
@PropMeta(mandatory = true)
String typeName;
@PropMeta(mandatory = true)
List<NamedTypeNode> typeArgs;
}
class TypeNameNode extends NamedTypeNode {
@PropMeta(mandatory = true)
String typeName;
}
abstract class StructuredTypeDef extends TypeNode {
}
class UnionTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
List<NamedTypeNode> types;
}
class IntersectionTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
List<NamedTypeNode> types;
}
class ObjectTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
List<PropertyTypeDef> types;
}
// [key:string]: number, propA?: MyType
class PropertyTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
String name;
@PropMeta(mandatory = true)
TypeNode valueType;
boolean anyName; // true for indexSignature, eg. [key:string]:type
boolean readonly;
boolean optional;
}
class TupleTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
List<TypeNode> types;
}
class TypeParameterNode {
@PropMeta(mandatory = true)
Identifier name;
NamedTypeNode upperBound;
NamedTypeNode lowerBound;
}
class TypeAliasDeclaration extends Declaration {
@PropMeta(mandatory = true)
Identifier typeName;
List<TypeParameterNode> typeParams;
@PropMeta(mandatory = true)
TypeNode defType;
}
class FunctionTypeDef extends StructuredTypeDef {
List<TypeParameterNode> typeParams;
@PropMeta(mandatory = true)
List<FunctionArgTypeDef> args;
boolean varArgs;
@PropMeta(mandatory = true)
NamedTypeNode returnType;
}
class FunctionArgTypeDef extends StructuredTypeDef {
@PropMeta(mandatory = true)
Identifier argName;
@PropMeta(mandatory = true)
NamedTypeNode argType;
boolean optional;
}
class EnumDeclaration extends Declaration {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
List<EnumMember> members;
}
class EnumMember {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
Literal value;
}
abstract class DecoratedDeclaration extends Declaration {
Decorators decorators;
}
class ClassDefinition extends DecoratedDeclaration {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
XLangClassKind classKind;
List<TypeParameterNode> typeParams;
ParameterizedTypeNode extendsType;
List<ParameterizedTypeNode> implementTypes;
@PropMeta(mandatory = true)
List<FieldDeclaration> fields;
@PropMeta(mandatory = true)
List<FunctionDeclaration> methods;
@PropMeta(mandatory = true)
List<ClassDefinition> classDefinitions;
}
class FieldDeclaration extends DecoratedDeclaration {
@PropMeta(mandatory = true)
Identifier name;
@PropMeta(mandatory = true)
NamedTypeNode type;
boolean optional;
Expression initializer;
int modifiers;
}
class CustomExpression extends Expression {
String source;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/canonical-entropy/nop-entropy.git
git@gitee.com:canonical-entropy/nop-entropy.git
canonical-entropy
nop-entropy
nop-entropy
master

搜索帮助