Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move BlockPass out of arglists, add particle proc-arg shorthand

  • Loading branch information...
commit 7fabf05d578cc792b5e6f7b795dde02ae6199843 1 parent e521fc6
Alex Suraci authored
23 kernel/boot.ay
View
@@ -18,8 +18,19 @@ macro(@~(x: Word)): InstanceVariable new(line, x text)
macro(~x = ~y): Assign new(line, x to-pattern to-node, y)
-- [x, y] { x + y }
-macro(~List ~Block):
- @right arguments = @left elements
+macro([~*args] ~Block):
+ @right arguments = args
+ @right
+
+-- [x, y] &z { x + y }
+macro([~*args] &~blk ~Block):
+ @right arguments = args
+ @right block = blk
+ @right
+
+-- &z { x + y }
+macro(&~blk ~Block):
+ @right block = blk
@right
-- foo { bar }
@@ -74,6 +85,14 @@ macro(~_ ~(Word)(~*args) [~*ys] ~(z: Block)):
x block = z
x
+-- proc-arg
+macro(~x &~y):
+ @left expand tap [s]:
+ s block = BlockPass new(y line, y)
+
+-- particle/symbol block-passing shorthand
+macro(~x #~y): `(~x &#~y)
+
-- foo [bar, ...]
macro(~x [~*ys]):
to-send tap [x]:
4 kernel/concurrency.ay
View
@@ -22,6 +22,6 @@ macro(receive ~(body: Block) after(~timeout) ~(action: Block)):
`(Actor receive [~e]: ~*bs)
-spawn(&action) := Actor send(#spawn, &action)
+spawn &action := Actor send(#spawn) &action
-spawn-link(&action) := Actor send(#spawn-link, &action)
+spawn-link &action := Actor send(#spawn-link) &action
3  kernel/condition.ay
View
@@ -70,6 +70,9 @@ macro(with-restarts(~*restarts) ~(block: Block)):
`(~(n)(~*as)) ->
`(Restart new(#~n, [~*as] { ~e }))
+ `(~(n)(~*as) &~b) ->
+ `(Restart new(#~n, [~*as] &~b { ~e }))
+
body =
pairs reduce(
`{ ~block rescue: (e: StandardError) -> error(e) }
58 kernel/control-flow.ay
View
@@ -20,14 +20,30 @@ macro(unless(~c) ~(b: Block)):
macro(super):
ZSuper new(line)
+for-macro:
+ splat-from(arguments) := do:
+ args = arguments dup
+
+ splat =
+ if(args last is-a?(Atomy::AST::Unary) && args last receiver == "*" to-sym)
+ then: args pop receiver
+ else: nil
+
+ [args, splat]
+
+macro(super &~blk):
+ Super new(line, [], nil, blk)
+
macro(super ~(blk: Block)):
- Super new(line, [], blk)
+ Super new(line, [], nil, blk)
-macro(super(~*args) ~(blk: Block)):
- Super new(line, args, blk)
+macro(super(~*as) ~(blk: Block)):
+ [args, splat] = splat-from(as)
+ Super new(line, args, splat, blk)
-macro(super(~*args)):
- Super new(line, args, nil)
+macro(super(~*as)):
+ [args, splat] = splat-from(as)
+ Super new(line, args, splat)
macro(break):
Break new(line, 'nil)
@@ -191,40 +207,24 @@ macro(~x rescue ~(y: Block) else ~(z: Block)):
module(Atomy::AST):
class(Super < Node):
- children([#arguments], #block?)
+ children([#arguments], #splat?, #block?)
generate
bytecode(g) := do:
pos(g)
- block = @block
- splat = nil
-
- args = 0
@arguments each [a]:
- e = a prepare
- e match:
- BlockPass:
- block =! e
- break
-
- Splat:
- splat =! e
- break
-
- _:
- e bytecode(g)
- args += 1
-
- when(splat):
- splat compile(g)
+ a compile(g)
+
+ when(@splat):
+ @splat compile(g)
g cast-array
- if(block)
- then: block compile(g)
+ if(@block)
+ then: @block compile(g)
else: g push-nil
- g send-super(nil, args, splat)
+ g send-super(nil, @arguments size, !!@splat)
class(ZSuper < Node):
generate
2  kernel/data-delta.ay
View
@@ -73,7 +73,7 @@ macro(~Word ~(s: Atomy::AST::String)(~*args)):
line,
@left text,
s raw || s value,
- args collect(&#text)
+ args collect #text
s value
)
2  kernel/data.ay
View
@@ -47,7 +47,7 @@ macro(~x for(~e) in(~c)):
macro(~x for(~e) in(~c) if(~t)):
`(~c collect [~e] { ~x } select [~e] { ~t })
-Array inject-right(i = _undefined, &block) :=
+Array inject-right(i = _undefined) &block :=
reverse inject(i) [x, y]: block [y, x]
.infix right 5 .
6 kernel/doc.ay
View
@@ -170,8 +170,8 @@ namespace(Atomy::Pretty):
raw(s) := Atomy::Pretty::Raw new(s to-s)
line := Atomy::Pretty::Line new(true)
linebreak := Atomy::Pretty::Line new(false)
- column(&f) := Atomy::Pretty::Column new(f)
- nesting(&f) := Atomy::Pretty::Nesting new(f)
+ column &f := Atomy::Pretty::Column new(f)
+ nesting &f := Atomy::Pretty::Nesting new(f)
group(x) := { x flatten } <|> { x }
softline := group(line)
softbreak := group(linebreak)
@@ -223,7 +223,7 @@ namespace(Atomy::Pretty):
-- call `f' with the width of the passed document, and render the result
-- after it
- width(d, &f) :=
+ width(d) &f :=
column [c1]: d <> column [c2]: f [c2 - c1]
-- helper documents
2  kernel/format/formatter.ay
View
@@ -292,7 +292,7 @@ module(Atomy::Format):
justify-to(_, _, []) := ""
justify-to(j, to, all: s . ss) := do:
- needed = to - all collect(&#size) inject(&#"+")
+ needed = to - all collect #size inject #(+ _)
spacings =
condition:
16 kernel/io.ay
View
@@ -6,21 +6,21 @@ x println := x tap: ^output-port puts(x to-s)
x dump := x tap: ^output-port print(x to-s)
x write := x tap: ^output-port puts(x show)
-with-output-to((filename: String), mode = "w", &action) :=
+with-output-to((filename: String), mode = "w") &action :=
let(output-port = File open(filename, mode)):
action ensuring:
^output-port close
-with-output-to(io, &action) :=
+with-output-to(io) &action :=
let(output-port = io): action call
-with-error-to((filename: String), mode = "w", &action) :=
+with-error-to((filename: String), mode = "w") &action :=
let(error-port = File open(filename, mode)):
action ensuring:
^error-port close
-with-error-to(io, &action) :=
- let(error-port = io, &action)
+with-error-to(io) &action :=
+ let(error-port = io) &action
read-line(sep = $separator) := do:
@@ -52,10 +52,10 @@ read-char := read-byte chr
read(length = nil, buffer = nil) :=
^input-port send(#read, length, buffer)
-with-input-from((filename: String), mode = "r", &action) :=
+with-input-from((filename: String), mode = "r") &action :=
let(input-port = File open(filename, mode)):
action ensuring:
^input-port close
-with-input-from(io, &action) :=
- let(input-port = io, &action)
+with-input-from(io) &action :=
+ let(input-port = io) &action
10 kernel/kpeg.ay
View
@@ -35,23 +35,23 @@ for-macro:
`(~g reg(~(b raw)))
process-val(g, c: Atomy::AST::Call) := do:
- args = "(" + c arguments collect(&#show) join(", ") + ")"
+ args = "(" + c arguments collect #show join(", ") + ")"
`(~g ref(~(c name text to-s), nil, ~args))
process-val(g, `@~(c: Atomy::AST::Call)) := do:
- args = "(" + c arguments collect(&#show) join(", ") + ")"
+ args = "(" + c arguments collect #show join(", ") + ")"
`(~g invoke(~(c name text to-s), ~args))
process-val(g, `^~(c: Atomy::AST::Call)) := do:
- args = "(" + c arguments collect(&#show) join(", ") + ")"
+ args = "(" + c arguments collect #show join(", ") + ")"
`(~g foreign-invoke("parent", ~(c name text to-s), ~args))
process-val(g, `%~(c: Atomy::AST::Call)) := do:
[gram, name] = c name text to-s split(".")
- args = "(" + c arguments collect(&#show) join(", ") + ")"
+ args = "(" + c arguments collect #show join(", ") + ")"
`(~g foreign-invoke(~gram, ~name, ~args))
@@ -139,7 +139,7 @@ macro(grammar: ~*body): names [g]:
`(~(name)(~*args) := ~val) ->
let(rule = name text,
- rule-vars = ::Set new(args to-a collect(&#text))):
+ rule-vars = ::Set new(args to-a collect #text)):
`(~g set(~(name text to-s)
~process-val(g, val)
~(args collect [x]: x text to-s)))
8 kernel/namespace.ay
View
@@ -4,18 +4,18 @@ module(Atomy):
HELPERS = Hash new
class(AtomyDelegator < SimpleDelegator):
- define(method-missing(m, *args, &block)):
+ define(method-missing(m, *args) &block):
target = self _-getobj--
{ if(target respond-to?(m, true))
- then: target _-send--(m, *args, &block)
- else: super(m, *args, &block)
+ then: target _-send--(m, *args) &block
+ else: super(m, *args) &block
} ensuring:
when($"@"):
$"@" delete-if [t]:
r"\A#{Regexp quote(_FILE)}:#{_LINE - 2}:" =~ t
-with-static-scope(mod, &blk) :=
+with-static-scope(mod) &blk :=
blk block call-under $:
self
Rubinius::StaticScope new $:
2  kernel/particles.ay
View
@@ -21,7 +21,7 @@ module(Atomy):
recv send(@message, *filled)
Particle arity :=
- (@receiver . @arguments) select(&#equal?(_undefined)) size
+ (@receiver . @arguments) select #equal?(_undefined) size
Symbol call(*args) := to-proc [*args]
6 kernel/pretty.ay
View
@@ -11,7 +11,7 @@ pretty-body(x . xs) := [from(#list) { x pretty }] + pretty-body(xs)
_ unamb := pretty
-from(*where, &y) :=
+from(*where) &y :=
let(atomy-pretty-context = where flatten) { y call }
from?(*where) :=
@@ -77,7 +77,7 @@ Atomy::Particle pretty-print := doc:
operator? = @message to-s !~ r"^[a-z_]"
- args = @arguments collect(&#(wildcard [_]))
+ args = @arguments collect #(wildcard [_])
msg+args =
if(operator?)
@@ -235,7 +235,7 @@ module(Atomy::Patterns):
Constant pretty-print := @constant pretty
Default pretty-print := `(~@pattern = ~@default) pretty
HeadTail pretty-print := `(~@head . ~@tail) pretty
- List pretty-print := `[~*(@patterns collect(&#to-node))] pretty
+ List pretty-print := `[~*(@patterns collect #to-node)] pretty
Literal pretty-print := @value pretty
Match pretty-print := @value pretty
Named pretty-print := doc:
6 kernel/therie.ay
View
@@ -12,7 +12,7 @@ class(Stats):
dynamic(stats, nil)
-theorize(&tests) :=
+theorize &tests :=
let(stats = Stats new):
tests call
"\n" display
@@ -31,7 +31,7 @@ theorize(&tests) :=
^stats
-describe(what, &body) := do:
+describe(what) &body := do:
f"- %s" [what] indented println
let(nesting-level = ^nesting-level + 1):
@@ -40,7 +40,7 @@ describe(what, &body) := do:
nil
-it(description, &tests) := do:
+it(description) &tests := do:
{ tests call
f"✓ %s" [description] indented colored(#green) println
} rescue {
16 lib/atomy/ast/block.rb
View
@@ -4,7 +4,7 @@ class Block < Rubinius::AST::Iter
include NodeLike
extend SentientNode
- children [:contents], [:arguments]
+ children [:contents], [:arguments], :block?
generate
def body
@@ -31,6 +31,11 @@ def bytecode(g)
# Push line info down.
pos(blk)
+ if @block
+ blk.push_block_arg
+ @block.to_pattern.deconstruct(blk)
+ end
+
arguments.bytecode(blk)
blk.state.push_block
@@ -88,15 +93,8 @@ def initialize(args)
def bytecode(g)
return if @arguments.empty?
- args = @arguments
-
- if args.last.kind_of?(Patterns::BlockPass)
- g.push_block_arg
- args.pop.deconstruct(g)
- end
-
g.cast_for_splat_block_arg
- args.each do |a|
+ @arguments.each do |a|
if a.kind_of?(Patterns::Splat)
a.pattern.deconstruct(g)
return
13 lib/atomy/ast/call.rb
View
@@ -4,11 +4,22 @@ class Call < Node
generate
def to_send
+ args = @arguments.dup
+ s = @arguments.last
+
+ if s.is_a?(Unary) && s.operator == :*
+ splat = s.receiver
+ args.pop
+ else
+ splat = nil
+ end
+
Send.new(
@line,
Primitive.new(@line, :self),
- @arguments,
+ args,
@name.is_a?(Word) && @name.text,
+ splat,
nil,
true
)
18 lib/atomy/ast/compose.rb
View
@@ -7,11 +7,25 @@ class Compose < Node
def to_send
case @right
when Call
+ @right.to_send.tap do |s|
+ s.receiver = @left
+ end
+ when List
+ args = @right.elements
+ s = args.last
+ if s.is_a?(Unary) && s.operator == :*
+ splat = s.receiver
+ args.pop
+ else
+ splat = nil
+ end
+
Send.new(
@line,
@left,
- @right.arguments,
- @right.name.is_a?(Word) && @right.name.text
+ args,
+ :[],
+ splat
)
else
Send.new(
177 lib/atomy/ast/internal/define.rb
View
@@ -4,93 +4,28 @@ class Define < Node
children :pattern, :body
generate
- def get_arguments(x)
- case x
- when Binary
- [x.rhs]
- when Word, Unary
- []
- when Call
- x.arguments
- when Compose
- case x.right
- when Call
- x.right.arguments
- when Word
- []
- when List
- x.right.elements
- when Compose
- if x.right.right.is_a?(Unary) and x.right.right.operator == "&"
- get_arguments(x.right.left)
- end
- when Unary
- get_arguments(x.left)
- end
- end
- end
-
def arguments
@arguments ||=
get_arguments(@pattern).collect(&:to_pattern) ||
raise("unknown pattern #{@pattern.inspect}")
end
- def get_receiver(x)
- case x
- when Binary
- x.lhs
- when Unary
- x.receiver
- when Call, Word
- Primitive.new(x.line, :self)
- when Compose
- if x.right.is_a?(Unary) and x.right.operator == "&"
- get_receiver(x.left)
- else
- x.left
- end
- end
- end
-
def receiver
@receiver ||=
get_receiver(@pattern).to_pattern ||
raise("unknown pattern #{@pattern.inspect}")
end
- def get_message_name(x)
- case x
- when Word
- x.text
- when Call
- x.name.text
- when Compose
- case x.right
- when Word
- x.right.text
- when Call
- x.right.name.text
- when List
- :[]
- when Compose
- if x.right.right.is_a?(Unary) and x.right.right.operator == "&"
- get_message_name(x.right.left)
- end
- when Unary
- get_message_name(x.left)
- end
- else
- x.message_name
- end
- end
-
def message_name
@message_name ||=
get_message_name(@pattern) ||
raise("unknown pattern #{@pattern.inspect}")
end
+ def block
+ @block ||= get_block(@pattern)
+ end
+
def compile_body(g)
meth = new_generator(g, message_name)
@@ -114,13 +49,15 @@ def compile_body(g)
receiver.deconstruct(meth)
end
+ if block
+ meth.push_block_arg
+ block.deconstruct(meth)
+ end
+
if arguments.size > 0
meth.push_local(0)
arguments.each do |a|
case a
- when Patterns::BlockPass
- meth.push_block_arg
- a.deconstruct(meth)
when Patterns::Splat
meth.dup
a.deconstruct(meth)
@@ -144,7 +81,9 @@ def compile_body(g)
meth.local_names = meth.state.scope.local_names
meth.use_detected
- raise "mismatch: (#{meth.local_names.inspect}, #{meth.local_count})" unless meth.local_names.size == meth.local_count
+ unless meth.local_names.size == meth.local_count
+ raise "locals mismatch: (#{meth.local_names}, #{meth.local_count})"
+ end
meth.pop_state
@@ -155,11 +94,8 @@ def push_method(g)
req = []
dfs = []
spl = nil
- blk = nil
arguments.each do |a|
case a
- when Patterns::BlockPass
- blk = a
when Patterns::Splat
spl = a
when Patterns::Default
@@ -191,8 +127,8 @@ def push_method(g)
g.push_nil
end
- if blk
- blk.construct(g)
+ if block
+ block.construct(g)
else
g.push_nil
end
@@ -237,6 +173,91 @@ def local_names
acc + a.local_names
end
end
+
+ private
+
+ def get_arguments(x)
+ case x
+ when Binary
+ [x.rhs]
+ when Word, Unary
+ []
+ when Call
+ x.arguments
+ when Compose
+ case x.right
+ when Call
+ x.right.arguments
+ when Word
+ []
+ when List
+ x.right.elements
+ when Compose
+ if x.right.right.is_a?(Unary) and x.right.right.operator == :&
+ get_arguments(x.right.left)
+ end
+ when Unary
+ get_arguments(x.left)
+ end
+ end
+ end
+
+ def get_receiver(x)
+ case x
+ when Binary
+ x.lhs
+ when Unary
+ x.receiver
+ when Call, Word
+ Primitive.new(x.line, :self)
+ when Compose
+ if x.right.is_a?(Unary) and x.right.operator == :&
+ get_receiver(x.left)
+ else
+ x.left
+ end
+ end
+ end
+
+ def get_message_name(x)
+ case x
+ when Word
+ x.text
+ when Call
+ x.name.text
+ when Compose
+ case x.right
+ when Word
+ x.right.text
+ when Call
+ x.right.name.text
+ when List
+ :[]
+ when Compose
+ if x.right.right.is_a?(Unary) and x.right.right.operator == :&
+ get_message_name(x.right.left)
+ end
+ when Unary
+ get_message_name(x.left)
+ end
+ else
+ x.message_name
+ end
+ end
+
+ def get_block(x)
+ case x
+ when Compose
+ case x.right
+ when Compose
+ if x.right.right.is_a?(Unary) and x.right.right.operator == :&
+ x.right.right.to_pattern
+ end
+ when Unary
+ x.right.to_pattern
+ end
+ end
+ end
end
end
end
34 lib/atomy/ast/internal/send.rb
View
@@ -1,7 +1,7 @@
module Atomy
module AST
class Send < Node
- children :receiver, [:arguments], :block?
+ children :receiver, [:arguments], :splat?, :block?
attributes :message_name
slots [:private, "false"]
generate
@@ -11,39 +11,25 @@ def bytecode(g)
@receiver.compile(g)
- block = @block
- splat = nil
-
- args = 0
@arguments.each do |a|
- e = a.prepare
- if e.kind_of?(BlockPass)
- block = e
- next
- elsif e.kind_of?(Splat)
- splat = e
- next
- end
-
- e.bytecode(g)
- args += 1
+ a.compile(g)
end
- if splat
- splat.compile(g)
+ if @splat
+ @splat.compile(g)
g.send :to_a, 0
if block
- block.compile(g)
+ @block.compile(g)
else
g.push_nil
end
- g.send_with_splat @message_name, args, @private
- elsif block
- block.compile(g)
- g.send_with_block @message_name, args, @private
+ g.send_with_splat @message_name, @arguments.size, @private
+ elsif @block
+ @block.compile(g)
+ g.send_with_block @message_name, @arguments.size, @private
else
- g.send @message_name, args, @private
+ g.send @message_name, @arguments.size, @private
end
end
end
2  lib/atomy/ast/word.rb
View
@@ -23,7 +23,7 @@ def macro_name
end
def to_send
- Send.new(@line, Primitive.new(@line, :self), [], @text, nil, true)
+ Send.new(@line, Primitive.new(@line, :self), [], @text, nil, nil, true)
end
end
end
58 lib/atomy/atomy.kpeg.rb
View
@@ -584,7 +584,7 @@ def _shebang
self.pos = _save
break
end
- _tmp = scan(/\A(?-mix:.*?$)/)
+ _tmp = scan(/\A(?-mix:.*?$)/u)
unless _tmp
self.pos = _save
end
@@ -753,7 +753,7 @@ def _line
return _tmp
end
- # ident_start = < /[\p{Ll}_]/u > { text }
+ # ident_start = < /[\p{Ll}_]/ > { text }
def _ident_start
_save = self.pos
@@ -779,7 +779,7 @@ def _ident_start
return _tmp
end
- # ident_letter = < (/[\p{L}\d]/u | !":" op_letter) > { text }
+ # ident_letter = < (/[\p{L}\d]/ | !":" op_letter) > { text }
def _ident_letter
_save = self.pos
@@ -833,7 +833,7 @@ def _ident_letter
return _tmp
end
- # op_letter = < /[\p{S}!@#%&*\-\\:.\/\?]/u > { text.to_sym }
+ # op_letter = < /[\p{S}!@#%&*\-\\:.\/\?]/ > { text.to_sym }
def _op_letter
_save = self.pos
@@ -994,7 +994,7 @@ def _comment
_save = self.pos
while true # choice
- _tmp = scan(/\A(?-mix:--.*?$)/)
+ _tmp = scan(/\A(?-mix:--.*?$)/u)
break if _tmp
self.pos = _save
_tmp = apply(:_multi_comment)
@@ -1036,7 +1036,7 @@ def _in_multi
_save1 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[^\-\{\}]*)/)
+ _tmp = scan(/\A(?-mix:[^\-\{\}]*)/u)
unless _tmp
self.pos = _save1
break
@@ -1053,7 +1053,7 @@ def _in_multi
_save2 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[^\-\{\}]*)/)
+ _tmp = scan(/\A(?-mix:[^\-\{\}]*)/u)
unless _tmp
self.pos = _save2
break
@@ -1068,7 +1068,7 @@ def _in_multi
self.pos = _save2
break
end
- _tmp = scan(/\A(?-mix:[^\-\{\}]*)/)
+ _tmp = scan(/\A(?-mix:[^\-\{\}]*)/u)
unless _tmp
self.pos = _save2
break
@@ -1085,12 +1085,12 @@ def _in_multi
_save3 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[^\-\{\}]*)/)
+ _tmp = scan(/\A(?-mix:[^\-\{\}]*)/u)
unless _tmp
self.pos = _save3
break
end
- _tmp = scan(/\A(?-mix:[-{}])/)
+ _tmp = scan(/\A(?-mix:[-{}])/u)
unless _tmp
self.pos = _save3
break
@@ -1450,7 +1450,7 @@ def _number
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[\+\-]?0[oO][0-7]+)/)
+ _tmp = scan(/\A(?-mix:[\+\-]?0[oO][0-7]+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1478,7 +1478,7 @@ def _number
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[\+\-]?0[xX][\da-fA-F]+)/)
+ _tmp = scan(/\A(?-mix:[\+\-]?0[xX][\da-fA-F]+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1506,7 +1506,7 @@ def _number
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[\+\-]?\d+(\.\d+)?[eE][\+\-]?\d+)/)
+ _tmp = scan(/\A(?-mix:[\+\-]?\d+(\.\d+)?[eE][\+\-]?\d+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1534,7 +1534,7 @@ def _number
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[\+\-]?\d+\.\d+)/)
+ _tmp = scan(/\A(?-mix:[\+\-]?\d+\.\d+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1562,7 +1562,7 @@ def _number
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[\+\-]?\d+)/)
+ _tmp = scan(/\A(?-mix:[\+\-]?\d+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1663,7 +1663,7 @@ def _op_assoc
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:left|right)/)
+ _tmp = scan(/\A(?-mix:left|right)/u)
if _tmp
text = get_text(_text_start)
end
@@ -1694,7 +1694,7 @@ def _op_prec
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9]+)/)
+ _tmp = scan(/\A(?-mix:[0-9]+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -2015,7 +2015,7 @@ def _str_seq
_save = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[^\\"]+)/)
+ _tmp = scan(/\A(?-mix:[^\\"]+)/u)
if _tmp
text = get_text(_text_start)
end
@@ -2121,7 +2121,7 @@ def _constant_name
_save = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[A-Z][a-zA-Z0-9_]*)/)
+ _tmp = scan(/\A(?-mix:[A-Z][a-zA-Z0-9_]*)/u)
if _tmp
text = get_text(_text_start)
end
@@ -3749,13 +3749,13 @@ def _number_escapes
_save1 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[xX])/)
+ _tmp = scan(/\A(?-mix:[xX])/u)
unless _tmp
self.pos = _save1
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9a-fA-F]{1,5})/)
+ _tmp = scan(/\A(?-mix:[0-9a-fA-F]{1,5})/u)
if _tmp
text = get_text(_text_start)
end
@@ -3777,7 +3777,7 @@ def _number_escapes
_save2 = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:\d{1,6})/)
+ _tmp = scan(/\A(?-mix:\d{1,6})/u)
if _tmp
text = get_text(_text_start)
end
@@ -3798,13 +3798,13 @@ def _number_escapes
_save3 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[oO])/)
+ _tmp = scan(/\A(?-mix:[oO])/u)
unless _tmp
self.pos = _save3
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-7]{1,7})/)
+ _tmp = scan(/\A(?-mix:[0-7]{1,7})/u)
if _tmp
text = get_text(_text_start)
end
@@ -3825,13 +3825,13 @@ def _number_escapes
_save4 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[uU])/)
+ _tmp = scan(/\A(?-mix:[uU])/u)
unless _tmp
self.pos = _save4
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9a-fA-F]{4})/)
+ _tmp = scan(/\A(?-mix:[0-9a-fA-F]{4})/u)
if _tmp
text = get_text(_text_start)
end
@@ -3915,9 +3915,9 @@ def _root
Rules[:_shebang] = rule_info("shebang", "\"\#!\" /.*?$/")
Rules[:_cont] = rule_info("cont", "((\"\\n\" sp)+ &{ continue?(p) } | sig_sp ((\"\\n\" sp)+ &{ continue?(p) })? | &.)")
Rules[:_line] = rule_info("line", "{ current_line }")
- Rules[:_ident_start] = rule_info("ident_start", "< /[\\p{Ll}_]/u > { text }")
- Rules[:_ident_letter] = rule_info("ident_letter", "< (/[\\p{L}\\d]/u | !\":\" op_letter) > { text }")
- Rules[:_op_letter] = rule_info("op_letter", "< /[\\p{S}!@\#%&*\\-\\\\:.\\/\\?]/u > { text.to_sym }")
+ Rules[:_ident_start] = rule_info("ident_start", "< /[\\p{Ll}_]/ > { text }")
+ Rules[:_ident_letter] = rule_info("ident_letter", "< (/[\\p{L}\\d]/ | !\":\" op_letter) > { text }")
+ Rules[:_op_letter] = rule_info("op_letter", "< /[\\p{S}!@\#%&*\\-\\\\:.\\/\\?]/ > { text.to_sym }")
Rules[:_operator] = rule_info("operator", "< op_letter+ > &{ text !~ /[@:]$/ } { text.to_sym }")
Rules[:_identifier] = rule_info("identifier", "< ident_start ident_letter* > { text.tr(\"-\", \"_\").to_sym }")
Rules[:_grouped] = rule_info("grouped", "\"(\" wsp expression:x wsp \")\" { x }")
12 test/suite/blocks.ay
View
@@ -33,13 +33,13 @@ describe("blocks"):
describe("block"):
it("binds a block argument"):
- [&x] { x call } call { 1 } should-be(1)
+ &x { x call } call { 1 } should-be(1)
it("binds as nil if no block given"):
- [&x] { x } call should-be(nil)
+ &x { x } call should-be(nil)
it("works with arguments before it"):
- [a, &x] { x call(a) } call(2) [a] { a + 1 } should-be(3)
+ [a] &x { x call(a) } call(2) [a] { a + 1 } should-be(3)
it("fails with arguments after it"):
{ [&x, a] { x call(a) } call(2) [a] { a + 1 }
@@ -60,15 +60,15 @@ describe("blocks"):
foo call(1, 2, 3) should-be([1, [2, 3]])
it("appears before a block arg"):
- foo = [a, *bs, &c]: [a, bs, c]
+ foo = [a, *bs] &c: [a, bs, c]
x = {}
{ foo call } should-raise(ArgumentError)
- res = foo call(1, &x)
+ res = foo call(1) &x
res at(0) should-be(1)
res at(1) should-be([])
res at(2) should: kind-of?(Proc)
- res = foo call(1, 2, 3, &x)
+ res = foo call(1, 2, 3) &x
res at(0) should-be(1)
res at(1) should-be([2, 3])
res at(2) should: kind-of?(Proc)
8 test/suite/definitions.ay
View
@@ -39,15 +39,15 @@ describe("definitions"):
0 bar-2(1, 2, 3) should-be([0, 1, [2, 3]])
it("appears before a block arg"):
- baz(a, *bs, &c) := [a, bs, c]
+ baz(a, *bs) &c := [a, bs, c]
x = :;
: baz ; should-raise(ArgumentError)
- res = baz(1, &x)
+ res = baz(1) &x
res at(0) should-be(1)
res at(1) should-be([])
res at(2) should: kind-of?(Proc)
- res = baz(1, 2, 3, &x)
+ res = baz(1, 2, 3) &x
res at(0) should-be(1)
res at(1) should-be([2, 3])
res at(2) should: kind-of?(Proc)
@@ -74,7 +74,7 @@ describe("definitions"):
d4(0, 1) should-be([0, 1])
it("may appear before a block arg"):
- d5(a = 1, &b) := [a, b]
+ d5(a = 1) &b := [a, b]
d5 should-be([1, nil])
d5(2) should-be([2, nil])
12 test/suite/super.ay
View
@@ -3,7 +3,7 @@ class(ZSuperA):
test-2(x) := [#super, x]
test-3 &x := [#super, x call]
test-4(x = 1) := [#super, x]
- test-5(x = 1, &y) := [#super, x, y call]
+ test-5(x = 1) &y := [#super, x, y call]
test-6(x) := [#super, x]
class(ZSuperB < ZSuperA):
@@ -11,7 +11,7 @@ class(ZSuperB < ZSuperA):
test-2(x) := super
test-3 &x := super
test-4(x = 0) := super
- test-5(x = 0, &y) := super
+ test-5(x = 0) &y := super
test-6(x) := { super } call
describe("zsuper"):
@@ -42,7 +42,7 @@ class(SuperA):
test-4 &x := [#super, x call]
test-5(x = 1) := [#super, x]
test-6(x = 1) := [#super, x]
- test-7(x = 1, &y) := [#super, x, y call]
+ test-7(x = 1) &y := [#super, x, y call]
test-8(x) := [#super, x]
class(SuperB < SuperA):
@@ -52,7 +52,7 @@ class(SuperB < SuperA):
test-4 &x := super: x call + 1
test-5(x = 0) := super(x + 1)
test-6(x = 0) := super()
- test-7(x = 0, &y) := super(x + 1, &y)
+ test-7(x = 0) &y := super(x + 1) &y
test-8(x) := do: super(1)
describe("super"):
@@ -68,8 +68,8 @@ describe("super"):
it("passes a &block to the superclass method"):
a = { 1 }
- SuperB new test-3(&a) should-be([#super, 1])
- SuperB new test-4(&a) should-be([#super, 2])
+ SuperB new test-3 &a should-be([#super, 1])
+ SuperB new test-4 &a should-be([#super, 2])
it("sends with the subclass method's defaults"):
SuperB new test-5(2) should-be([#super, 3])
Please sign in to comment.
Something went wrong with that request. Please try again.