@lcap/nasl-parser
Version:
Take Nasl text to Nasl AST with the help of generalized parsing.
172 lines • 3.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDefinition = isDefinition;
exports.isDeclaration = isDeclaration;
const fs_1 = require("fs");
const nasl = [
'App',
'Definition', 'Declaration', 'LogicDeclare', 'LogicSig', 'Logic',
'TyParamList',
'VarInit',
'TyAnn',
'AssignValue',
'Param',
'LogicReturn',
'MatchCasePats',
'CasePat',
'ExprPat',
'TypePat',
'Statements',
'VarsAndStmt',
'VarDecl',
'UsingNamespace'
];
const annot = [
'Annotations',
'Annotation',
'BuiltinAnnotation',
'CustomAnnotation',
'AnnArg',
'AnnArgVal'
];
const data = [
'Struct',
'StructBody',
'StructProperty',
'Entity',
'PrimaryConstructor',
'StructConstructor',
'Enum',
'EnumItem',
'Metadata',
'ValidationRule'
];
const expr = [
'AnnExpression',
'Expression',
'LogicOr',
'LogicAnd',
'Comparison',
'Addition',
'Multiplication',
'UnaryExpr',
'PrefixExpr',
'PostfixExpr',
'HighestPriorityExpression',
'LiteralExpression',
'TermRef',
'MatchExpr',
'MatchCases',
'MatchExprNormalCase',
'MatchExprDefaultCase',
'ParensizedExpr',
'PostfixSuffix',
'ArrayAccessSuffix',
'MemberAccessSuffix',
'SQLUFilterSuffix',
'ArrayLit',
'MapLit',
'MapEntry',
'EmptyBrackets',
'EmptyBraces',
'SimpleLambda',
'LamParamList',
'LamParam',
'SubLogic',
'LamParamAndBody',
'CallSuffix',
'TypeArgList',
'ValueArgList',
'ValueArg',
'UnnamedArg',
'NamedArg',
'StringInterpolation',
'InterpolationPart',
'ItpChar',
'InterpolationExpression',
'StringLit',
'JSString',
'BooleanLit',
'IntegerLit',
'DecimalLit',
'NullLit',
'QIdentifier',
'EnumIntRef',
'SimpleIdentifier'
];
const sql = [
'WeakSQL',
'QueryIter',
'SqlProp',
'SqlSingleProp',
'SqlMultiProp',
'NamedProp',
'Join',
'JoinCond',
'SimpleJoinCond',
'ComplexJoinCond',
'Where',
'GroupBy',
'OrderBy',
'SingleOrderBy',
'DynOrd',
'Select',
'Pagination',
'Into'
];
const stmt = [
'Statement',
'Assignment',
'SingleAssign',
'BatchAssign',
'If',
'ElseIf',
'FinalElse',
'While',
'Switch',
'SwitchCases',
'SwitchNormalCase',
'SwitchDefaultCase',
'ForeachLoop',
'LoopCond',
'LoopIndex',
'LoopRange',
'ExprStmt',
'MatchStmt',
'MatchStmtNormalCase',
'MatchStmtDefaultCase',
'PageRedirection',
'InAppRedirection',
'ExtRedirection',
'Abort',
'End',
'ValidationRuleCall'
];
const type = [
'TypeIntro',
'Type',
'UnionType',
'FunctionType',
'AnonymousType',
'TypedSimpleName',
'NamedType',
'TypeConstructor',
'TypeVariable',
'ReferenceType'
];
function generatePredicate() {
const names = [...nasl, ...annot, ...data, ...expr, ...sql, ...stmt, ...type];
const strs = names.map(name => `export const is${name} = (n : object) => n && n['__type'] === '${name}'\n`);
// const strs = names.map(name => `export function is${name}(x : ${name}): x is ${name} { return (x as ${name})['__type'] === '${name}' }\n`);
// console.log(strs);
const strs2 = names.map(name => `export interface ${name} { __type: '${name}' }\n`);
(0, fs_1.writeFileSync)('./ts/toAST/predicate.ts', strs.concat(strs2).join(''));
}
function isDefinition(node) {
return ['Logic', 'Struct'].includes(node['__type']);
}
function isDeclaration(node) {
return node['__type'] === 'LogicDeclare';
}
generatePredicate();
//# sourceMappingURL=gen-predicate.js.map