Skip to content

Instantly share code, notes, and snippets.

Created August 6, 2016 23:22
Show Gist options
  • Save anonymous/501954bc2c538afca6b1b3bf032fac95 to your computer and use it in GitHub Desktop.
Save anonymous/501954bc2c538afca6b1b3bf032fac95 to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2008-2013 Stanislaw Findeisen <[email protected]>
*
* This file is part of phphard.
*
* phphard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* phphard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with phphard. If not, see <http://www.gnu.org/licenses/>.
*/
open Common;
/* Token data: file name, line number, line offset, token */
type tokenData = | TokenData (string, int, int);
type constantLiteral =
| Null tokenData
| Int (tokenData, int)
| Float (tokenData, float)
| StringSQ (tokenData, string);
type simpleType =
| TypeBool tokenData | TypeFloat tokenData | TypeInt tokenData | TypeString tokenData;
type identifier = | Identifier (tokenData, string);
type variable = | This tokenData | Variable (tokenData, string);
type identifier_variable = | IdentVar_ident identifier | IdentVar_var variable;
type expression =
| ConstLiteral constantLiteral
| StringDQ (tokenData, string)
| VarExpr variable
| IdentExpr identifier
| New (identifier, list expression)
| Dereference (expression, list identifier_variable) /* (f()[5])->$a->b->$c */
| Parent (list identifier_variable)
| Self (list identifier_variable)
| StaticReferenceChain (identifier, list identifier_variable) /* A::$a->b->$c */
| ArrayExpr (expression, expression)
| FunCallExpr (expression, list expression)
| PreDecrement expression
| PreIncrement expression
| PostDecrement expression
| PostIncrement expression
| UnaryMinus expression
| BitwiseNot expression
| TypeCast (simpleType, expression)
| InstanceOf (expression, identifier)
| LogicalNot expression
| Multiplication (expression, expression)
| Division (expression, expression)
| Modulo (expression, expression)
| Plus (expression, expression)
| Minus (expression, expression)
| Concat (expression, expression)
| ShiftLeft (expression, expression)
| ShiftRight (expression, expression)
| IsSmaller (expression, expression)
| IsSmallerEq (expression, expression)
| IsEqual (expression, expression)
| IsIdentical (expression, expression)
| BitwiseAnd (expression, expression)
| BitwiseXor (expression, expression)
| BitwiseOr (expression, expression)
| LogicalAnd (expression, expression)
| LogicalXor (expression, expression)
| LogicalOr (expression, expression)
| TernaryChoice (expression, expression, expression)
| AssignExpr (expression, expression);
type formalArgument = | FormalArg variable | TypedFormalArg (identifier, variable);
type formalArgumentWDefault = | FormalArgWDefault (formalArgument, constantLiteral);
type formalArgsList = (list formalArgument, list formalArgumentWDefault);
type switchItem = | SwCase expression | SwDefault;
type variableDeclaration = | VarDecl variable | VarDeclAssig (variable, expression);
type statement =
| AssignStmt (expression, expression)
| VarDeclStmt variableDeclaration
| FunCallStmt (expression, list expression)
| Break tokenData
| Return expression
| Throw expression
| If (expression, statement)
| IfElse (expression, statement, statement)
| SwitchStmt (expression, list (switchItem, statement))
| TryCatch (statement, list (formalArgument, statement)) /* Must be >=1 catch clauses! */
| BlockStmt (list statement);
type functionDefinition = | Function (identifier, formalArgsList, statement);
type classItemVisibility = | Public | Protected | Private;
type classItem =
| InstanceMethod (classItemVisibility, functionDefinition)
| StaticMethod (classItemVisibility, functionDefinition)
| StaticVar (classItemVisibility, variableDeclaration)
| StaticConst (classItemVisibility, identifier, expression);
type abstractClause = | Concrete | Abstract;
type extendsClause = | RootClass | Extends identifier;
type classDefinition = | Class (abstractClause, identifier, extendsClause, list classItem);
type sourceFileItem =
| PHPStatement statement | PHPFunction functionDefinition | PHPClass classDefinition;
type sourceFile = | PHPSourceFile (list sourceFileItem);
let funCallExprAsPair fce =>
switch fce {
| FunCallExpr f params [@implicit_arity] => (f, params)
| _ => raise (PHPAnalException "expected FunCallExpr")
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment