@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
160 lines (122 loc) • 3.63 kB
text/typescript
import { LogicItem, Enum } from '@lcap/nasl';
import * as nasl from '@lcap/nasl';
export class CstIdentifier {
name: string;
namespace: Array<string>;
}
export type SupportedAnnotationValue =
nasl.NullLiteral | nasl.BooleanLiteral | nasl.NumericLiteral | nasl.StringLiteral;
export type SupportedDefinition =
nasl.Logic | nasl.Structure | nasl.Entity | nasl.Enum | nasl.FrontendType
| nasl.DataSource | CstIntEnumRef | CstNamespace | UsingNamespace;
export class CstAnnotationArg {
name: string
value: SupportedAnnotationValue
constructor(name: string, value: SupportedAnnotationValue) {
this.name = name;
this.value = value;
}
}
export class CstAnnotation {
type: 'Builtin' | 'Custom';
name: string;
value: Array<CstAnnotationArg>;
constructor(type: 'Builtin' | 'Custom', name: string, value: Array<CstAnnotationArg>) {
this.type = type;
this.name = name;
this.value = value;
}
}
// 专为 app::enums::MyEnum::1 设计
export class CstIntEnumRef {
enumTypeName: string;
value: string;
constructor(enumTypeName: string, value: string) {
this.enumTypeName = enumTypeName;
this.value = value;
}
}
export class UsingNamespace {
namespace: Array<string>;
constructor(nsp: Array<string>) {
this.namespace = nsp;
}
}
declare module '@lcap/nasl' {
interface Entity {
annotations?: Array<CstAnnotation>
}
interface Structure {
annotations?: Array<CstAnnotation>
}
interface StructureProperty {
annotations?: Array<CstAnnotation>
}
interface Logic {
annotations?: Array<CstAnnotation>
}
interface LogicItem {
annotations?: Array<CstAnnotation>
}
interface Enum {
annotations?: Array<CstAnnotation>
}
interface EnumItem {
annotations?: Array<CstAnnotation>
}
interface Function {
annotations?: Array<CstAnnotation>
}
// interface TypeParam {
// scopedName: cstIdentifier
// annotations?: Array<Annotation>
// }
interface Identifier {
qName: CstIdentifier
}
interface CallLogic {
qName: CstIdentifier
callKind: 'Function' | 'Logic' | 'Constructor' | 'AuthInterface'
// simpleLambda?: SimpleLambda
}
interface TypeAnnotation {
qName: CstIdentifier
}
class EmptyBrackets { }
}
export class EmptyBraces extends LogicItem { } // { }
export class EmptyBrackets extends LogicItem { } // [ ]
export class SeqNasl {
// namespace 依赖线性有序结构
nodes: Array<SupportedDefinition> = new Array();
}
export class CstNamespace {
name: string;
defs: Array<SupportedDefinition> = new Array();
constructor(name: string, defs: Array<SupportedDefinition>) {
this.name = name;
this.defs = defs;
}
}
export * from '@lcap/nasl';
export {
Structure, StructureProperty, Variable, Logic, Function, TypeParam, Identifier,
CallLogic, TypeAnnotation
} from '@lcap/nasl';
// FROM(app.dataSources.defaultDS.entities.OrderProduct as OrderProduct)
// .INNER_JOIN(app.dataSources.defaultDS.entities.OrderForm as OrderForm)
// .ON(OrderProduct.orderId == OrderForm.id)
// .INNER_JOIN(app.dataSources.defaultDS.entities.Product as Product)
// .ON(OrderProduct.productId == Product.id)
// .WHERE(OrderProduct.createdBy == '张三' && OrderProduct.createdTime > startDateTime)
// .GROUP_BY(OrderProduct.productId, Product.name)
// .ORDER_BY([productName, 'ASC'])
// .SELECT({
// OrderProduct: OrderProduct,
// OrderForm: OrderForm,
// Product: Product,
// totalAmount: SUM(OrderProduct.amount),
// productId: OrderProduct.productId,
// productName: Product.name}
// )
// .PAGINATE([1, 1000])