btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

Function Issues #64

Open webarthur opened 8 years ago

webarthur commented 8 years ago

define function doesnt work! Its comile to $define(...)

Functions doesnt work without parentheses? =/

webarthur commented 8 years ago
add_action('admin_menu', 'advset_menu')

Compiles to:

$add_action('admin_menu', 'advset_menu')

=/

webarthur commented 8 years ago
if is_admin()

  # Admin menu
  add_action('admin_menu', 'advset_menu')

  # Add plugin option in Plugins page
  add_filter( 'plugin_action_links', 'advset_plugin_action_links', 10, 2 )

Parse error on line NaN: Unexpected 'IDENTIFIER'

jsommr commented 8 years ago

The prepended $ to function calls surprised me as well. I'd really like to see that fixed, because there aren't many x to php transpilers out there. The fact that code written in Mammouth can be transpiled to js as well could make this a very interesting language to use.

btwael commented 8 years ago

This is one of most complex bug that we have, cause mammouth compiler scoping/context system identifies only variables and functions declared in the current mammouth file or included/imported PHP or mammouth files, in addition to system predefined funcs and vars. However I'm planning to fix this by rewriting the compiler again to add this feature.

But if you can't wait for this moment, you can hack on src/predefined.coffee, and add a Line at the end like:

    'add_action': 'function'
    'add_filter': 'function

Then compile mammouth by running jake build (you must install dependencies) and enjoy :D

pwhelan commented 8 years ago

Functions doesnt work without parentheses? =/

any plans of fixing this?

toovy commented 8 years ago

@btwael great lang, love it, would really appreciate to use mammouth. This bug is probably really complex. While the hack may work e.g. Wordpress has so many predefined functions that imho the advantages of using mammouth instead of php are nearly lost. Is this bug fixable?

A similar issue arises when using global constants:

My lib still written in php:

<?php
define('FOO', 'bar')

Then the new lib on top:

{{
echo FOO
}}

Compiles to:

<?php echo $FOO ?>

Here the constant function could be used as a workaround, but it also compiles to $constant('FOO').

Thanks,BR toovy

btwael commented 8 years ago

I'm working on mammouth 4, where plugins development with external APIs (including wordpress...) will be fixed. (I finished my finales today, so I start developing this new version).

Thank you for your support

toovy commented 8 years ago

@btwael great, really looking forward to it. :)