Skip to content

Instantly share code, notes, and snippets.

View ichiriac's full-sized avatar
🚀

Ioan CHIRIAC ichiriac

🚀
View GitHub Profile
@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 {
@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);
npm install php-transpiler --save
@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);
@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 / php-parser.sh
Created December 17, 2016 18:37
Install php-parser from npm
npm install php-parser --save
<?php
interface Decorable {
public function doSomething();
}
interface Decorator extends Decorable {
public function __construct(Decorable $target);
}
@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)) {
<link href="../core-menu/core-submenu.html" rel="import">
<link href="../core-item/core-item.html" rel="import">
<link href="../core-pages/core-pages.html" rel="import">
<link href="../paper-checkbox/paper-checkbox.html" rel="import">
<polymer-element name="my-element">
<template>
<style>
#design_host {
@ichiriac
ichiriac / weby.php
Created October 16, 2013 17:17
Have some fun with pthreads
<?php
define('CRLF', "\r\n");
class HaveToWork extends Thread {
protected $wait;
public $socket = null;
public function __construct() {
$this->wait = true;
$this->start();
}
public function run() {