Skip to content

Instantly share code, notes, and snippets.

View ichiriac's full-sized avatar
🚀

Ioan CHIRIAC ichiriac

🚀
View GitHub Profile
@ichiriac
ichiriac / ManualParser.js
Created November 25, 2014 15:15
Tryout of a manual implementation of a parser
var lex = require('./lexer');
var tokens = require('./tokens');
var names = require('./grammar/tokens');
function isNumber(n) {
return n != '.' && n != ',' && !isNaN(parseFloat(n)) && isFinite(n);
}
function getTokenName(token) {
if (!isNumber(token)) {
<?php
interface Decorable {
public function doSomething();
}
interface Decorator extends Decorable {
public function __construct(Decorable $target);
}
@ichiriac
ichiriac / php-parser.sh
Created December 17, 2016 18:37
Install php-parser from npm
npm install php-parser --save
@ichiriac
ichiriac / demo.js
Last active January 3, 2017 12:18
A simple usage of php-parser
var parser = require('php-parser');
// initialize a new parser instance
var instance = new parser({
parser: {
extractDoc: true,
suppressErrors: true
},
ast: {
withPositions: true
@ichiriac
ichiriac / demo.php
Created December 17, 2016 19:26
A sample PHP file for showing AST with php-parser
<?php
/**
* Some namespace & file description
*/
namespace foo {
function bar($a, $b) {
return $a + $b;
}
// will print : 5
echo bar(2, 3);
npm install php-transpiler --save
@ichiriac
ichiriac / usage.js
Created January 24, 2017 13:06
Quick Start / Usage / php-transpiler
// initialize the php parser factory class
var engine = require('php-parser');
var transpiler = require('php-transpiler');
var jsCode = transpiler.generate(
engine.parseCode('<?php echo "Hello World";')
);
console.log(jsCode);
@ichiriac
ichiriac / scan.js
Created January 29, 2017 08:23
Scan a path with PHP files
var fs = require('fs');
// https://www.npmjs.com/package/php-parser
var parser = require('php-parser');
// https://www.npmjs.com/package/glob
var glob = require('glob');
glob("**/*.php", options, function (er, files) {
for(var i = 0; i < files.length; i++) {
var file = files[i];
try {