Git Product home page Git Product logo

snow's People

Contributors

trezjin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

snow's Issues

Arrow Operator

I cannot use below variable. Please help.

storeId = Mage..app().getStore()
Fatal error: Uncaught exception 'Exception' with message 'Unexpected character while trying to parse T_OBJECT_TYPE_COMPARISON at line 9: 
        storeId = Mage..app().getStore()
-----------------------^' in D:\Program\Snow\snowcompiler.php:358
Stack trace:
#0 D:\Program\Snow\snow.php(169): SnowCompiler->compile()
#1 {main}
  thrown in D:\Program\Snow\snowcompiler.php on line 358

Issue with Class

Hi, when I tried to input "class X" in my file the issue occurred as below.

Fatal error: Uncaught exception 'Exception' with message 'Unable to parse input: given input is no T_EXPRESSIONS:
class X
null' in D:\Program\Snow\snowcompiler.php:368
Stack trace:
#0 D:\Program\Snow\snow.php(169): SnowCompiler->compile()
#1 {main}

thrown in D:\Program\Snow\snowcompiler.php on line 368

new Object

I have an issue as creating new object. Please help.

Obj = new Data
Fatal error: Uncaught exception 'Exception' with message 'Unable to parse input: given input is no T_EXPRESSIONS:

Gettext Function

In Magento __('string') (double underscores) is a pre defined function used as a translator for multiple stores with different languages, and as I know Wordpress also has a similar function. However Snow didn't recognize this or the alias of getext _() (single underscore) as a function. Please help.

Mage..helper('adminhtml').__('Latest Products')
Fatal error: Uncaught exception 'Exception' with message 'Unexpected character while trying to parse T_FNCSCALL

throw new Exception

throw new Exception
is compiled to
throw (new Exception
Could you please help remove the bracket?

Update Documentation

  • in Quoted Strings section: NUM should be !NUM in Snow code
  • in Existence section: update PHP code for empty check

Improve parse error reporting

For example by taking the longest found chain for a target match: while walking through the language description and checking for correctness, remember how many entries of that specific rule have been matched already. Report the rule with the highest number of matched entries.

Template() Question

In template() function, can we use a class instead of pushing data from an array like below?
This is the way Mustache Php renders its data https://github.com/bobthecow/mustache.php

Hello {{name}}
You have just won {{value}}
Well, {{taxed_value}}, after taxes.
class Data {
    public $name  = "Son";
    public $value = 10000;

    public function taxed_value() {
        return $this->value - ($this->value * 0.4);
    }   
}

New Feature

I need to integrate many PHP codes into html, can Snow just parse codes between tag or ? This will make Snow much more flexible and very helpful to me.

Support for de-structuring assignments

add support for de-structuring assigments of the kind:

[a, b, , d] = <simple expression>

the left hand-side should therefore always be
[(<identifier>,)*<identifier>] =

DIRECTORY_SEPARATOR

I am using Windows so my folder path includes backslash \ and I have to use DS between url partials to prevent conflicts when deploy to production linux server. But Snow didn't recognize DS, I have tried many ways and it still doesn't work. Please help.

require_once Mage..getBaseDir('lib') % DS % 'Autoloader.php'
require_once Mage..getBaseDir('lib') + DS + 'Autoloader.php'

New Feature

I need to integrate many PHP codes into html, can Snow just parse codes between tag or ? This will make Snow much more flexible and very helpful to me.

Optional for Including Helper Functions

Snow's helper functions are really nice and useful. However could you please make it optional to include helpers at the top of compiled files?

 if (!function_exists('in')) { function in($needle, $haystack) { switch(gettype($haystack)) { case 'string': return strpos($haystack, $needle) !== false; case 'array': return in_array($needle, $haystack); case 'integer': return $haystack - $needle >= 0; case 'object': return isset($haystack->$needle);default:return null; } } } if (!function_exists('replace')) { function replace($haystack, $pattern, $rep) { if (is_array($haystack)) { $pos = array_search($pattern, $haystack, true); if ($pos === false) return $haystack; return array_replace($haystack, Array($pos => $rep)); } $pp = '/^[^a-zA-Z0-9\\\\s].*' . str_replace('/', '\/', $pattern[0]) . '[imsxADSUXJu]*$/m'; if (preg_match($pp, $pattern)) return preg_replace($pattern, $rep, $haystack); else return str_replace($pattern, $rep, $haystack); } } if (!function_exists('template')) { function template($file, $data, $rootCore = '$data', $eval = true, $depth = 0) { $code = str_replace('\'', '\\\'', (file_exists($file.'.tpl') ? file_get_contents($file . '.tpl') : $file)); $parseVar = function($var, $root = '$data') use ($rootCore) { if (trim($var) == '.') return $root; $parts = explode('.', trim($var)); if ($parts[0] == '') $start = $rootCore; else $start = $root . '[\'' . $parts[0] . '\']'; for ($i = 1; $i < count($parts); $i++) { $start .= '[\'' . $parts[$i]. '\']'; } return $start; }; $parseVars = function($code, $root = '$data') use ($parseVar) { preg_match_all('/\{\{(?!#\/\^)((?:[^}]|\}[^}])+)\}\}/m', $code, $matches); foreach ($matches[1] as $key => $match) { $var = $parseVar($match, $root); $var = '(is_object('.$var.') && is_callable('.$var.') ? '.$var.'() : '.$var . ')'; if (trim($match) != '.') { $var = 'function_exists(\''.$match.'\') ? '.$match.'() : ' . $var; } $code = str_replace($matches[0][$key], '\' . (' . $var . ') . \'', $code); } return $code; }; $parseTpl = function($code, $root = '$data') use ($depth, $file) { preg_match_all('/\{\{>((?:[^}]|\}[^\}])+)\}\}/m', $code, $matches); foreach ($matches[1] as $key => $match) { $code = str_replace($matches[0][$key], template(dirname((file_exists($file.'.tpl') ? $file : __FILE__))."/".trim($match), null, $root, false, $depth + 1), $code); } return $code; }; preg_match_all('/\{\{(#|\^)((?:[^}]|\}[^}])+)\}\}((?:[^{]|\{[^{]|\{\{[^#\^])*)\{\{\/\2\}\}/m', $code, $matches); foreach ($matches[1] as $key => $match) { $var = $parseVar($matches[2][$key]); if ($match == '^') { $code = str_replace($matches[0][$key], '\'; if (empty('.$var.')) { $__p .= \'' . $matches[3][$key] . '\'; } $__p .= \'', $code); } else if ($match == '#') { $replacement = '\'; if (!empty('.$var.')) { if (is_array('.$var.')) foreach (' . $var . ' as $counter => $entry'.$depth.') { $__p .= \''; $replacement .= $parseVars($parseTpl($matches[3][$key], '$entry'.$depth), '$entry'.$depth) . '\'; } else { $__p .= \'' . $matches[3][$key] . '\'; }} $__p .= \''; $code = str_replace($matches[0][$key], $replacement, $code); } } $code = $parseVars($parseTpl($code, $rootCore), $rootCore); if ($eval) { $code = '$__p = \'' . $code . '\';'; eval($code); return $__p; } return $code; } } 

Add some unification wrappers

Currently, using some of the PHP standard library functions are rather inconsistent and thus make it harder to actually use them. Those should be unified.

Some of them are:

  • preg_replace(pattern, replacement, haystack) and str_replace(needle, replacement, haystack) -> replace(haystack, needle/pattern, replacement)
  • in_array(needle, haystack), strpos(haystack, needle), isset(haystack[needle]), needle <= x, isset(haystack->needle) -> needle in x

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.