-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ahmet
committed
Mar 4, 2014
1 parent
8a26bdc
commit d3d4e34
Showing
6 changed files
with
119 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
atom-ObjC2RubyMotion | ||
atom-objc-2-rubymotion | ||
==================== | ||
|
||
Objective-C to RubyMotion converter converted to use with atom | ||
Objective-C to RubyMotion converter converted to use with atom editor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
class Converter | ||
constructor: (string) -> | ||
@orig = string | ||
@s = string | ||
|
||
|
||
result: -> | ||
@multilines_to_one_line() | ||
@replace_nsstring() | ||
@mark_spaces_in_string() | ||
@convert_square_brackets_expression() | ||
@remove_semicolon_at_the_end() | ||
@remove_autorelease() | ||
@remove_type_declaration() | ||
@restore_spaces_in_string() | ||
|
||
#allow idempotency | ||
result = @s | ||
@s = @orig | ||
|
||
return result | ||
|
||
# HELPERS | ||
|
||
convert_args: (match, groups...) => | ||
# Consider args with colon followed by spaces | ||
following_args = groups[1].replace /([^:]+)(\s+)(\S+):/g, '$1,$3:' | ||
|
||
# Clear extra spaces after colons | ||
following_args = following_args.replace /:\s+/g, ':' | ||
|
||
return "#{groups[0]}(#{following_args})" | ||
|
||
ruby_style_code: (match, groups...) => | ||
arg_pattern = /([^:]+)\:\s*(.+)/ | ||
|
||
msg = groups[1].replace(arg_pattern, @convert_args) | ||
return "#{groups[0]}.#{msg}" | ||
|
||
space_to_mark: (match, groups...) => | ||
return groups[0].replace /\s/g, '__SPACE__' | ||
|
||
# CONVERSIONS | ||
|
||
multilines_to_one_line: -> | ||
# Remove trailing white space first. Refs: TrimTrailingWhiteSpace | ||
@s = @s.replace /[\t ]+$/, '' | ||
@s = @s.replace /([^;\s])$\n\s*/mg, '$1 ' | ||
|
||
return this | ||
|
||
replace_nsstring: -> | ||
@s = @s.replace /@("(?:[^\\"]|\\.)*")/g, '$1' | ||
|
||
return this | ||
|
||
mark_spaces_in_string: -> | ||
@s = @s.replace /("(?:[^\\"]|\\.)*")/g, @space_to_mark | ||
|
||
return this | ||
|
||
restore_spaces_in_string: -> | ||
@s = @s.replace /__SPACE__/g, ' ' | ||
|
||
return this | ||
|
||
|
||
convert_square_brackets_expression: -> | ||
max_attempt = 10 # Avoid infinite loops | ||
attempt_count = 0 | ||
square_pattern = /\[([^\[\]]+?)\s+([^\[\]]+?)\]/g | ||
|
||
loop | ||
attempt_count += 1 | ||
if attempt_count > max_attempt | ||
break | ||
else if square_pattern.test @s | ||
@s = @s.replace(square_pattern, @ruby_style_code) | ||
else | ||
break | ||
|
||
return this | ||
|
||
remove_semicolon_at_the_end: -> | ||
@s = @s.replace /;/g, '' | ||
|
||
return this | ||
|
||
remove_autorelease: -> | ||
@s = @s.replace /\.autorelease/g, '' | ||
|
||
return this | ||
|
||
remove_type_declaration: -> | ||
@s = @s.replace /([^\s\S]*)[a-zA-Z_0-9]+\s*\*\s*([^=]+)=/gm, '$1$2=' | ||
|
||
return this | ||
|
||
@Converter = Converter | ||
|
||
|
||
module.exports = | ||
activate: -> | ||
atom.workspaceView.command "rubymotion:convert", => @convert() | ||
|
||
convert: -> | ||
# This assumes the active pane item is an editor | ||
selection = atom.workspace.getActiveEditor().getSelection() | ||
converter = new Converter selection.getText() | ||
selection.insertText(converter.result()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
{ | ||
"name": "ascii-art", | ||
"main": "./lib/ascii-art", | ||
"version": "0.0.0", | ||
"private": true, | ||
"name": "objc-2-rubymotion", | ||
"main": "./lib/objc-2-rubymotion", | ||
"version": "0.0.1", | ||
"description": "A short description of your package", | ||
"activationEvents": ["ascii-art:convert"], | ||
"repository": "https://github.com/atom/ascii-art", | ||
"activationEvents": ["rubymotion:convert"], | ||
"repository": "https://github.com/ahmetabdi/atom-objc-2-rubymotion", | ||
"license": "MIT", | ||
"engines": { | ||
"atom": ">0.39.0" | ||
}, | ||
"dependencies": { | ||
"figlet": "1.0.8" | ||
} | ||
"dependencies": {} | ||
} |
This file was deleted.
Oops, something went wrong.