farleyknight-ionize 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. data/README.rdoc +59 -0
  2. data/Rakefile +5 -0
  3. data/bin/ionize +47 -0
  4. data/lib/ionize.rb +75 -0
  5. data/lib/ionize/environment.rb +56 -0
  6. data/lib/ionize/environment/application.rb +58 -0
  7. data/lib/ionize/environment/php_array.rb +95 -0
  8. data/lib/ionize/parser.rb +272 -0
  9. data/lib/ionize/tokenizer.rb +544 -0
  10. data/lib/ionize/translate.rb +34 -0
  11. data/lib/ionize/translate/composite_string_statements.rb +79 -0
  12. data/lib/ionize/translate/debug.rb +16 -0
  13. data/lib/ionize/translate/ext.rb +47 -0
  14. data/lib/ionize/translate/function_args.rb +132 -0
  15. data/lib/ionize/translate/if_statements.rb +42 -0
  16. data/lib/ionize/translate/multiple_statements.rb +22 -0
  17. data/lib/ionize/translate/php_to_ruby.rb +40 -0
  18. data/lib/ionize/translate/rails_for_php.rb +191 -0
  19. data/lib/ionize/translate/rewritable.rb +133 -0
  20. data/lib/ionize/translate/rewrites.rb +51 -0
  21. data/lib/ionize/translate/statements.rb +622 -0
  22. data/lib/ionize/translate/switch_case_statements.rb +52 -0
  23. data/lib/ionize/translate/term_statements.rb +76 -0
  24. data/lib/ionize/translate/translator.rb +52 -0
  25. data/lib/ionize/version.rb +9 -0
  26. data/spec/fixtures/array_lookup.php +10 -0
  27. data/spec/fixtures/boolean_operators.php +5 -0
  28. data/spec/fixtures/boolean_operators.rb +6 -0
  29. data/spec/fixtures/class_def.php +34 -0
  30. data/spec/fixtures/class_def.rb +34 -0
  31. data/spec/fixtures/dangling_else.php +8 -0
  32. data/spec/fixtures/dangling_else.rb +12 -0
  33. data/spec/fixtures/drupal_1.php +663 -0
  34. data/spec/fixtures/drupal_2.php +1152 -0
  35. data/spec/fixtures/empty_string.php +12 -0
  36. data/spec/fixtures/for_loop.php +17 -0
  37. data/spec/fixtures/for_loop2.php +13 -0
  38. data/spec/fixtures/for_loop3.php +16 -0
  39. data/spec/fixtures/for_loop3.rb +17 -0
  40. data/spec/fixtures/for_loop4.php +5 -0
  41. data/spec/fixtures/for_loop4.rb +6 -0
  42. data/spec/fixtures/foreach.php +9 -0
  43. data/spec/fixtures/foreach2.php +8 -0
  44. data/spec/fixtures/foreach3.php +7 -0
  45. data/spec/fixtures/foreach3.rb +7 -0
  46. data/spec/fixtures/fun_def.php +9 -0
  47. data/spec/fixtures/fun_def2.php +30 -0
  48. data/spec/fixtures/fun_def2.rb +30 -0
  49. data/spec/fixtures/fun_def3.php +33 -0
  50. data/spec/fixtures/fun_def4.php +43 -0
  51. data/spec/fixtures/fun_def4.rb +37 -0
  52. data/spec/fixtures/fun_def5.php +36 -0
  53. data/spec/fixtures/fun_with_if.php +6 -0
  54. data/spec/fixtures/fun_with_if.rb +6 -0
  55. data/spec/fixtures/fun_with_ifs.php +12 -0
  56. data/spec/fixtures/fun_with_ifs.rb +14 -0
  57. data/spec/fixtures/hello_world.php +6 -0
  58. data/spec/fixtures/heredoc.php +6 -0
  59. data/spec/fixtures/heredoc.rb +5 -0
  60. data/spec/fixtures/if.php +6 -0
  61. data/spec/fixtures/if.rb +7 -0
  62. data/spec/fixtures/if_boolean.php +5 -0
  63. data/spec/fixtures/if_boolean.rb +5 -0
  64. data/spec/fixtures/if_else.php +11 -0
  65. data/spec/fixtures/if_else1.php +17 -0
  66. data/spec/fixtures/if_else2.php +8 -0
  67. data/spec/fixtures/if_else3.php +15 -0
  68. data/spec/fixtures/if_else_nested.php +14 -0
  69. data/spec/fixtures/if_else_nested.rb +15 -0
  70. data/spec/fixtures/if_else_series.php +12 -0
  71. data/spec/fixtures/if_else_series.rb +12 -0
  72. data/spec/fixtures/if_not.php +5 -0
  73. data/spec/fixtures/if_not.rb +5 -0
  74. data/spec/fixtures/if_with_brackets.php +7 -0
  75. data/spec/fixtures/if_with_brackets.rb +7 -0
  76. data/spec/fixtures/long_if_else.php +10 -0
  77. data/spec/fixtures/long_if_else.rb +9 -0
  78. data/spec/fixtures/oo.php +16 -0
  79. data/spec/fixtures/php_nuke/sql_layer.php +527 -0
  80. data/spec/fixtures/postop.php +3 -0
  81. data/spec/fixtures/preop.php +7 -0
  82. data/spec/fixtures/simple_fun_def.php +4 -0
  83. data/spec/fixtures/switch_case.php +13 -0
  84. data/spec/fixtures/switch_case.rb +14 -0
  85. data/spec/fixtures/switch_case2.php +25 -0
  86. data/spec/fixtures/switch_case3.php +40 -0
  87. data/spec/fixtures/switch_case3.rb +42 -0
  88. data/spec/fixtures/switch_case4.php +56 -0
  89. data/spec/fixtures/switch_case5.php +71 -0
  90. data/spec/fixtures/switch_case_with_rescue_nil.php +43 -0
  91. data/spec/fixtures/switch_case_with_rescue_nil.rb +35 -0
  92. data/spec/fixtures/tertiary.php +3 -0
  93. data/spec/helper.rb +17 -0
  94. data/spec/php_environment_spec.rb +83 -0
  95. data/spec/php_parser_spec.rb +121 -0
  96. data/spec/php_translator_spec.rb +358 -0
  97. data/spec/rails_for_php_spec.rb +303 -0
  98. metadata +191 -0
@@ -0,0 +1,12 @@
1
+
2
+
3
+
4
+ // This should are the arguments as two nodes, not one
5
+
6
+ parse_two_strings('', $_GET['content']);
7
+
8
+
9
+ // This should parse multiple array lookups
10
+
11
+ parse_nested_array($_GET['something']['another']);
12
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/php
2
+
3
+ srand(time());
4
+ for ($i=0; $i < 3; $i++)
5
+ {
6
+ $random = (rand()%3);
7
+ $slot[] = $random;
8
+ }
9
+ print("<td width=\"33%\"><center>$slot[0]</td>");
10
+ print("<td width=\"33%\"><center>$slot[1]</td>");
11
+ print("<td width=\"33%\"><center>$slot[2]</td>");
12
+
13
+ if($slot[0] == $slot[1] && $slot[0] == $slot[2])
14
+ {
15
+ print("</td></tr>Winner! -- Hit refresh on your browser to play again");
16
+ exit;
17
+ }
@@ -0,0 +1,13 @@
1
+ <?php
2
+
3
+ for ($i = 0; $i < 3; $i++) {
4
+ print $i;
5
+ }
6
+ print "\n";
7
+
8
+ $i = 0;
9
+ while ($i < 3) {
10
+ print $i;
11
+ $i++;
12
+ }
13
+ ?>
@@ -0,0 +1,16 @@
1
+
2
+ $res = array();
3
+ $nr = array();
4
+
5
+ $row = array();
6
+ $result = array();
7
+ $result = odbc_fetch_row($res, $nr);
8
+ $nf = odbc_num_fields($res); /* Field numbering starts at 1 */
9
+
10
+ for($count=1; $count < $nf+1; $count++) {
11
+ $field_name = odbc_field_name($res, $count);
12
+ $field_value = odbc_result($res, $field_name);
13
+ $row[$field_name] = $field_value;
14
+ }
15
+
16
+
@@ -0,0 +1,17 @@
1
+
2
+ res = array()
3
+ nr = array()
4
+
5
+ row = array()
6
+ result = array()
7
+ result = odbc_fetch_row(res, nr)
8
+ nf = odbc_num_fields(res)
9
+
10
+ count = 1
11
+ while count < nf + 1
12
+ field_name = odbc_field_name(res, count)
13
+ field_value = odbc_result(res, field_name)
14
+ row[field_name] = field_value
15
+ count += 1
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+
2
+ for ( $i = 0; $i < 3; $i++ ) {
3
+ print $i;
4
+ }
5
+
@@ -0,0 +1,6 @@
1
+
2
+ i = 0
3
+ while i < 3
4
+ print i
5
+ i += 1
6
+ end
@@ -0,0 +1,9 @@
1
+
2
+
3
+ foreach (array_keys($updates) as $update) {
4
+ if ($update > $schema_version) {
5
+ $default = $update;
6
+ break;
7
+ }
8
+ }
9
+
@@ -0,0 +1,8 @@
1
+
2
+
3
+
4
+ foreach (post('start') as $module => $version) {
5
+ drupal_set_installed_schema_version($module, $version - 1);
6
+ $updates = drupal_get_schema_versions($module);
7
+ $max_version = max($updates);
8
+ }
@@ -0,0 +1,7 @@
1
+
2
+ $items = array();
3
+ foreach ($items as $item) {
4
+ if ($item == 4)
5
+ break;
6
+ }
7
+
@@ -0,0 +1,7 @@
1
+
2
+ items = array()
3
+ items.each do |item|
4
+ if item == 4
5
+ break
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+
2
+ // Easy.. really easy
3
+ // Should be a piece of cake
4
+
5
+ function slotnumber()
6
+ {
7
+ srand(time());
8
+ }
9
+
@@ -0,0 +1,30 @@
1
+
2
+ function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
3
+ if (array_key_exists('not null', $attributes) and $attributes['not null']) {
4
+ $not_null = 'NOT NULL';
5
+ }
6
+
7
+ if (array_key_exists('default', $attributes)) {
8
+ if (is_null($attributes['default'])) {
9
+ $default_val = 'NULL';
10
+ $default = 'default NULL';
11
+ } elseif ($attributes['default'] === FALSE) {
12
+ $default = '';
13
+ } else {
14
+ $default_val = "$attributes[default]";
15
+ $default = "default $attributes[default]";
16
+ }
17
+ }
18
+
19
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type");
20
+ if (!empty($default)) {
21
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default");
22
+ }
23
+
24
+ if (!empty($not_null)) {
25
+ if (!empty($default)) {
26
+ $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val");
27
+ }
28
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
29
+ }
30
+ }
@@ -0,0 +1,30 @@
1
+
2
+ def db_add_column(ret, table, column, type, attributes = array())
3
+ if array_key_exists('not null', attributes) and attributes['not null']
4
+ not_null = 'NOT NULL'
5
+ end
6
+
7
+ if array_key_exists('default', attributes)
8
+ if is_null(attributes['default'])
9
+ default_val = 'NULL'
10
+ default = 'default NULL'
11
+ elsif attributes['default'] === false
12
+ default = ''
13
+ else
14
+ default_val = "#{attributes['default']}"
15
+ default = "default #{attributes['default']}"
16
+ end
17
+ end
18
+
19
+ ret << update_sql("ALTER TABLE {" + table + "} ADD #{column} #{type}")
20
+ if !empty(default)
21
+ ret << update_sql("ALTER TABLE {" + table + "} ALTER #{column} SET #{default}")
22
+ end
23
+
24
+ if !empty(not_null)
25
+ if !empty(default)
26
+ ret << update_sql("UPDATE {" + table + "} SET #{column} = #{default_val}")
27
+ end
28
+ ret << update_sql("ALTER TABLE {" + table + "} ALTER #{column} SET NOT NULL")
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+
2
+ // Here's a goodie..
3
+ // Watch out for the '&' and 'and' nodes
4
+
5
+ function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
6
+ if (array_key_exists('not null', $attributes) and $attributes['not null']) {
7
+ $not_null = 'NOT NULL';
8
+ }
9
+ if (array_key_exists('default', $attributes)) {
10
+ if (is_null($attributes['default'])) {
11
+ $default_val = 'NULL';
12
+ $default = 'default NULL';
13
+ }
14
+ elseif ($attributes['default'] === FALSE) {
15
+ $default = '';
16
+ }
17
+ else {
18
+ $default_val = "$attributes[default]";
19
+ $default = "default $attributes[default]";
20
+ }
21
+ }
22
+
23
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type");
24
+ if (!empty($default)) {
25
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default");
26
+ }
27
+ if (!empty($not_null)) {
28
+ if (!empty($default)) {
29
+ $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val");
30
+ }
31
+ $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL");
32
+ }
33
+ }
@@ -0,0 +1,43 @@
1
+
2
+
3
+ function update_fix_d6_requirements() {
4
+ $ret = array();
5
+
6
+ if (drupal_get_installed_schema_version('system') < 6000 && !variable_get('update_d6_requirements', FALSE)) {
7
+ $spec = array('type' => 'int', 'size' => 'small', 'default' => 0, 'not null' => TRUE);
8
+ db_add_field($ret, 'cache', 'serialized', $spec);
9
+ db_add_field($ret, 'cache_filter', 'serialized', $spec);
10
+ db_add_field($ret, 'cache_page', 'serialized', $spec);
11
+ db_add_field($ret, 'cache_menu', 'serialized', $spec);
12
+
13
+ db_add_field($ret, 'system', 'info', array('type' => 'text'));
14
+ db_add_field($ret, 'system', 'owner', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
15
+ if (db_table_exists('locales_target')) {
16
+ db_add_field($ret, 'locales_target', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
17
+ }
18
+ if (db_table_exists('locales_source')) {
19
+ db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
20
+ db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
21
+ }
22
+ variable_set('update_d6_requirements', TRUE);
23
+
24
+ $schema = array();
25
+
26
+ // Create the cache_block table. See system_update_6027() for more details.
27
+ $schema['cache_block'] = array(
28
+ 'fields' => array(
29
+ 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
30
+ 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
31
+ 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
32
+ 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
33
+ 'headers' => array('type' => 'text', 'not null' => FALSE),
34
+ 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
35
+ ),
36
+ 'indexes' => array('expire' => array('expire')),
37
+ 'primary key' => array('cid'),
38
+ );
39
+ db_create_table($ret, 'cache_block', $schema['cache_block']);
40
+ }
41
+
42
+ return $ret;
43
+ }
@@ -0,0 +1,37 @@
1
+
2
+ def update_fix_d6_requirements
3
+ ret = array()
4
+ if (drupal_get_installed_schema_version("system") < (6000 and (not variable_get("update_d6_requirements", false)))) then
5
+ spec = array("type" => "int", "size" => "small", "default" => 0, "not null" => true)
6
+ db_add_field(ret, "cache", "serialized", spec)
7
+ db_add_field(ret, "cache_filter", "serialized", spec)
8
+ db_add_field(ret, "cache_page", "serialized", spec)
9
+ db_add_field(ret, "cache_menu", "serialized", spec)
10
+
11
+ db_add_field(ret, "system", "info", array("type" => "text"))
12
+ db_add_field(ret, "system", "owner", array("type" => "varchar", "length" => 255, "not null" => true, "default" => ""))
13
+ if db_table_exists("locales_target") then
14
+ db_add_field(ret, "locales_target", "language", array("type" => "varchar", "length" => 12, "not null" => true, "default" => ""))
15
+ end
16
+ if db_table_exists("locales_source") then
17
+ db_add_field(ret, "locales_source", "textgroup", array("type" => "varchar", "length" => 255, "not null" => true, "default" => "default"))
18
+ db_add_field(ret, "locales_source", "version", array("type" => "varchar", "length" => 20, "not null" => true, "default" => "none"))
19
+ end
20
+ variable_set("update_d6_requirements", true)
21
+
22
+ schema = array()
23
+
24
+ schema["cache_block"] = array(
25
+ "fields" => array(
26
+ "cid" => array("type" => "varchar", "length" => 255, "not null" => true, "default" => ""),
27
+ "data" => array("type" => "blob", "not null" => false, "size" => "big"),
28
+ "expire" => array("type" => "int", "not null" => true, "default" => 0),
29
+ "created" => array("type" => "int", "not null" => true, "default" => 0),
30
+ "headers" => array("type" => "text", "not null" => false),
31
+ "serialized" => array("type" => "int", "size" => "small", "not null" => true, "default" => 0)),
32
+ "indexes" => array("expire" => array("expire")), "primary key" => array("cid"))
33
+
34
+ db_create_table(ret, "cache_block", schema["cache_block"])
35
+ end
36
+ return ret
37
+ end
@@ -0,0 +1,36 @@
1
+
2
+ function update_do_one($module, $number, &$context) {
3
+ // If updates for this module have been aborted
4
+ // in a previous step, go no further.
5
+ if (!empty($context['results'][$module]['#abort'])) {
6
+ return;
7
+ }
8
+
9
+ $function = $module .'_update_'. $number;
10
+ if (function_exists($function)) {
11
+ $ret = $function($context['sandbox']);
12
+ }
13
+
14
+ if (isset($ret['#finished'])) {
15
+ $context['finished'] = $ret['#finished'];
16
+ unset($ret['#finished']);
17
+ }
18
+
19
+ if (!isset($context['results'][$module])) {
20
+ $context['results'][$module] = array();
21
+ }
22
+ if (!isset($context['results'][$module][$number])) {
23
+ $context['results'][$module][$number] = array();
24
+ }
25
+ $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret);
26
+
27
+ if (!empty($ret['#abort'])) {
28
+ $context['results'][$module]['#abort'] = TRUE;
29
+ }
30
+ // Record the schema update if it was completed successfully.
31
+ if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) {
32
+ drupal_set_installed_schema_version($module, $number);
33
+ }
34
+
35
+ $context['message'] = 'Updating '. check_plain($module) .' module';
36
+ }
@@ -0,0 +1,6 @@
1
+
2
+ function db_add_column(&$ret, $table, $column, $type, $attributes = array()) {
3
+ if (array_key_exists('not null', $attributes) and $attributes['not null']) {
4
+ $not_null = 'NOT NULL';
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+
2
+ def db_add_column(ret, table, column, type, attributes = array())
3
+ if array_key_exists('not null', attributes) and attributes['not null']
4
+ not_null = 'NOT NULL'
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+
2
+
3
+ function hey() {
4
+ if (TRUE)
5
+ print "wtf";
6
+
7
+ if (TRUE)
8
+ print "okay";
9
+
10
+ if (TRUE)
11
+ print "whatever";
12
+ }
@@ -0,0 +1,14 @@
1
+
2
+ def hey
3
+ if true
4
+ print "wtf"
5
+ end
6
+
7
+ if true
8
+ print "okay"
9
+ end
10
+
11
+ if true
12
+ print "whatever"
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+
2
+ <?php
3
+
4
+ print "Hello World!\n";
5
+
6
+ ?>
@@ -0,0 +1,6 @@
1
+
2
+
3
+ $something =<<<EOF
4
+ okay
5
+ EOF;
6
+
@@ -0,0 +1,5 @@
1
+
2
+
3
+ something =<<EOF
4
+ okay
5
+ EOF
@@ -0,0 +1,6 @@
1
+
2
+
3
+ $something = "value";
4
+
5
+ if ($something == "value")
6
+ print "value";
@@ -0,0 +1,7 @@
1
+
2
+
3
+ something = "value"
4
+
5
+ if (something == "value")
6
+ print "value"
7
+ end