lib/parser/methods.fy in fancy-0.3.3 vs lib/parser/methods.fy in fancy-0.4.0
- old
+ new
@@ -72,24 +72,23 @@
case /(.*)#{(.*)}(.*)/ -> |matches|
prefix = matches[1]
interpol_str = matches[2]
suffix = matches[3]
- binding = AST MessageSend new: line message: (ast: line identifier: "binding") to: (AST Self new: line) args: (AST RubyArgs new: line args: [])
- evalstr = AST StringLiteral new: line value: interpol_str
- msg = ast: line identifier: "eval:binding:"
- binding_send = AST MessageSend new: line message: msg to: (ast: line identifier: "Fancy") \
- args: (AST MessageArgs new: line args: [evalstr, binding])
-
prefix_str = ast: line string: (" " + prefix + " ") # hack, pre- & append " " since it gets removed
suffix_str = ast: line string: (" " + suffix + " ")
+ interpol_ast = AST StringInterpolation new: line code: interpol_str
# create messagesend to concatenate:
concat_ident = ast: line identifier: "++"
- concat_prefix_send = AST MessageSend new: line message: concat_ident to: prefix_str args: (AST MessageArgs new: line args: [binding_send])
- concat_suffix_send = AST MessageSend new: line message: concat_ident to: concat_prefix_send args: (AST MessageArgs new: line args: [suffix_str])
+ interpol_send = AST MessageSend new: line message: concat_ident to: prefix_str args: (AST MessageArgs new: line args: [interpol_ast])
- concat_suffix_send # this shall get returned, yo
+ # don't concatenate suffix if it's empty..
+ unless: (suffix == "") do: {
+ interpol_send = AST MessageSend new: line message: concat_ident to: interpol_send args: (AST MessageArgs new: line args: [suffix_str])
+ }
+
+ interpol_send # this shall get returned, yo
case _ ->
AST StringLiteral new: line value: str
}
}
@@ -162,10 +161,17 @@
def ast: line oper: oper arg: arg to: receiver (AST Self new: line) {
message = ast: line send: oper arg: arg
ast: line send: message to: receiver
}
+ def ast: line oper: oper arg: arg1 arg: arg2 to: receiver (AST Self new: line) {
+ m1 = SelectorValue new(oper, arg1)
+ m2 = SelectorValue new(ast: line identifier: "", arg2)
+ message = [m1, m2]
+ ast: line send: message to: receiver
+ }
+
def ast: line future_oper: oper arg: arg to: receiver {
oper_send = ast: line oper: oper arg: arg to: receiver
AST FutureSend new: line message_send: oper_send
}
@@ -246,10 +252,15 @@
def ast: line oper: op arg: arg body: body access: access ('public) owner: owner (nil) {
margs = [ast: line param: op var: arg]
ast: line method: margs body: body access: access owner: owner
}
+ def ast: line oper: op arg: arg1 arg: arg2 body: body access: access ('public) owner: owner (nil) {
+ margs = [SelectorVarDefault new(op, arg1, nil), SelectorVarDefault new(ast: line identifier: "", arg2, nil)]
+ ast: line method: margs body: body access: access owner: owner
+ }
+
def ast: line method: margs body: body access: access ('public) owner: owner (nil) {
if: (margs is_a?(AST Identifier)) then: {
args = AST MethodArgs new: line args: []
if: owner then: {
AST SingletonMethodDef new: line name: margs args: args \
@@ -294,15 +305,11 @@
def ast: line block: body args: args {
args = AST BlockArgs new: line args: args
AST BlockLiteral new: line args: args body: body
}
- def ast: line require_: file {
- AST Require new: line file: file
- }
-
- def ast: line class: name parent: parent body: body {
+ def ast: line class: name parent: parent body: body (AST ExpressionList new: line) {
AST ClassDef new: line name: name parent: parent body: body
}
def ast: line match_expr: expr body: match_body {
AST Match new: line expr: expr body: match_body
@@ -326,9 +333,21 @@
}
def ast: line ruby_args: args block: block (nil) {
{ args = [] } unless: args
AST RubyArgs new: line args: args block: block
+ }
+
+ def ast: line string_value: string {
+ string
+ }
+
+ def ast: line goto: label_name {
+ AST Goto new: line label_name: label_name
+ }
+
+ def ast: line label: label {
+ AST Label new: line name: label
}
def ast: line parse_error: text {
ParseError new: line message: text filename: @filename . raise!
}