{"id":15578480,"url":"https://github.com/xtlsoft/pisp","last_synced_at":"2025-04-24T02:11:44.234Z","repository":{"id":57085097,"uuid":"144929157","full_name":"xtlsoft/Pisp","owner":"xtlsoft","description":"A lisp-like language for php.","archived":false,"fork":false,"pushed_at":"2018-12-31T08:13:10.000Z","size":37,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T09:34:34.595Z","etag":null,"topics":["language","lisp","parser","php","php-library","php7"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtlsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-16T02:59:53.000Z","updated_at":"2024-03-16T11:19:33.000Z","dependencies_parsed_at":"2022-08-24T14:56:39.344Z","dependency_job_id":null,"html_url":"https://github.com/xtlsoft/Pisp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtlsoft%2FPisp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtlsoft%2FPisp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtlsoft%2FPisp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtlsoft%2FPisp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtlsoft","download_url":"https://codeload.github.com/xtlsoft/Pisp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546086,"owners_count":21448260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language","lisp","parser","php","php-library","php7"],"created_at":"2024-10-02T19:10:45.791Z","updated_at":"2025-04-24T02:11:44.216Z","avatar_url":"https://github.com/xtlsoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pisp\r\n\r\nA lisp-like language for php.\r\n\r\n## Overview\r\n\r\nThis is a sample Hello World code of it.\r\n\r\nPHP Code:\r\n\r\n```php\r\n\u003c?php\r\nrequire_once \"vendor/autoload.php\";\r\n$pisp = new \\Pisp\\Pisp;\r\n$code = file_get_contents(\"code.pisp\");\r\n$pisp-\u003edefine(\"print\", function ($args, $vm) {\r\n    foreach ($args as $v) {\r\n        if (is_string($v) || method_exists($v, \"__toString\")) {\r\n            echo $v;\r\n        } else {\r\n            var_dump($v);\r\n        }\r\n    }\r\n});\r\n$pisp-\u003eexecute($code);\r\n```\r\n\r\nContent of code.pisp:\r\n\r\n```lisp\r\n(print \"Hello World\" \"\\n\")\r\n```\r\n\r\nResult:\r\n\r\n```plain\r\nHello World\r\n```\r\n\r\n## Installation\r\n\r\n```bash\r\ncomposer require xtlsoft/pisp\r\n```\r\n\r\n## Documentation\r\n\r\n### Basic PHP API\r\n\r\n#### \\Pisp\\Pisp\r\n\r\nWe have built a facade for you.\r\nYou can use it easily.\r\n\r\n```php\r\n\u003c?php\r\n$pisp = new \\Pisp\\Pisp();\r\n```\r\n\r\nRight, The `\\Pisp\\Pisp` class is the facade.\r\n\r\nIt extends the `\\Pisp\\VM\\VM` class and have an `execute` method to execute code directly.\r\n\r\nFor example:\r\n\r\n```php\r\n\u003c?php\r\n$code = '(print [\"Hello World\"] [\"\\n\"])';\r\n$pisp-\u003eexecute($code);\r\n```\r\n\r\n#### \\Pisp\\VM\\VM\r\n\r\nThis is the main VM class.\r\n\r\nWe have a define and a delete method which are used to define and delete functions.\r\n\r\nYes! Variables are also functions in Pisp because it is purely functional.\r\n\r\n```php\r\n\u003c?php\r\n$vm = new \\Pisp\\Pisp; // Also can be $vm = new \\Pisp\\VM\\VM;\r\n\r\n$vm-\u003edefine(\"abc\", 123);\r\n$vm-\u003edefine(\"+\", function ($args, $vm) {\r\n    return $args[0] + $args[1];\r\n});\r\n\r\n$vm-\u003edelete(\"abc\");\r\n\r\necho $vm-\u003eexecute(\"(+ 1 2)\"); // 3\r\n```\r\n\r\nHave you noticed? When defining a function, it must a valid callback with 2 parameters.\r\nThe first one is the array of the real arguments, and the second one is the instance of the \\Pisp\\VM\\VM class.\r\n\r\nYou can dynamically add functions.\r\n\r\n#### \\Pisp\\Parser\\Parser\r\n\r\nThis is for parsing code.\r\n\r\n```php\r\n\u003c?php\r\n$parser = new \\Pisp\\Parser\\Parser;\r\n$rslt = $parser-\u003eparse('(print [\"Hello World\\n\"])');\r\nvar_export($rslt instanceof \\Pisp\\Parser\\AST\\Root); // true\r\n```\r\n\r\n#### \\Pisp\\Parser\\ASTWalker\r\n\r\nThis is for walking the AST.\r\n\r\n```php\r\n\u003c?php\r\n$walker = new \\Pisp\\Parser\\ASTWalker($rslt);\r\n$walker-\u003ewalk(function (\\Pisp\\Parser\\AST\\Node $node) {\r\n    echo $node-\u003ename, PHP_EOL;\r\n});\r\n```\r\n\r\n### Grammar and language specifications\r\n\r\n#### Basic Grammar\r\n\r\nA function call starts with a `(` and ends with a `)` .\r\nFunction name and arguments are separated by any blank characters.\r\n\r\nArguments are optional.\r\n\r\nFor example:\r\n\r\n```lisp\r\n(+ 1 2)\r\n(+\r\n 1\r\n 2\r\n)\r\n( + 1 2 )\r\n(a_function_call_without_arguments)\r\n```\r\n\r\nThe literals are not surrounded by `[` and `]` now.\r\n\r\nFor example:\r\n\r\n```lisp\r\n(+ 1 2)\r\n(print \"a string\")\r\n(+ 1.2 1.4)\r\n```\r\n\r\nMoreover, Pisp supports lazy calls.\r\n\r\nJust add an `@` before the function name and the arguments will be their ASTs.\r\n\r\n```lisp\r\n(@print (undefined_function))\r\n```\r\n\r\nThis will outputs the var_dump result of the `\\Pisp\\Parser\\AST\\CallingNode` class.\r\n\r\n#### Default Functions\r\n\r\nPisp doesn't include any functions by default. This means, if you runs the examples above, you will get a `NoFunctionException`. You must define them by yourself.\r\n\r\nHowever, there's a useful StdLib, just:\r\n\r\n```php\r\n\\Pisp\\StdLib\\StandardLibrary::register($vm);\r\n```\r\n\r\n#### Comments\r\n\r\nPisp only supports block comments starting with `#|` and ending with `|#`.\r\n\r\n```lisp\r\n#| This is the function comment |#\r\n(do_something (some_function) [\"literal\"]) #| ok too |#\r\n```\r\n\r\nPisp supports nested comments.\r\n\r\nExample:\r\n\r\n```lisp\r\n#| comment some code\r\n    (print \"Hello World\") #| This prints \"Hello World\" |#\r\n|#\r\n```\r\n\r\nYou can also use a little trick to let it support it:\r\n\r\n```php\r\n\u003c?php\r\n$pisp = new \\Pisp\\Pisp;\r\n$pisp-\u003edefine(\"rem\", function ($args, $vm) {\r\n    return;\r\n});\r\n```\r\n\r\nThen, you can just use:\r\n\r\n```lisp\r\n(@rem \"This is a comment\")\r\n```\r\n\r\nAnd this won't be executed.\r\n\r\n#### Literals\r\n\r\nPisp now support many literals.\r\n\r\nLiterals are not surrounded by `[` and `]` now.\r\n\r\nThere are currently three types of literals: numeric, string and list.\r\n\r\n##### Numeric\r\n\r\nNumeric is an integer or float.\r\n\r\nExample:\r\n\r\n```lisp\r\n(print 123 123.456 1e10 0x3f3f3f3f)\r\n```\r\n\r\n##### String\r\n\r\nStrings are surrounded by quotes. Supports muiltiple quotes.\r\n\r\n`\\n` or other things are not fully supported at the moment.\r\n\r\nExample:\r\n\r\n```lisp\r\n(print \"Hello World\" 'Another \\'test\\' Hello World')\r\n```\r\n\r\n##### List\r\n\r\nList is a collection of values.\r\n\r\nIt is surrounded with `[` and `]`, each value is separated with a `,`.\r\n\r\nExample:\r\n\r\n```lisp\r\n(print [1, 2, [3, 4]] [\"Hello\", 234, \"World\", 'you'])\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtlsoft%2Fpisp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtlsoft%2Fpisp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtlsoft%2Fpisp/lists"}