Re: [perl #129311] Simple Grammar Goes into infinite loop

2016-09-21 Thread Andrew Buchanan
Ok, that clarifies things. Now that I understand what is happening, it is 
straightforward to recognise and fix the problem. A sentence in the 
documentation might help other perl 5 transitioners from getting bitten, 
perhaps at the explanation of the * quantifier. 




> On 21 Sep 2016, at 6:35 PM, Sam S. via RT  
> wrote:
> 
> For the record the problems the auto-advance feature causes even in Perl 5 
> (where embedded code blocks are experimental and rarely used), are twofold:
> 
> 1) Writing an infinite loop can be indicative of a programmer mistake, and 
> the auto-advance feature hides it by making the regex "do something" (which 
> may or may not be what the programmer intended) instead of hanging (which 
> would have caused the programmer to re-write the regex).
> 
> 2) It can cause mysterious-seeming double captures. When there is a capture 
> group in a quantified zero-width assertion, it will capture the same thing 
> twice, because auto-advance kicks in when the cursor has not advanced after 
> *two* iterations. Now, Perl 5 lets repeated captures of the same capture 
> group overwrite each other, so this does not normally show up other than as a 
> performance degradation (whereas in Perl 6 it would cause the same 
> sub-matches to appear twice  in $/). But it can show up in even Perl 5 with 
> `while(m//g) { }` global matching. I remember a discussion on perlmonks a few 
> years ago, where even experienced Perl hackers were tearing their hair out 
> trying to figure out why such a while loop iterated over the same match twice.



Re: [perl #129311] Simple Grammar Goes into infinite loop

2016-09-20 Thread Andrew Buchanan
Is this also technically correct, even though it clearly shouldn't match?

perl6 -e '"foo" ~~ /(.*)+\:/'  # hangs

In either case, going into an infinite loop is not exactly DWIM. 


> On 20 Sep 2016, at 9:12 PM, Will Coleda via RT  
> wrote:
> 
> On Tue Sep 20 06:06:59 2016, c...@zoffix.com wrote:
>> Here's a much shorter way to reproduce it:
>> 
>> perl6 -e '"foo" ~~ /(.*)+/'  # hangs
>> 
>> While my previous explanation for why this occurs makes sense, it's
>> worth noting this behaviour is not observed in Perl 5, for example:
>> 
>> perl -e '"foo" =~ /(.*)+/'  # does not hang
> 
> This sounds like a dupe of #75586
> 
> -- 
> Will "Coke" Coleda



[perl #129311] Simple Grammar Goes into infinite loop

2016-09-20 Thread via RT
# New Ticket Created by  Andrew Buchanan 
# Please include the string:  [perl #129311]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=129311 >


This is a simple two-regex grammar. It is as if the ‘?’ modifier is set on the 
wildcards, and matching nothing doesn’t stop the parser.
--
Andrew Buchanan
tomentiru...@gmail.com 





This is a simple two-regex grammar. It is as if the ‘?’ modifier is set on the wildcards, and matching nothing doesn’t stop the parser.
--Andrew Buchanantomentiru...@gmail.com

use v6;

# This Grammar goes into an infinite loop
grammar G {
regex Body { + }
# With this, only one character is chosen at a time, except when there 
is a \v
regex Text { \V*: % \v+ }
# With this, the input is found, and then it goes into an infinite loop
#regex Text { \V* }
# This works
# regex Text { \V+ }
}
class A {
method FALLBACK($fn, $match) {
say "<$fn> matched '$match'";
}
}

my $g = G.new;
my $actions = A.new;
my $rule = 'Body';
say "Calling parse";
$g.parse("Line 1", :$rule, :$actions);

=finish
moar::dcbrule=@:
moar::ar=ar
moar::mastdir=/Users/andrewbuchanan/.rakudobrew/moar-nom/install/share/nqp/lib/MAST
moar::tomrule=$(AR) $(ARFLAGS) $@ 3rdparty/libtommath/*.o
moar::shaobjects=3rdparty/sha1/sha1.o
moar::ccshared=
moar::be=0
moar::dynasmlua=./3rdparty/dynasm/dynasm.lua
moar::ld=clang
moar::mtlib=3rdparty/tinymt/libtinymt.a
moar::mtobjects=3rdparty/tinymt/tinymt64.o
moar::noreturnspecifier=
moar::perl=perl
moar::shaclean=$(RM) 3rdparty/sha1/libsha1.a 3rdparty/sha1/*.o
moar::static_inline=static __inline__
moar::ccdebugflags=-g3
moar::auxclean=@:
moar::thirdpartylibs=3rdparty/dyncall/dyncall/libdyncall_s.a 
3rdparty/dyncall/dyncallback/libdyncallback_s.a 
3rdparty/dyncall/dynload/libdynload_s.a 
3rdparty/libatomic_ops/src/libatomic_ops.a 3rdparty/tinymt/libtinymt.a 
3rdparty/sha1/libsha1.a 3rdparty/libtommath/libtommath.a 3rdparty/libuv/libuv.a
moar::config=--optimize 
--prefix=/Users/andrewbuchanan/.rakudobrew/moar-nom/install --make-install
moar::ccinc=-I
moar::booltype=_Bool
moar::ldout=-o
moar::moarlib=libmoar.a
moar::mtrule=$(AR) $(ARFLAGS) $@ 3rdparty/tinymt/*.o
moar::dcrule=cd 3rdparty/dyncall &&  ./configure && CC='$(CC)' 
CFLAGS='$(CFLAGS)' $(MAKE) -f Makefile
moar::dcbobjects=
moar::cflags=-fno-omit-frame-pointer -fno-optimize-sibling-calls -O3 -DNDEBUG 
-Wno-logical-op-parentheses -D_DARWIN_USE_64_BIT_INODE=1
moar::laolib=3rdparty/libatomic_ops/src/libatomic_ops.a
moar::libdir=/Users/andrewbuchanan/.rakudobrew/moar-nom/install/lib
moar::nul=/dev/null
moar::osvers=15.0
moar::translate_newline_output=0
moar::dlrule=@:
moar::cat=cat
moar::can_unaligned_int32=1
moar::ldimp=
moar::pkgconfig=/usr/bin/pkg-config
moar::ccdef=-D
moar::lib=lib%s.a
moar::tomclean=$(RM) 3rdparty/libtommath/libtommath.a 3rdparty/libtommath/*.o
moar::dlllocal=__attribute__ ((visibility ("hidden")))
moar::dcbclean=$(RM) 3rdparty/dyncall/dyncallback/libdyncallback_s.a
moar::noreturnattribute=__attribute__((noreturn))
moar::ptr_size=8
moar::dllimport=__attribute__ ((visibility ("default")))
moar::ccout=-o
moar::can_unaligned_num64=1
moar::has_pthread_yield=0
moar::ldrpath=-Wl,-rpath,"//Users/andrewbuchanan/.rakudobrew/moar-nom/install/lib"
 
-Wl,-rpath,"/Users/andrewbuchanan/.rakudobrew/moar-nom/install/share/perl6/site/lib"
moar::ldusr=-l%s
moar::mainflags=-DMVM_SHARED
moar::name=moar
moar::dll=lib%s.dylib
moar::cincludes= -I3rdparty/libuv/include -I3rdparty/libuv/src 
-I3rdparty/libatomic_ops/src -I3rdparty/libtommath -I3rdparty/dynasm 
-I3rdparty/dyncall/dynload -I3rdparty/dyncall/dyncall 
-I3rdparty/dyncall/dyncallback
moar::uvrule=$(AR) $(ARFLAGS) $@ $(UV_DARWIN)
moar::tomlib=3rdparty/libtommath/libtommath.a
moar::staticlib=
moar::dlclean=$(RM) 3rdparty/dyncall/dynload/libdynload_s.a
moar::make=make
moar::ccinstflags=-fsanitize=address
moar::ldflags= -O3 -DNDEBUG 
-Wl,-rpath,"//Users/andrewbuchanan/.rakudobrew/moar-nom/install/lib" 
-Wl,-rpath,"/Users/andrewbuchanan/.rakudobrew/moar-nom/install/share/perl6/site/lib"
moar::crossconf=
moar::obj=.o
moar::usrlibs[0]=pthread
moar::dlobjects=
moar::defs[0]=_DARWIN_USE_64_BIT_INODE=1
moar::cppout=>
moar::ccoptiflags=-O3 -DNDEBUG
moar::asmswitch=-S
moar::ldoptiflags=-O3 -DNDEBUG
moar::mkflags=
moar::moar=libmoar.dylib
moar::version=2016.09
moar::dcclean=cd 3rdparty/dyncall && $(MAKE) -f Makefile clean
moar::moarshared=-install_name 
"/Users/andrewbuchanan/.rakudobrew/moar-nom/install/lib/libmoar.dylib"
moar::sharule=$(AR) $(ARFLAGS) $@ 3rdparty/sha1/*.o
moar::ccwarnflags=-Wno-logical-op-parentheses
moar::jit=$(JIT_POSIX_X64)
moar::moardll=libmoar.dylib
moar::asm=.s
moar::mknoisy=ifneq ($(NOISY), 1)MSG = @echoCMD = @NOOUT = > /dev/nullNOERR = 
2> /dev/nullendif
moar::dclib=3rdparty/dyncall/dyncall/libdyncall_s.a
moar::ccdefflags=-D_DARWIN_USE_64_BIT_INODE=1
moar::cc=clang
moar::exe=
moar::

[perl #129311] Simple Grammar Goes into infinite loop

2016-09-20 Thread Zoffix Znet via RT
Here's a much shorter way to reproduce it:

perl6 -e '"foo" ~~ /(.*)+/'  # hangs

While my previous explanation for why this occurs makes sense, it's worth 
noting this behaviour is not observed in Perl 5, for example:

perl -e '"foo" =~ /(.*)+/'  # does not hang


[perl #129311] Simple Grammar Goes into infinite loop

2016-09-20 Thread Zoffix Znet via RT
I'm not seeing the bug here, to be honest.

The `Body` is asking for one or more tokens `Text`, *nothing* is a valid match 
for those tokens, so after matching the provided text, your grammar continues 
to match nothing infinite number of times.