Grammars

2015-04-19 Thread mt1957
L.s., I found a small problem when writing a piece of grammar. A simplified part of it is shown here; ... token tag-body { ~ } token body-start { '[' } token body-end { ']' } token body-text { .*? } ... I needed to do something on body-end so I wrote a method for it using an actions c

Re: Grammars

2015-04-20 Thread Larry Wall
On Sun, Apr 19, 2015 at 06:31:30PM +0200, mt1957 wrote: : L.s., : : I found a small problem when writing a piece of grammar. A : simplified part of it is shown here; : ... : token tag-body { ~ } : token body-start { '[' } : token body-end { ']' } : token body-text { .*? } : ... : A coupl

keywords in grammars

2019-12-25 Thread Alt Mcarter
I'm trying to write a toy BASIC to assembler. Here's my code so far: grammar G {     rule TOP    { }     rule stmts  { * }     rule statement  { | | }     rule print-stmt { 'print' }     rule for-loop   { 'for' '=' 'to'   'next' }     rule assign { '

Perl6 grammars -- Parsing english

2012-06-26 Thread Lard Farnwell
Hi guys, To understand and play around with perl6 grammars I was trying to do a simple NLP parts of speech parser in perl6 grammars. This is sort of what I did: --- grammar Sentence{ proto rule VP {*} proto rule NP {*} rule sentence

Re: keywords in grammars

2019-12-26 Thread Brian Duggan
On Wednesday, December 25, Alt Mcarter wrote: > But I'm wondering, is there a way to write token var in such a way that it > matches <[a..z]>+ EXCEPT when it is a keyword (print, for, to, next, etc.)? You could use a negative code assertion -- #!/usr/bin/env raku my @keywords = ; grammar

how to call Grammars correctly?

2008-12-17 Thread Илья
Hi, PM> if the rule is called correctly it appears to work fine: PM> if 'foo' ~~ // So, I try to use that way: grammar G { token TOP { ^ + $ }; token foo { ':' ? }; token bar { \w }; }; ":a:b:c" ~~ //; say $/; say $/; #Use of uninitialized value say $_ for $/; # Use of uninitializ

Re: Perl6 grammars -- Parsing english

2012-06-26 Thread Moritz Lenz
On 06/26/2012 02:04 PM, Lard Farnwell wrote: > Hi guys, > > To understand and play around with perl6 grammars I was trying to do a simple > NLP parts of speech parser in perl6 grammars. This is sort of what I did: > > --- > grammar Sentence{ &g

Re: Perl6 grammars -- Parsing english

2012-07-04 Thread Lard Farnwell
Hi Moritz, Thanks that was interesting. My investigation into grammars took a while but here are the results thus far: > Grammar rules and regexes are just methods… I hadn't thought about what a grammar and rule actually was before. This inspired m

Re: Perl6 grammars -- Parsing english

2012-07-11 Thread Moritz Lenz
Hi Lard, sorry for the late and incomplete answer. Am 04.07.2012 15:09, schrieb Lard Farnwell: Hi Moritz, Thanks that was interesting. My investigation into grammars took a while but here are the results thus far: Grammar rules and regexes are just methods… I hadn't thought about w

Grammars and biological data formats

2014-08-09 Thread Fields, Christopher J
(accidentally sent to perl6-lang, apologies for cross-posting but this seems more appropriate) I have a fairly simple question regarding the feasibility of using grammars with commonly used biological data formats. My main question: if I wanted to parse() or subparse() vary large files (not

grammars and indentation of input

2016-09-13 Thread Theo van den Heuvel
Hi all, I am beginning to appreciate the power of grammars and the Match class. This is truly a major asset within Perl6. I have a question on an edge case. I was hoping to use a grammar for an input that has meaningful indented blocks. I was trying something like this: token element

Parsing with Regexes and Grammars

2018-08-01 Thread Theo van den Heuvel
@Moritz Dear Moritz, I am using your book and have some remarks on it that I hope you find useful. It appears the address you are using here is send-only. The content of the book is good, but there are some problems with the publishing process. E.g. the first couple of pages are missing com

Re: how to call Grammars correctly?

2008-12-18 Thread Vasily Chekalkin
Илья wrote: Hi, PM> if the rule is called correctly it appears to work fine: PM> if 'foo' ~~ // So, I try to use that way: grammar G { token TOP { ^ + $ }; token foo { ':' ? }; token bar { \w }; }; ":a:b:c" ~~ //; say $/; say $/; #Use of uninitialized value say $_ for $/; # Use

Re: how to call Grammars correctly?

2008-12-18 Thread Moritz Lenz
Vasily Chekalkin wrote: > Илья wrote: >> Hi, >> >> PM> if the rule is called correctly it appears to work fine: >> >> PM> if 'foo' ~~ // >> >> So, I try to use that way: >> >> grammar G { >> token TOP { ^ + $ }; >> token foo { ':' ? }; >> token bar { \w }; >> }; >> >> ":a:b:c" ~~ /

Re: how to call Grammars correctly?

2008-12-18 Thread Andy_Bach
>> So, I try to use that way: >> >> grammar G { >> token TOP { ^ + $ }; >> token foo { ':' ? }; >> token bar { \w }; >> }; >> >> ":a:b:c" ~~ //; >> >> say $/; >> say $/; #Use of uninitialized value >> say $_ for $/; # Use of uninitialized value > > Try $/ Or even $/ (haven't tried it,

Re: Grammars and biological data formats

2014-08-09 Thread timo
(accidentally sent this privately only, now re-sending to the list) Hello Christopher, In the Perl 6 specification, there are plans for lazy and memory-releasing ways to parse strings that are either too large to fit into memory at once or that are generated lazily (like being streamed in through

Re: Grammars and biological data formats

2014-08-09 Thread timo
On 08/10/2014 12:21 AM, t...@wakelift.de wrote: > Something that does surprise me is that your tests seem to imply that :p > for subparse doesn't work. I'll look into that, because I believe it > ought to be implemented already. Perhaps not properly hooked up, though. On #perl6 I got corrected qu

Re: Grammars and biological data formats

2014-08-09 Thread Darren Duncan
I've already been thinking for awhile now that parsers need to be able to operate in a streaming fashion (when the grammars lend themselves to it, by not needing to lookahead, much if at all, to understand what they've already seen) so that strings that don't fit in memory all

Re: Grammars and biological data formats

2014-08-09 Thread Fields, Christopher J
> On Aug 9, 2014, at 5:25 PM, "t...@wakelift.de" wrote: > > >> On 08/10/2014 12:21 AM, t...@wakelift.de wrote: >> Something that does surprise me is that your tests seem to imply that :p >> for subparse doesn't work. I'll look into that, because I believe it >> ought to be implemented already.

Re: Grammars and biological data formats

2014-08-09 Thread Fields, Christopher J
On Aug 9, 2014, at 8:51 PM, "Fields, Christopher J" wrote: > > >> On Aug 9, 2014, at 5:25 PM, "t...@wakelift.de" wrote: >> >> >>> On 08/10/2014 12:21 AM, t...@wakelift.de wrote: >>> Something that does surprise me is that your tests seem to imply that :p >>> for subparse doesn't work. I'll l

Re: grammars and indentation of input

2016-09-13 Thread Timo Paulssen
I haven't read your code, but your question immediately made me think of this module: https://github.com/masak/text-indented Would be interested to hear if this helps you! - Timo

Re: grammars and indentation of input

2016-09-13 Thread Brian Duggan
I've also recently been experimenting with parsing an indent-based language -- specifically, a small subset of Slim () -- I push to a stack when I see a tag, and pop based on the depth of the indendation. Here's a working example: https://git.io/vig93 Brian

Re: grammars and indentation of input

2016-09-13 Thread Aaron Sherman
, Sep 13, 2016 at 7:13 AM, Theo van den Heuvel wrote: > Hi all, > > I am beginning to appreciate the power of grammars and the Match class. > This is truly a major asset within Perl6. > > I have a question on an edge case. I was hoping to use a grammar for an > input that has

Re: grammars and indentation of input

2016-09-13 Thread Patrick R. Michaud
I don't have an example handy, but I can categorically say that Perl 6 grammars are designed to support exactly this form of parsing. It's almost exactly what I did in "pynie" -- a Python implementation on top of Perl 6. The parsing was done using a Perl 6 grammar. If I remem

Re: grammars and indentation of input

2016-09-13 Thread Moritz Lenz
Hi, On 13.09.2016 18:55, Patrick R. Michaud wrote: > I don't have an example handy, but I can categorically say that > Perl 6 grammars are designed to support exactly this form of parsing. > It's almost exactly what I did in "pynie" -- a Python implementation > on

Re: grammars and indentation of input

2016-09-13 Thread Theo van den Heuvel
As so often it turned out that the reason my program did not work was elsewhere (in the grammar). My approach worked al along. It was instructive to look at the examples you guys mentioned. Thanks Theo

generating grammars, capturing in regex interpolation, etc.

2015-04-14 Thread Nathan Gray
I've been playing in Perl 6 (after several years of absence). I am very impressed. I'm porting my recent Date::Reformat into Perl 6, for fun, to get me back into the Perl 6 headspace, and possibly to help others, either with something useful, or something they can look to for examples. I've run

Fwd: Re: grammars and indentation of input

2016-09-13 Thread Theo van den Heuvel
Thanks Timo and Brian, both examples are educational. However, they have a common limitation in that they both perform their magic after a Match object has been created. I was trying to influence the parsing step itself. I am experimenting to find if I can influence the parsing process progr

Re: generating grammars, capturing in regex interpolation, etc.

2015-04-14 Thread Patrick R. Michaud
On Tue, Apr 14, 2015 at 08:58:27PM -0400, Nathan Gray wrote: > I've run into a snag, in that my strptime processing in Perl 5 > relies on building a string that looks like a regex with named > captures, and then interpolating that into a real regex. >[...] > my $pattern = Q/$=[hello]/; > my

Re: generating grammars, capturing in regex interpolation, etc.

2015-04-15 Thread Nathan Gray
On Tue, Apr 14, 2015 at 08:58:29PM -0500, Patrick R. Michaud wrote: > Just an idea: instead of building strings to be interpolated into > a regex, could you just build regexes directly? > > my $pattern = rx/$=[hello]/; > my $match = "hello" ~~ / /; > > The resulting string is captured i

Re: generating grammars, capturing in regex interpolation, etc.

2015-04-16 Thread Nathan Gray
On Wed, Apr 15, 2015 at 09:45:39PM -0400, Nathan Gray wrote: > I had given up on using regexes embedded within regexes, because > I could not get capturing to work. I did a backtrace on one of the test cases that fails, which led me to src/core/Cursor.pm in method INTERPOLATE(\var, $i = 0,

Re: generating grammars, capturing in regex interpolation, etc.

2015-04-17 Thread Tobias Leich
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 The comment in INTERPOLATE is about "subcaptures"... but if you do not capture the interpolated regex itself, you break that chain. Am 17.04.2015 um 04:34 schrieb Nathan Gray: > On Wed, Apr 15, 2015 at 09:45:39PM -0400, Nathan Gray wrote: >> I had g

Re: generating grammars, capturing in regex interpolation, etc.

2015-04-20 Thread Nathan Gray
> Am 17.04.2015 um 04:34 schrieb Nathan Gray: > > # Call it if it is a routine. This will capture if requested. > > return (var)(self) if nqp::istype(var,Callable); > > > > This seems to indicate that captures in the embedded regexes > > should capture. On Fri, Apr 17, 2015 at 09:47:22AM +0200

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Bennett Todd
Having the minutia of the programmatic run-time state of the parse then influence the parse itself, is at the heart of the perl5 phenomenon "only Perl can parse perl", which I rather hope isn't going to be preserved in perl6.

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Theo van den Heuvel
Hi Bennett, There are many situations that require non-contextfree languages. Even though much of these could be solved in the AST-building step (called 'transduction' in my days) instead of the parsing step, that does not solve all cases. I am just wondering if and to what extent we can parse

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Patrick R. Michaud
On Tue, Sep 13, 2016 at 10:35:01AM -0400, Bennett Todd wrote: > Having the minutia of the programmatic run-time state of the parse then > influence the parse itself, is at the heart of the perl5 phenomenon "only > Perl can parse perl", which I rather hope isn't going to be preserved in > perl6.

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Aaron Sherman
> > Having the minutia of the programmatic run-time state of the parse then > influence the parse itself, is at the heart of the perl5 phenomenon "only > Perl can parse perl" I don't mean to be hostile, but you're demonstrably wrong, here. (also it's "only perl can parse Perl" as in, only the "pe

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Bennett Todd
Thank you, very much. Yes, I'm disappointed, but I'd rather know.

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Bennett Todd
Hostile or not, thanks for your informative reply.

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Aaron Sherman
Oh, a side point: there's some confusion introduced by the lack of a scanner/lexer in modern all-in-one-parsers. Python, for example, uses a scanner and so its grammar is nominally not context sensitive, but its scanner very much is (maintaining a stack of indentation exactly as OP was asking abou

Re: Fwd: Re: grammars and indentation of input

2016-09-13 Thread Bennett Todd
Well put. The clearest description of Python's approach I've read, explained it as a lexer that tracked indentation level, and inserted appropriate tokens when it changed.

Grammars: parse tags of which only some need closing tags

2010-08-28 Thread Moritz Lenz
. Some of them stand on their own, like [% setvar title Grammars: parse tags of which only some ... %] And others have opening/closing pairs, and their proper nesting needs to be enforced, for example [% ifvar title %] [% readvar title %] [% endifvar %] (yes, the syntax is horrible, but when

"rule" declarator: Different results for 'unadorned' match vs unnamed/named captures? (in re Grammars...).

2021-03-11 Thread William Michels via perl6-users
Hello, I've been chatting with raiph on SO regarding Grammar "tokens" vs "rules". The OP is here https://stackoverflow.com/q/62051742 and our discussion is here https://stackoverflow.com/a/62053666 . I think there's something going on with the examples below, as I'm seeing different results when

Re: "rule" declarator: Different results for 'unadorned' match vs unnamed/named captures? (in re Grammars...).

2021-03-12 Thread Ralph Mellor
On Thu, Mar 11, 2021 at 8:53 PM William Michels wrote: > > I think there's something going on with the examples below, as I'm > seeing different results when comparing a basic "rule" match vs either > unnamed or named "rule" captures. All your examples are correct according to my current understa