English | 简体中文
Darabonba 生成器只能在 Node.js 环境下运行。建议使用 NPM 包管理工具安装。在终端输入以下命令进行安装:
npm install @darabonba/cpp-generator
生成 C++ 代码
'use strict';
const path = require('path');
const fs = require('fs');
const parser = require('@darabonba/parser');
const CppGenerator = require('@darabonba/cpp-generator');
const sourceDir = "<Darabonda package directory>";
const outputDir = "<Generate output directory>";
// generate AST data by Darabonba Parser
let packageMetaFilePath = path.join(sourceDir, 'Darafile');
let packageMeta = JSON.parse(fs.readFileSync(packageMetaFilePath, 'utf8'));
let mainFile = path.join(sourceDir, packageMeta.main);
let ast = parser.parse(fs.readFileSync(mainFile, 'utf8'), mainFile);
// initialize generator
let generatorConfig = {
...packageMeta,
pkgDir: sourceDir,
outputDir
};
let generator = new CppGenerator(generatorConfig);
// generate cpp code by generator
generator.visit(ast);
// The execution result will be output in the 'outputDir'
git clone https://github.com/aliyun/darabonba-cpp-generator.git
cd darabonba-cpp-generator/
node examples/complex.js
提出问题, 不符合指南的问题可能会立即关闭。
发布详情会更新在 release notes 文件中
Apache-2.0 Copyright (c) 2009-present, Alibaba Cloud All rights reserved.