How to use the luaparse.parse function in luaparse

To help you get started, we’ve selected a few luaparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liwangqian / LuaCoderAssist / test / ts_symbol_parse.js View on Github external
fs_1.readFile(fileName, (err, data) => {
    var ast = luaparse_1.parse(data.toString('utf8'), {locations: true, scope: true});
    fs_1.writeFileSync("F:\\lua\\test.json", JSON.stringify(ast, null, 4));

    var walker = new walker_1.Walker(types_1.get({}), console.log);

    walker.processDocument(fileName, ast);

    console.log(JSON.stringify(walker.document, null, 4));
});
github ark120202 / babel-lua / packages / babel-plugin-lua-generator / __tests__ / index.js View on Github external
it(group, async () => {
          const directory = path.join(__dirname, 'fixtures', group);
          const [js, lua] = await Promise.all([
            readFile(path.join(directory, 'input.js')),
            readFile(path.join(directory, 'output.lua')),
          ]);

          let jsAst = babylon.parse(js);
          jsAst = transform(jsAst);
          jsAst = deepPick(jsAst, (val, key) => key !== 'loc');

          let luaAst = luaparse.parse(lua, { luaVersion: '5.3' });
          luaAst = deepMap(luaAst, (val, key) => (key === 'raw' ? undefined : val));
          delete luaAst.comments;

          try {
            expect(jsAst).toEqual(luaAst);
          } catch (err) {
            expect(generate(jsAst).code).toEqual(generate(luaAst).code);
          }
        });
      });
github Tencent / LuaPanda / src / code / server / docSymbolProcesser.ts View on Github external
try {
			let AST = luaparse.parse(luaText, { locations: true, scope: true, comments: true});
			instance.docInfo = new  Tools.docInformation(AST, uri, path);
			instance.buildDocDefineSymbols();
			instance.parseError = false;
			return instance;
		} catch (error) {
			Logger.ErrorLog("[Error] 解析文件 " + uri + " AST的过程中出错:");
			Logger.ErrorLog("[error stack]:" + error.stack );

			//建立空文件(没有AST)
			instance.docInfo = new  Tools.docInformation(new Object, uri, path);
			DocSymbolProcesser.tempSaveInstance = instance;
			//解析
			try {
				luaparse.parse(luaText, { locations: true, scope: true, onCreateNode: instance.onCreateNode});
			}catch{}
			instance.parseError = true;
			return instance;
		}
	}
github liwangqian / LuaCoderAssist / client / lib / metrics / lib / analysis.js View on Github external
stream.collect((error, data) => {
                resolve({
                    path: filePath,
                    ast: luaparse.parse(data, { locations: true, comments: false })
                });
            });
        });
github Tencent / LuaPanda / src / code / server / docSymbolProcesser.ts View on Github external
public static create(luaText: string, uri: string, path?: string) {
		let instance: DocSymbolProcesser = new DocSymbolProcesser();
		if(!path){
			path = Tools.uriToPath(uri);
		}
		try {
			let AST = luaparse.parse(luaText, { locations: true, scope: true, comments: true});
			instance.docInfo = new  Tools.docInformation(AST, uri, path);
			instance.buildDocDefineSymbols();
			instance.parseError = false;
			return instance;
		} catch (error) {
			Logger.ErrorLog("[Error] 解析文件 " + uri + " AST的过程中出错:");
			Logger.ErrorLog("[error stack]:" + error.stack );

			//建立空文件(没有AST)
			instance.docInfo = new  Tools.docInformation(new Object, uri, path);
			DocSymbolProcesser.tempSaveInstance = instance;
			//解析
			try {
				luaparse.parse(luaText, { locations: true, scope: true, onCreateNode: instance.onCreateNode});
			}catch{}
			instance.parseError = true;
github ukon1990 / wow-auction-helper / src / client / utils / tsm / tsm-lua.util.ts View on Github external
public processLuaData(input: any) {
    const result = {};
    const fields = lua.parse(input).body[0].init[0].fields;

    fields.forEach(field => {
      const fRes = this.convertField(field);
      if (!fRes) {
        return;
      }

      if (fRes.character && fRes.character.realm) {
        this.addRealmBoundData(fRes, result, field);

      } else {
        if (fRes.type === undefined || fRes.type === 'undefined') {
        } else {
          result[fRes.type] = fRes.data;
        }
      }
github ark120202 / babel-lua / packages / lua-parse / src / index.js View on Github external
export default function parse(input, options = {}) {
  const onCreateNode = options.locations
    ? node => {
        if (node.loc) {
          node.loc.filename = options.sourceFilename;
          if (t.isIdentifier(node)) {
            node.loc.identifierName = node.name;
          }
        }
        if (options.onCreateNode) options.onCreateNode(node);
      }
    : options.onCreateNode;
  return luaparse.parse(input, {
    ...options,
    onCreateNode,
  });
}
github ukon1990 / wow-auction-helper / client / src / client / utils / lua.util.ts View on Github external
static toObject(input): object {
    const { fields } = lua.parse(input).body[0].init[0];
    return this.handleFields(fields as TableKey[]);
  }
github liwangqian / LuaCoderAssist / server / lib / engine / core.js View on Github external
break;
            case 'IfStatement':
                parseIfStatement(node);
                break;
            case 'MemberExpression':
                walkNode(node.base);
                break;
            case 'Chunk':
                walkNodes(node.body);
                break;
            default:
                break;
        }
    };

    const node = luaparse_1.parse(code, {
        comments: false,
        scope: true,
        ranges: true,
    });

    walkNode(node);

    if (moduleType.moduleMode) {
        let origModule = _G.get(theModule.name);
        if (!origModule) {
            _G.set(theModule.name, theModule);
        } else {
            mergeTableFields(origModule.type.fields, theModule.type.fields);
        }
    }
github DaanBroekhof / JoroDox / app / utils / tasks / LuaScriptParserTask.js View on Github external
filesList.each(path => {
      const luaAST = luaparser.parse(jetpack.read(args.project.rootPath + syspath.sep + path.replace(new RegExp('/', 'g'), syspath.sep)), {locations: true});

      const data = this.convertAstTree(luaAST.body[0], luaAST.comments);

      if (scripts.length % Math.floor(files.length / this.progressReportRate) === 0) {
        this.progress(scripts.length, filesList.size(), `Parsing ${filesList.size()} LUA scripts...`);
      }

      scripts.push({path, data});
      relations.push(this.addRelationId({
        fromKey: 'lua_script',
        fromType: 'lua_scripts',
        fromId: path,
        toKey: 'source',
        toType: 'files',
        toId: path
      }));

luaparse

A Lua parser in JavaScript

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis