How to use php-parser - 10 common examples

To help you get started, we’ve selected a few php-parser 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 HvyIndustries / crane / client / src / hvy / treeBuilder.ts View on Github external
return new Promise((resolve, reject) =>
        {
            phpParser.parser.locations = true;
            phpParser.parser.docBlocks = true;
            var ast = phpParser.parseCode(text);

            this.BuildObjectTree(ast, filePath).then((tree) =>
            {
                // TODO -- Convert this to promise
                var symbolCache = this.BuildSymbolCache(tree, filePath);

                var returnObj = {
                    tree: tree,
                    symbolCache: symbolCache
                };

                // DEBUG
                console.log("Built tree for file: " + filePath);

                resolve(returnObj);
            });
github HvyIndustries / crane / client / src / hvy / treeBuilder.ts View on Github external
return new Promise((resolve, reject) =>
        {
            phpParser.parser.locations = true;
            phpParser.parser.docBlocks = true;
            var ast = phpParser.parseCode(text);

            this.BuildObjectTree(ast, filePath).then((tree) =>
            {
                // TODO -- Convert this to promise
                var symbolCache = this.BuildSymbolCache(tree, filePath);

                var returnObj = {
                    tree: tree,
                    symbolCache: symbolCache
                };

                // DEBUG
                console.log("Built tree for file: " + filePath);

                resolve(returnObj);
github HvyIndustries / crane / client / src / hvy / treeBuilder.ts View on Github external
return new Promise((resolve, reject) =>
        {
            phpParser.parser.locations = true;
            phpParser.parser.docBlocks = true;
            var ast = phpParser.parseCode(text);

            this.BuildObjectTree(ast, filePath).then((tree) =>
            {
                // TODO -- Convert this to promise
                var symbolCache = this.BuildSymbolCache(tree, filePath);

                var returnObj = {
                    tree: tree,
                    symbolCache: symbolCache
                };

                // DEBUG
                console.log("Built tree for file: " + filePath);
github glayzzle / php-writer / src / trait.js View on Github external
Trait.prototype.setConstant = function(name, value) {
    var constant = this.getConstant(name);
    if (!constant) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            'const ' + name + (
                value ? ' = ' + value : ''
            ) + ';\n' +
        ' }');
        this.ast.body.unshift(
            ast.children[0].body[0]
        );
    } else {
        if (typeof value !== 'undefined') constant.setValue(value);
    }
    return this;
};
github glayzzle / php-writer / src / class.js View on Github external
Class.prototype.setMethod = function(name, args, body, flags) {
    var method = this.getMethod(name);
    if (!method) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            flags + ' function ' + name + '(' + args +  ') {\n' +
                body + '\n' +
            '}\n' +
        ' }');
        this.ast.body.push(
            ast.children[0].body[0]
        );
    } else {
        // update the function
        if (typeof flags !== 'undefined') method.setFlags(flags);
        if (typeof args !== 'undefined') method.setArgs(args);
        if (typeof body !== 'undefined') method.setCode(body);
    }
    return this;
};
github glayzzle / php-writer / src / interface.js View on Github external
Interface.prototype.setMethod = function(name, args, body, flags) {
    var method = this.getMethod(name);
    if (!method) {
        // append the function
        var ast = parser.parseEval('class a { \n' +
            flags + ' function ' + name + '(' + args +  ') {\n' +
                body + '\n' +
            '}\n' +
        ' }');
        this.ast.body.push(
            ast.children[0].body[0]
        );
    } else {
        // update the function
        if (typeof flags !== 'undefined') method.setFlags(flags);
        if (typeof args !== 'undefined') method.setArgs(args);
        if (typeof body !== 'undefined') method.setCode(body);
    }
    return this;
};
github recca0120 / vscode-phpunit / server / src / Parser.ts View on Github external
/// 
import Engine from 'php-parser';
import files from './Filesystem';
import URI from 'vscode-uri';
import { PathLike } from 'fs';
import { TestNode, TestOptions, TestSuiteNode } from './TestNode';
import {
    TextDocument,
    WorkspaceFolder as _WorkspaceFolder,
} from 'vscode-languageserver';

const engine = Engine.create({
    ast: {
        withPositions: true,
        withSource: true,
    },
    parser: {
        php7: true,
        debug: false,
        extractDoc: true,
        suppressErrors: true,
    },
    lexer: {
        all_tokens: true,
        comment_tokens: true,
        mode_eval: true,
        asp_tags: true,
        short_tags: true,
github chris-l / php-unparser / test / index.js View on Github external
fs.readFile(filename, function(err, data) {
    if (!err) {
      counter ++;
      try {
        var ast = parser.parseCode(data.toString(), {
          parser: {
            extractDoc: true,
            debug: isDebug
          },
          ast: {
            withPositions: true
          }
        });
        var code = unparse(ast);
        if (isDebug) console.log(code);
        if (counter === total) {
          console.log('Finished to test ' + total + ' file(s)');
          process.exit(0);
        }
        if (counter % 500 === 0) {
          console.log(counter + ' of ' + total + ' - ' + Math.round(counter / total * 100) + '%');
github glayzzle / php-writer / test / assert.js View on Github external
(function parseCode() {
      ast = parser.parseEval(code, {
        parser: {
          extractDoc: true
        }
      });
    }).should.not.throw(code);
    this.obj.should.be.Object();
github recca0120 / vscode-phpunit / server / src / phpunit / test-suite.ts View on Github external
parse(code: string, uri: string): Method[] {
        return this.getTests(
            Engine.parseCode(code, {
                ast: {
                    withPositions: true,
                    withSource: true,
                },
                parser: {
                    debug: false,
                    extractDoc: true,
                    suppressErrors: true,
                },
                lexer: {
                    all_tokens: true,
                    comment_tokens: true,
                    mode_eval: true,
                    asp_tags: true,
                    short_tags: true,
                },

php-parser

Parse PHP code from JS and returns its AST

BSD-3-Clause
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis