Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added loose 'or', 'and'. line continuation on method signatures and c…
…alls
  • Loading branch information
dwarring committed Oct 15, 2013
1 parent ee184fe commit 4904f02
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
13 changes: 9 additions & 4 deletions examples/rubyish/rubyish.nqp
Expand Up @@ -43,10 +43,10 @@ grammar Rubyish::Grammar is HLL::Grammar {

token tmpl-hdr {'<%rbi>' \h* \n? <?{$*IN_TEMPLATE := 1}>}
token tmpl-esc {\h* '<%'
[<?{$*IN_TEMPLATE}>||<.panic('Template directive precedes "<%rbi>"')>]
[<?{$*IN_TEMPLATE}> || <.panic('Template directive precedes "<%rbi>"')>]
}
token tmpl-unesc { '%>' \h* \n?
[<?{$*IN_TEMPLATE}>|| <.panic('Template directive precedes "<%rbi>"')>]
[<?{$*IN_TEMPLATE}> || <.panic('Template directive precedes "<%rbi>"')>]
}

rule stmtlist {
Expand Down Expand Up @@ -78,7 +78,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
token comma { :s [','|'=>'] :s }

rule signature {
'(' ~ ')' [<param>* %% <comma>]
'(' ~ ')' [:my $*LINE_SPAN := 1; <param>* %% <comma>]
}

token param { <ident> }
Expand Down Expand Up @@ -193,6 +193,8 @@ grammar Rubyish::Grammar is HLL::Grammar {
Rubyish::Grammar.O(':prec<j=>, :assoc<right>', '%assignment');
Rubyish::Grammar.O(':prec<l=>, :assoc<left>', '%tight_and');
Rubyish::Grammar.O(':prec<k=>, :assoc<left>', '%tight_or');
Rubyish::Grammar.O(':prec<d=>, :assoc<left>', '%loose_and');
Rubyish::Grammar.O(':prec<c=>, :assoc<left>', '%loose_or');
}

# Operators - mostly stolen from NQP
Expand Down Expand Up @@ -226,12 +228,15 @@ grammar Rubyish::Grammar is HLL::Grammar {
token infix:sym<||> { <sym> <O('%tight_or, :op<unless>')> }
token infix:sym<//> { <sym> <O('%tight_or, :op<defor>')> }

token infix:sym<and> { <sym> <O('%loose_and, :op<if>')> }
token infix:sym<or> { <sym> <O('%loose_or, :op<unless>')> }

# Parenthesis
token circumfix:sym<( )> {'(' <.ws> <EXPR> ')' <O('%methodop')> }

# Method call
token postfix:sym<.> {
'.' <ident> [ '(' ~ ')' <call-args>? ]?
'.' <ident> [ '(' ~ ')' <call-args=.paren-args>? ]?
<O('%methodop')>
}

Expand Down
5 changes: 4 additions & 1 deletion examples/rubyish/t/infix.t
@@ -1,4 +1,4 @@
puts "1..17"
puts "1..19"
x=1

puts "ok #{x} - assignment"
Expand Down Expand Up @@ -31,3 +31,6 @@ puts "#{(nil // 2) == 2? 'ok' : 'nok'} 15 - infix // arced"

puts "ok #{2 **4} - exponentiation **"
puts "ok #{37 % 20} - modulus %"

puts "#{1&&0 or 1? 'ok' : 'nok'} 18 - loose 'or'"
puts "#{1||0 and 0||1? 'ok' : 'nok'} 19 - loose 'and'"
2 changes: 1 addition & 1 deletion examples/rubyish/t/interpolation.t 100644 → 100755
Expand Up @@ -5,7 +5,7 @@ puts "ok #{a} - variable"
puts "ok #{a+1} - expression"
b = 'ok'
puts "#{b} #{3*(a - 1) + 1} - expression"
puts %q{ok 5}
puts %q<ok 5> ~ ' - %q<...>'
puts %Q{ok #{a*=3} - expression - side affect}
puts %Q{ok #{(a+=2)-1} - expression - side affect}
puts "#{if a==8 then 'ok' else 'nok' end} #{a} - nested statement"
11 changes: 8 additions & 3 deletions examples/rubyish/t/line-spanning.t
Expand Up @@ -20,9 +20,14 @@ h = {"a" => 10,
}
puts "#{h<c>? 'ok' : 'nok'} 3 - hash spanning lines"

def tricky(k,
n)
puts "#{k} - #{n} - multi-line signatures and calls"
end

puts(
tricky(
"ok",

"ok 4 - call args spanning lines"
4

)
)

0 comments on commit 4904f02

Please sign in to comment.