diff --git a/BUILD.gn b/BUILD.gn index f7df579..0535ce6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,8 +17,8 @@ import("//foundation/ace/ace_engine/ace_config.gni") ets_loader_lib_dir = get_label_info(":build_ets_loader_library", "target_out_dir") + "/lib" -ets_loader_peg_dir = get_label_info(":build_ets_loader_library", - "target_out_dir") + "/peg_parser/dist" +ets_loader_syntax_dir = get_label_info(":build_ets_loader_library", + "target_out_dir") + "/syntax_parser/dist" ets_loader_declarations_dir = get_label_info(":build_ets_loader_library", "target_out_dir") + "/declarations" ets_loader_component_config_file = @@ -32,7 +32,7 @@ action("build_ets_loader_library") { depfile = "$target_gen_dir/$target_name.d" outputs = [ ets_loader_lib_dir, - ets_loader_peg_dir, + ets_loader_syntax_dir, ets_loader_declarations_dir, ets_loader_component_config_file, ] @@ -48,14 +48,14 @@ action("build_ets_loader_library") { _babel_js = _ace_config_dir + "/node_modules/@babel/cli/bin/babel.js" _babel_config_js = _ace_config_dir + "/babel.config.js" _uglify_source_js = _ace_config_dir + "/uglify-source.js" - _build_peg_js = _ace_config_dir + "/build_peg.js" + _build_parser_js = _ace_config_dir + "/build_parser.js" _build_declarations_file_js = _ace_config_dir + "/build_declarations_file.js" inputs = [ _babel_config_js, _babel_js, _uglify_source_js, - _build_peg_js, + _build_parser_js, _build_declarations_file_js, ] @@ -87,18 +87,18 @@ action("build_ets_loader_library") { rebase_path(_babel_js, root_build_dir), "--ets-loader-src-dir", rebase_path(_ets_loader_dir + "/src", root_build_dir), - "--ets-loader-peg-src-dir", - rebase_path(_ets_loader_dir + "/peg_parser/src", root_build_dir), + "--ets-loader-syntax-src-dir", + rebase_path(_ets_loader_dir + "/syntax_parser/src", root_build_dir), "--babel-config-js", rebase_path(_babel_config_js, root_build_dir), "--uglify-source-js", rebase_path(_uglify_source_js, root_build_dir), - "--build-peg-js", - rebase_path(_build_peg_js, root_build_dir), + "--build-parser-js", + rebase_path(_build_parser_js, root_build_dir), "--output-dir", rebase_path(ets_loader_lib_dir, root_build_dir), - "--output-peg-dir", - rebase_path(ets_loader_peg_dir, root_build_dir), + "--output-syntax-dir", + rebase_path(ets_loader_syntax_dir, root_build_dir), "--declarations-file-dir", rebase_path(_declarations_file_dir, root_build_dir), "--build-declarations-file-js", @@ -154,9 +154,9 @@ ohos_copy("ets_loader_library") { module_install_name = "" } -ohos_copy("ets_loader_peg") { +ohos_copy("ets_loader_syntax") { deps = [ ":build_ets_loader_library" ] - sources = [ ets_loader_peg_dir ] + sources = [ ets_loader_syntax_dir ] outputs = [ target_out_dir + "/$target_name" ] module_source_dir = target_out_dir + "/$target_name" module_install_name = "" diff --git a/build_ets_loader_library.py b/build_ets_loader_library.py index 49d289a..4511664 100755 --- a/build_ets_loader_library.py +++ b/build_ets_loader_library.py @@ -39,13 +39,14 @@ def parse_args(): parser.add_argument('--node', help='path to nodejs exetuable') parser.add_argument('--babel-js', help='path to babel.js') parser.add_argument('--ets-loader-src-dir', help='path to compiler/src') - parser.add_argument('--ets-loader-peg-src-dir', - help='path to compiler/peg_parser/src') + parser.add_argument('--ets-loader-syntax-src-dir', + help='path to compiler/syntax_parser/src') parser.add_argument('--babel-config-js', help='path babel.config.js') parser.add_argument('--uglify-source-js', help='path uglify-source.js') - parser.add_argument('--build-peg-js', help='path build_peg.js') + parser.add_argument('--build-parser-js', help='path build_parser.js') parser.add_argument('--output-dir', help='path to output') - parser.add_argument('--output-peg-dir', help='path peg file to output') + parser.add_argument('--output-syntax-dir', + help='path syntax file to output') parser.add_argument('--declarations-file-dir', help='path declarations file') parser.add_argument('--build-declarations-file-js', @@ -59,8 +60,9 @@ def parse_args(): return options -def do_build(build_cmd, uglify_cmd, peg_cmd, build_declarations_file_cmd): - for cmd in [build_cmd, uglify_cmd, peg_cmd, build_declarations_file_cmd]: +def do_build(build_cmd, uglify_cmd, syntax_cmd, build_declarations_file_cmd): + for cmd in [build_cmd, uglify_cmd, syntax_cmd, + build_declarations_file_cmd]: build_utils.check_output(cmd) @@ -75,13 +77,14 @@ def main(): depfile_deps = [options.node, options.babel_js, options.babel_config_js] depfile_deps.extend(build_utils.get_all_files(options.ets_loader_src_dir)) depfile_deps.extend( - build_utils.get_all_files(options.ets_loader_peg_src_dir)) + build_utils.get_all_files(options.ets_loader_syntax_src_dir)) uglify_cmd = [options.node, options.uglify_source_js, options.output_dir] depfile_deps.append(options.uglify_source_js) - peg_cmd = [options.node, options.build_peg_js, options.output_peg_dir] - depfile_deps.append(options.build_peg_js) + syntax_cmd = [options.node, options.build_parser_js, + options.output_syntax_dir] + depfile_deps.append(options.build_parser_js) build_declarations_file_cmd = [options.node, options.build_declarations_file_js, @@ -92,13 +95,13 @@ def main(): build_utils.call_and_write_depfile_if_stale( lambda: do_build(build_cmd, uglify_cmd, - peg_cmd, build_declarations_file_cmd), + syntax_cmd, build_declarations_file_cmd), options, depfile_deps=depfile_deps, input_paths=depfile_deps, output_paths=([ options.output_dir, - options.output_peg_dir, + options.output_syntax_dir, options.output_declarations_dir, options.output_component_config_file])) diff --git a/compiler/build_peg.js b/compiler/build_parser.js similarity index 74% rename from compiler/build_peg.js rename to compiler/build_parser.js index b1cb34d..03f79ad 100644 --- a/compiler/build_peg.js +++ b/compiler/build_parser.js @@ -19,12 +19,12 @@ const exec = util.promisify(childProcess.exec); const fs = require('fs'); const path = require('path'); -function generatePeg(inputFile) { - const readDirPath = path.resolve(__dirname, './peg_parser/src'); +function generateSyntaxParser(inputFile, nodePath) { + const readDirPath = path.resolve(__dirname, './syntax_parser/src'); const readDirSubFiles = fs.readdirSync(readDirPath); const catalogPath = path.resolve(inputFile, '..'); const catalogSubFiles = fs.readdirSync(catalogPath) - const pegjs = path.resolve(__dirname, './node_modules/pegjs/bin/pegjs'); + const parserPath = path.resolve(__dirname, './node_modules/pegjs/bin/pegjs'); if (catalogSubFiles.includes('dist')) { exec('rm -rf ' + catalogPath + '/dist/*.js'); @@ -32,16 +32,17 @@ function generatePeg(inputFile) { exec('mkdir ' + catalogPath + '/dist'); } - ;(async function pegTransJs () { + ;(async function transJs () { if (readDirSubFiles.length) { for (let item of readDirSubFiles) { let name = path.basename(item, '.peg'); if (name){ - await exec(pegjs + ' -o ' + catalogPath + '/dist/' + name + '.js ' + readDirPath + '/' + item); + await exec(nodePath + ' ' + parserPath + ' -o ' + + catalogPath + '/dist/' + name + '.js ' + readDirPath + '/' + item); } } } })() } -generatePeg(process.argv[2]); +generateSyntaxParser(process.argv[2], process.argv[0]); diff --git a/compiler/package.json b/compiler/package.json index b23b9bb..fe0cde3 100644 --- a/compiler/package.json +++ b/compiler/package.json @@ -10,12 +10,12 @@ ], "scripts": { "lint": "eslint --fix ./src --ext .ts", - "build": "npm run generatePeg && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts", + "build": "npm run generateSyntaxParser && npm run generateDeclarations && ./node_modules/.bin/babel ./src --out-dir lib --extensions .ts", "create": "node ./lib/create.js --env projectName", "compile": "webpack --config webpack.config.js --env buildMode=debug projectName", "test": "npm run build && mocha -r ts-node/register test/test.ts", "generateDeclarations": "node ./build_declarations_file.js ../../../interface/sdk-js/api/@internal/component/ets ./declarations ./lib", - "generatePeg": "node build_peg.js ./peg_parser/dist", + "generateSyntaxParser": "node build_parser.js ./syntax_parser/dist", "postinstall": "node npm-install.js" }, "devDependencies": { diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index c2e3e83..00c1ada 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -59,7 +59,7 @@ import { addLog, hasDecorator } from './utils'; -const parser = require('../peg_parser/dist/peg_parser.js'); +const parser = require('../syntax_parser/dist/syntax_parser.js'); export interface ComponentCollection { entryComponent: string; @@ -692,11 +692,11 @@ export function sourceReplace(source: string, sourcePath: string): ReplaceResult } export function preprocessExtend(content: string, sourcePath: string, log: LogInfo[]): string { - let pegCheckContent: string; + let syntaxCheckContent: string; let result: any; try { result = parser.parse(content); - pegCheckContent = result.content; + syntaxCheckContent = result.content; for (let i = 0; i < result.collect_extend.component.length; i++) { collectExtend( result.collect_extend.component[i], @@ -713,7 +713,7 @@ export function preprocessExtend(content: string, sourcePath: string, log: LogIn column: err.location.start.column, fileName: sourcePath }); - pegCheckContent = content; + syntaxCheckContent = content; } if (result.error_otherParsers) { for(let i = 0; i < result.error_otherParsers.length; i++) { @@ -726,7 +726,7 @@ export function preprocessExtend(content: string, sourcePath: string, log: LogIn }); } } - return pegCheckContent; + return syntaxCheckContent; } function collectExtend(component: string, attribute: string, parameter: string): void { diff --git a/compiler/peg_parser/src/parse_extend.peg b/compiler/syntax_parser/src/parse_extend.peg similarity index 100% rename from compiler/peg_parser/src/parse_extend.peg rename to compiler/syntax_parser/src/parse_extend.peg diff --git a/compiler/peg_parser/src/peg_parser.peg b/compiler/syntax_parser/src/syntax_parser.peg similarity index 100% rename from compiler/peg_parser/src/peg_parser.peg rename to compiler/syntax_parser/src/syntax_parser.peg