Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Commit

Permalink
Fixed #36
Browse files Browse the repository at this point in the history
  • Loading branch information
DeflatedPickle committed Jan 31, 2018
1 parent 7076e74 commit 728cdd9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fixed [#33](https://github.com/DeflatedPickle/Nishi/issues/33)
- Fixed [#35](https://github.com/DeflatedPickle/Nishi/issues/35)
- Changed fail-safe return type to "var"
- Fixed [#36](https://github.com/DeflatedPickle/Nishi/issues/36)

### [Nishi-0.18.6-alpha](https://github.com/DeflatedPickle/Nishi/releases/tag/v0.18.6-alpha)
- Fixed [#24](https://github.com/DeflatedPickle/Nishi/issues/24)
Expand Down
6 changes: 3 additions & 3 deletions Nishi.g4
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function: FUNCTION ID OPEN_BRACKET (parameter COMMA)* parameter* CLOSE_BRACKET f
| OVERRIDE FUNCTION ID OPEN_BRACKET (parameter COMMA)* parameter* CLOSE_BRACKET TYPE_SETTER type_ function_block #OverrideFunctionSetter // override fun my_func(name -> String) -> Void {}
;
call_function: ID OPEN_BRACKET (call_parameter COMMA)* call_parameter* CLOSE_BRACKET;
class_access: ID (OPEN_BRACKET (call_parameter COMMA)* call_parameter* CLOSE_BRACKET)* (AT call_function | AT ID)*;
class_access: (ID | type_) (OPEN_BRACKET (call_parameter COMMA)* call_parameter* CLOSE_BRACKET)* (AT call_function | AT ID)*;
access: ID AT ID
| ID AT ID OPEN_BRACKET (call_parameter COMMA)* call_parameter* CLOSE_BRACKET
;
Expand Down Expand Up @@ -116,9 +116,9 @@ interface_block: OPEN_BLOCK (doc_block | interface_private_block | interface_pub
get_block: GET OPEN_BLOCK RETURN ID CLOSE_BLOCK;
set_block: SET OPEN_BLOCK assignment CLOSE_BLOCK;

value: STRING | LITERAL_STRING | MULTI_STRING | NUMBER | BOOLEAN | FLOAT | list_ | ID | ID type_setter (OPEN_BRACKET (parameter COMMA)* parameter* CLOSE_BRACKET)* | class_access;
value: STRING | LITERAL_STRING | MULTI_STRING | NUMBER | BOOLEAN | FLOAT | ID | (ID | type_) OPEN_BRACKET (parameter COMMA)* parameter* CLOSE_BRACKET | (ID | type_) type_setter (OPEN_BRACKET (parameter COMMA)* parameter* CLOSE_BRACKET)* | class_access | type_ | class_access;
type_setter: LESS_THAN (type_ COMMA)* type_* MORE_THAN;
type_: 'String' | 'Integer' | 'Boolean' | 'Void' | 'List' type_setter | ID | ID type_setter;
type_: 'String' | 'Integer' | 'Boolean' | 'Void' | 'Float' | 'List' | ('List') type_setter | ('List') type_setter OPEN_BRACKET (call_parameter COMMA)* call_parameter* CLOSE_BRACKET | ID | ID type_setter;
list_: OPEN_SQUARE (value COMMA)* value* CLOSE_SQUARE;

parameter: ID TYPE_SETTER type_ // arg -> Integer
Expand Down
14 changes: 12 additions & 2 deletions NishiTranspiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,22 +305,32 @@ def enterAssignment(self, ctx:NishiParser.AssignmentContext):
string.append(f"{ctx.ID()}")

if value:
if value.split("()")[0] in self.variable_contexts["classes"]:
if value.split("(")[0] in self.variable_contexts["classes"]:
self.insert_text(f"{' '.join(string)} = ")
return

elif value.split("(")[0] in self.carp_to_csharp.keys():
capital_type = True

elif value[0].isupper() and value.split("<")[0] in self.carp_to_csharp.keys():
capital_type = True

if value:
if value.startswith("'") and value.endswith("'"):
value = value.replace("'", "\"").replace("\\", "\\\\")

if multi_string:
value = value.replace("\"\"\"", "@\"", 1).replace("\"\"\"", "\"", 1)

if "@" in value:
self.insert_text(f"{' '.join(string)} = {value.split('@')[0]}.")
return

string.append(f"= {'new ' if capital_type else ''}{value}{'f' if is_float else ''}")

self.variable_contexts[self.context_type][self.context].append(str(ctx.ID()))

self.insert_text(f"{' '.join(string).replace('this@', '')}", 1, True)
self.insert_text(f"{' '.join(string).replace('this@', '').replace('@', '.')}", 1, True)
# self.insert_text(f"{' '.join(string).replace('this@', '').replace('@', '.')}", 1, True)

# Print
Expand Down
10 changes: 10 additions & 0 deletions examples/simple_class.nishi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class MyClass {
println(my_non_lit_string)
println(my_multi_string)

my_list: List<String>()
my_list@Add("MyValue")

print_me: String@Join("\n", my_list)
println(print_me)

# print(String@Join("\n", my_list))
# The line above doesn't work.
# However, variables can be set to the value and then printed.

my_dict -> Dictionary<String, String>: Dictionary<String, String>()
my_dict@Add("MyKey", "MyValue")
}
Expand Down

0 comments on commit 728cdd9

Please sign in to comment.