perl6 / std Goto Github PK
View Code? Open in Web Editor NEW(ARCHIVE) Raku standard grammar
Home Page: https://raku.org/
(ARCHIVE) Raku standard grammar
Home Page: https://raku.org/
=head1 Perl 6 Parser Stuff in the Pugs Repo Welcome to pugs/src/perl6. This is the home of STD.pm6, the canonical Perl 6 grammar, which is written in Perl 6 (of course). It is also the home of viv, a retargettable Perl 6 metacompiler which can translate STD.pm6 into Perl 5 (and eventually other things). The metacompiler relies on STD.pm6 to parse itself, requiring a stored bootstrap version of the compiled STD.pm. This is also the home of Cursor, the canonical implementation of the Perl 6 rules engine; it co-evolves with viv and executes the actual rules. This is also the home of a collection of minor tools used in the development of STD.pm6 and viv. =head1 Prerequisites You'll need the following Perl bits to run stuff: * Perl 5.10.0 or later in PATH * YAML::XS (e.g. sudo apt-get install libyaml-libyaml-perl) * Moose (e.g. sudo apt-get install libmoose-perl) * File::ShareDir =head1 Running Stuff You can get started by using the Makefile command, C<make>. This will convert the Perl 6 grammar into a Perl 5 module, C<STD>. C<STD> has a fairly simple API; just call C<parse> as a class method with the source you want to parse as a parameter, and look at the result. Another module, C<Actions>, is provided which converts C<STD>'s output into a more object-oriented form; see C<viv>'s source for an example of the latter's use. (Both methods have more options when you need them.) The following tools are provided which leverage the power of C<STD>: * C<tryfile> parses a file of Perl 6 code and reports 'ok' or 'FAILED', plus the time taken and memory used. * C<std> does the same, but also tests Actions. * C<redspans> parses a file, reporting what rules matched which tokens. * C<reds> appears to be an older, non-working version of redspans. * C<teststd> uses STD to check the syntax of the Perl 6 Specification Tests. * C<tloop> is an interactive STD syntax checker. * C<vill> is a prototype STD-based LLVM-based Perl 6 JIT compiler. * C<viv> is a retargettable metacompiler for the static subset of Perl 6. * C<std_hilite/STD_syntax_highlight> is a syntax highlighter with multiple output formats. See the headers of the respective programs for more details, and don't hesitate to ask around as quite a bit of this is underdocumented. =head1 Working the Makefile To regenerate perl 5 files from perl 6 STD.pm6, STD_P5.pm6, and Cursor.pm6 changes: make To do that, but without running the self test (bootstrap): make fast To remake only one file: make STD.pmc To update the first stage, allowing new STD.pm6 or Cursor.pm6 features to be used while building future versions of STD.pm6 or Cursor.pm6: make reboot To remove all generated files: make clean To test the ability to parse the Perl 6 test suite (this is a very effective regression test, but B<slow> - 20-75 minutes; also, it runs in a snapshot of the current directory, so you can continue hacking): make snaptest
In the following example rather common $|++
idiom makes "Bogus statement" error. I think it should report "Unsupported use of" error instead.
glitchmr@strawberry ~/g/std> echo '$|' | ./viv -
===SORRY!===
Unsupported use of $| variable; in Perl 6 please use :autoflush on open at (eval) line 1:
------> $|⏏<EOL>
Parse failed
glitchmr@strawberry ~/g/std> echo '$|++' | ./viv -
===SORRY!===
Bogus statement at (eval) line 1:
------> <BOL>⏏$|++
Parse failed
std thinks that 3 !=3 is about assigning the negated three instead of a comparision.
See: https://rt.perl.org/Ticket/Update.html?id=121108
./viv -e 'say 1 != 3'
[...]
└─VAST::SYM_infix__S_BangEqual, BEG: 6, END: 8, SYM: !=,
TEXT: !=, WS: 1, _from: 8, _op: VAST::infix__S_BangEqual,
_pos: 8, _specific: 1, assoc: chain, dba: chaining,
diffy: 1, iffy: 1, prec: m=, pure: 1
[...]
./viv -e 'say 1 !=3'
[...]
└─VAST::SYM_infix__S_Equal, BEG: 7, END: 8, SYM: =, TEXT: =,
_from: 8, _op: VAST::infix__S_Equal, _pos: 8,
_specific: 1, assoc: right, dba: list assignment,
fiddly: 1, prec: i=, pure: 0
[...]
On a fresh Ubuntu 14.04.1 box with perl 5.18.2, STD's make snap
errors out:
Compiled lib/Stash.pm6
Compiled ./CursorBase.pm6
Compiled ./Cursor.pm6
===SORRY!===
Preceding context expects a term, but found infix = instead at STD.pm6 line 2787:
------> $*CURLEX.<$?SIGNATURE> ~⏏= '(' ~ substr(self.orig, $startpos, $¢.
Parse failed
make: *** [STD.pmc] Error 2
The build also produces lots of warnings about given
/when
being deprecated (but they don't stop the build from happening).
When I feed this program to STD:
do { } for 1;
I get the response
Unsupported use of do...for; in Perl 6 please use repeat...for at
But feeding
repeat { } for 1;
into STD gives
Undeclared routine: 'repeat'
So one way or another, std is inconsistent.
<masak> std: repeat { say "OH HAI" }
<p6eval> std f43a358: OUTPUT«===SORRY!===Undeclared routine: 'repeat' used at line 1
Check failedFAILED 00:00 41m»
<jnthn> I think the parser is gonna need to commit after seeing repeat, fwiw
* masak submits stdbug
By current spec,
+Order::Decrease == 1
+Order::Same == 0
+Order::Increase == -1
Not only does this numification run counter to popular interpretations of "Increase" and "Decrease", but also requires a different interpretation:
say 5 cmp 7
OUTPUT: Increase
(From the LHS, you must increase to get to the RHS)
say +(5 cmp 7)
OUTPUT: -1
(From the RHS, you must go down (subtract/add negative) to get to the LHS)
I don't know about you, but this weird numification of words in addition to the differing interpretation between the object and its numification is broken. I recommend Decrease == -1 and Increase == 1.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.