Skip to content

Instantly share code, notes, and snippets.

@ichiriac
ichiriac / scan.js
Created Jan 29, 2017
Scan a path with PHP files
View scan.js
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 Jan 24, 2017
Quick Start / Usage / php-transpiler
View usage.js
// 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 / demo.php
Created Dec 17, 2016
A sample PHP file for showing AST with php-parser
View demo.php
<?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 Jan 3, 2017
A simple usage of php-parser
View demo.js
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 Dec 17, 2016
Install php-parser from npm
View php-parser.sh
npm install php-parser --save
View gist:e5dd520a0be57ca163f7
<?php
interface Decorable {
public function doSomething();
}
interface Decorator extends Decorable {
public function __construct(Decorable $target);
}
@ichiriac
ichiriac / ManualParser.js
Created Nov 25, 2014
Tryout of a manual implementation of a parser
View ManualParser.js
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)) {
View designer.html
<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 Oct 16, 2013
Have some fun with pthreads
View weby.php
<?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() {
You can’t perform that action at this time.