Re: Grammar Help

2021-12-26 Thread Paul Procacci
Hey all,

Firstly, I want to thank everyone for all their responses.  It helped
greatly.

I wanted to share what I ended up with that seems to be working. (below)
I'm open to suggestions on how to improve this, tidy things up a bit, etc.

Running on the below grammar yields the following what to me seems perfect:

% raku ./test2.raku < test.data
{objectKey => {a => 1234, anotherObjectKey => {b => "45934"}, b => 5345,
newobjectKey => {a => 1534, b => "asdf"}}}

Thanks all for taking the time to respond.
~Paul


 data 
objectKey:
{
a = 1234;
b = 5345;

newobjectKey:
{
a = 1534;
b = "asdf";
}

anotherObjectKey:
{
b = "45934";
}
}
 end data 


- logic -
grammar Test {

rule TOP{  }
rule object {   }
rule objectKey  {  ':'   }
rule objectBody { '{' ~ '}' +}
rule pair   {  '='  ';'   }
token cstr  { + }
token number{ <[0..9]>+}
token string{ '"' ~ '"' <-["]>+}

proto token item{ * };
  token item:sym{  }
  token item:sym  {  }

proto token value   { * };
  token value:sym   {  }
  token value:sym   {  }
}

class TestActions {

method TOP($/) { make $.made; }
method object($/) { make $.made => $.made; }
method objectBody($/) { make $>>.made.hash.item; }
method pair($/) { make $.made => $.made; }
method objectKey($/) { make $.made; }
method cstr($/)  { make ~$/; }
method string($/){ make ~$/; }
method number($/){ make ~$/; }

method item:sym($/){ make $.made; }
method item:sym($/)  { make $.made; }
method value:sym($/) { make ~$/; }
method value:sym($/) { make ~$/; }
}
- end logic -

On Sun, Dec 26, 2021 at 1:01 AM Paul Procacci  wrote:

> Hey all,
>
> Twas the night of Christmas, when all through the house, not a creature
> was stirring except Paul w/ his mouse.
>
> Hope everyone had a Merry Christmas and takes likings to corny opening
> statements.  ;)
>
> I was writing a little something tonight using Grammars and ran into
> something that I can't seem to wrap my head around.  I'm hoping someone
> could explain in detail.
>
> Given the following data:
>  data -
> objectKey:
> {
> a = "bi";
> b = "hi";
> }
>  end data -
>
>
>  and the following logic partially taken from JSON::Tiny:
>
>  code 
> grammar myTest {
> token TOP{ \s*  \s* }
> rule  object {  '{'  '}' }
> # rule  object {  '{' ~ '}'  }
> rule  objectKey  {  ':' }
> rule  pairlist   {  * % \; }
> rule  pair   {  '='  }
> token cstr   { + }
> token value  { '"' ~ '"' * }
> }
>
> class myTestActions {
> method TOP($/) {
> make $.made.hash.item;
> }
>
> method object($/) {
> say 'hello';
> }
>
> method objectKey($/) {
> make $.made;
> }l
> method pairlist($/) {
> make $>>.made.flat;
> }
>
> method pair($/) {
> make $.made => $.made;
> }
>
> method cstr($/)  { make ~$/ }
> method value($/) { make ~$/ }
> }
>  code 
>
>
> ... it'd be my hopes that this would match.  However, It's not matching on
> 'object' and I can't seem to figure out why.
>
> Adding Grammar::Tracer yields the following:
>
> TOP
> |  object
> |  |  objectKey
> |  |  |  cstr
> |  |  |  * MATCH "objectKey"
> |  |  * MATCH "objectKey:\n"
> |  |  pairlist
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "a"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"bi\""
> |  |  |  * MATCH "a = \"bi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "b"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"hi\""
> |  |  |  * MATCH "b = \"hi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * FAIL
> |  |  |  * FAIL
> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
> |  * FAIL
> * FAIL
>
> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect here?
> Appreciate any insight.
>
> Thanks,
> Paul
> --
> __
>
> :(){ :|:& };:
>


-- 
__

:(){ :|:& };:


Re: Grammar Help

2021-12-26 Thread Paul Procacci
Hey Ralph,

I don't use Comma.  I'm not a fan of IDE's and generally stick to vi for
all my needs.  Old habits are hard to break especially once you've been
using the same tool for ~25 years like I have.  ;(
I've been switching back and forth between:

use Grammar::Tracer;

and

use Grammar::Tracer::Compact;

Both I've found helpful, though obviously not fool proof.  It'd be nice if
it show'd why it failed (i.e. what it encountered vs what it expected )
rather than just a 'failed'.
The difference was partly my fault for not even considering the differences
between '%' and '%%'.  It was a fork lift from JSON::Tiny and it's one
change I overlooked entirely.

As an aside, I'm coming back to raku after a year hiatus in hopes that the
support for FreeBSD has improved and to some degree, have to reteach myself
the little tidbits I've forgotten.
Ultimately, I'm looking to parse the following using Grammars:

 data -
objectKey:
{
a = "bi";
b = "hi";
newObjectKey:
{
 a = "go";
}
   anotherObjectKey:
   {
a = 'ho';
   }
  c = "no";
}


... and naturally with a Match object that represents this as a
hierarchical hash structure containing all the elements.
The differences between this and JSON are close enough that I thought a
mere copy/paste from JSON::Tiny w/ just enough changes to account for the
differences would be enough, but they are in fact different enough that
this was an oversight.

At least I learned a bit in the process.

Thanks,
Paul

On Sun, Dec 26, 2021 at 5:37 PM Ralph Mellor 
wrote:

> On Sun, Dec 26, 2021 at 6:01 AM Paul Procacci  wrote:
> >
> > Hope everyone had a Merry Christmas and takes likings to corny opening
> statements.  ;)
>
> I love me some corn but it's especially appropriate to share some
> in winter if you've got hungry mice. :)
>
> As others have noted, you need `%%` instead of `%`.
>
> Grammar::Tracer isn't always intuitive. Have you tried CommaIDE's
> Grammar Live View? https://commaide.com/docs/grammar-live-view
>
> I wonder if you would have immediately known what the problem was
> with the latter or if the problem was just that you were thinking `%` did
> what `%%` does?
>
> --
> love, raiph
>


-- 
__

:(){ :|:& };:


Re: Greeting Larry Wall: I will learn to love you new language.

2021-12-26 Thread Ralph Mellor
On Sat, Dec 25, 2021 at 4:31 PM Maneesh Sud via perl6-users
 wrote:
>
> Merry Christmas and a Happy New Year.

Hi. Happy holidays to you too.

> Does perl6 or moarvm run on risc-v 32-bit processors.

I think a key piece is dyncall/libffi support. Googling suggests
dyncall doesn't support risc-v but libffi does. But I really don't
know much about such things.

I recommend you focus on the IRC channel #moarvm rather
than this mailing list for more info/discussion of such matters.
The channel is publicly logged and searchable. My search for
`risc` draws a blank:
https://logs.liz.nl/search.html?query=risc=words==moarvm;
message-type==2013-11-04=2021-12-26

I suggest you log on there and ask. Here's a web client link:
https://kiwiirc.com/nextclient/irc.libera.chat/#moarvm

Good luck and happy holidays!

--
love, raiph


Re: Grammar Help

2021-12-26 Thread Ralph Mellor
On Sun, Dec 26, 2021 at 6:01 AM Paul Procacci  wrote:
>
> Hope everyone had a Merry Christmas and takes likings to corny opening 
> statements.  ;)

I love me some corn but it's especially appropriate to share some
in winter if you've got hungry mice. :)

As others have noted, you need `%%` instead of `%`.

Grammar::Tracer isn't always intuitive. Have you tried CommaIDE's
Grammar Live View? https://commaide.com/docs/grammar-live-view

I wonder if you would have immediately known what the problem was
with the latter or if the problem was just that you were thinking `%` did
what `%%` does?

--
love, raiph


Re: Grammar Help

2021-12-26 Thread William Michels via perl6-users
Hi Paul,

Quick check yesterday you have a stray "l" character between two code
blocks:

method objectKey($/) {
make $.made;
}l # <-- WHAT'S THIS?
method pairlist($/) {
make $>>.made.flat;
}

I defer to Brad and Simon, otherwise.

Best, Bill.

On Sun, Dec 26, 2021 at 9:37 AM Brad Gilbert  wrote:

> I'm on mobile, but without checking, I think the problem is here
>
> rule  pairlist   {  * % \; }
>
> Specifically it's the missing %
>
> rule  pairlist   {  * %% \; }
>
> JSON doesn't allow trailing commas or semicolons, so JSON::Tiny uses just
> %.
> Your data does have trailing semicolons, so you want to use %% instead.
>
> Also why did you change , without actually changing anything?
>
>
> On Sun, Dec 26, 2021, 3:22 AM Simon Proctor 
> wrote:
>
>> Still waking up but I think the issue is your pairlist has a semi colon
>> divider but this should be after each pair.
>>
>> So the trailing semi colon after b is causing it to fail.
>>
>> On Sun, 26 Dec 2021, 06:01 Paul Procacci,  wrote:
>>
>>> Hey all,
>>>
>>> Twas the night of Christmas, when all through the house, not a creature
>>> was stirring except Paul w/ his mouse.
>>>
>>> Hope everyone had a Merry Christmas and takes likings to corny opening
>>> statements.  ;)
>>>
>>> I was writing a little something tonight using Grammars and ran into
>>> something that I can't seem to wrap my head around.  I'm hoping someone
>>> could explain in detail.
>>>
>>> Given the following data:
>>>  data -
>>> objectKey:
>>> {
>>> a = "bi";
>>> b = "hi";
>>> }
>>>  end data -
>>>
>>>
>>>  and the following logic partially taken from JSON::Tiny:
>>>
>>>  code 
>>> grammar myTest {
>>> token TOP{ \s*  \s* }
>>> rule  object {  '{'  '}' }
>>> # rule  object {  '{' ~ '}'  }
>>> rule  objectKey  {  ':' }
>>> rule  pairlist   {  * % \; }
>>> rule  pair   {  '='  }
>>> token cstr   { + }
>>> token value  { '"' ~ '"' * }
>>> }
>>>
>>> class myTestActions {
>>> method TOP($/) {
>>> make $.made.hash.item;
>>> }
>>>
>>> method object($/) {
>>> say 'hello';
>>> }
>>>
>>> method objectKey($/) {
>>> make $.made;
>>> }l
>>> method pairlist($/) {
>>> make $>>.made.flat;
>>> }
>>>
>>> method pair($/) {
>>> make $.made => $.made;
>>> }
>>>
>>> method cstr($/)  { make ~$/ }
>>> method value($/) { make ~$/ }
>>> }
>>>  code 
>>>
>>>
>>> ... it'd be my hopes that this would match.  However, It's not matching
>>> on 'object' and I can't seem to figure out why.
>>>
>>> Adding Grammar::Tracer yields the following:
>>>
>>> TOP
>>> |  object
>>> |  |  objectKey
>>> |  |  |  cstr
>>> |  |  |  * MATCH "objectKey"
>>> |  |  * MATCH "objectKey:\n"
>>> |  |  pairlist
>>> |  |  |  pair
>>> |  |  |  |  cstr
>>> |  |  |  |  * MATCH "a"
>>> |  |  |  |  value
>>> |  |  |  |  * MATCH "\"bi\""
>>> |  |  |  * MATCH "a = \"bi\""
>>> |  |  |  pair
>>> |  |  |  |  cstr
>>> |  |  |  |  * MATCH "b"
>>> |  |  |  |  value
>>> |  |  |  |  * MATCH "\"hi\""
>>> |  |  |  * MATCH "b = \"hi\""
>>> |  |  |  pair
>>> |  |  |  |  cstr
>>> |  |  |  |  * FAIL
>>> |  |  |  * FAIL
>>> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
>>> |  * FAIL
>>> * FAIL
>>>
>>> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect
>>> here?
>>> Appreciate any insight.
>>>
>>> Thanks,
>>> Paul
>>> --
>>> __
>>>
>>> :(){ :|:& };:
>>>
>>


Re: Grammar Help

2021-12-26 Thread Brad Gilbert
I'm on mobile, but without checking, I think the problem is here

rule  pairlist   {  * % \; }

Specifically it's the missing %

rule  pairlist   {  * %% \; }

JSON doesn't allow trailing commas or semicolons, so JSON::Tiny uses just %.
Your data does have trailing semicolons, so you want to use %% instead.

Also why did you change , without actually changing anything?


On Sun, Dec 26, 2021, 3:22 AM Simon Proctor  wrote:

> Still waking up but I think the issue is your pairlist has a semi colon
> divider but this should be after each pair.
>
> So the trailing semi colon after b is causing it to fail.
>
> On Sun, 26 Dec 2021, 06:01 Paul Procacci,  wrote:
>
>> Hey all,
>>
>> Twas the night of Christmas, when all through the house, not a creature
>> was stirring except Paul w/ his mouse.
>>
>> Hope everyone had a Merry Christmas and takes likings to corny opening
>> statements.  ;)
>>
>> I was writing a little something tonight using Grammars and ran into
>> something that I can't seem to wrap my head around.  I'm hoping someone
>> could explain in detail.
>>
>> Given the following data:
>>  data -
>> objectKey:
>> {
>> a = "bi";
>> b = "hi";
>> }
>>  end data -
>>
>>
>>  and the following logic partially taken from JSON::Tiny:
>>
>>  code 
>> grammar myTest {
>> token TOP{ \s*  \s* }
>> rule  object {  '{'  '}' }
>> # rule  object {  '{' ~ '}'  }
>> rule  objectKey  {  ':' }
>> rule  pairlist   {  * % \; }
>> rule  pair   {  '='  }
>> token cstr   { + }
>> token value  { '"' ~ '"' * }
>> }
>>
>> class myTestActions {
>> method TOP($/) {
>> make $.made.hash.item;
>> }
>>
>> method object($/) {
>> say 'hello';
>> }
>>
>> method objectKey($/) {
>> make $.made;
>> }l
>> method pairlist($/) {
>> make $>>.made.flat;
>> }
>>
>> method pair($/) {
>> make $.made => $.made;
>> }
>>
>> method cstr($/)  { make ~$/ }
>> method value($/) { make ~$/ }
>> }
>>  code 
>>
>>
>> ... it'd be my hopes that this would match.  However, It's not matching
>> on 'object' and I can't seem to figure out why.
>>
>> Adding Grammar::Tracer yields the following:
>>
>> TOP
>> |  object
>> |  |  objectKey
>> |  |  |  cstr
>> |  |  |  * MATCH "objectKey"
>> |  |  * MATCH "objectKey:\n"
>> |  |  pairlist
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * MATCH "a"
>> |  |  |  |  value
>> |  |  |  |  * MATCH "\"bi\""
>> |  |  |  * MATCH "a = \"bi\""
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * MATCH "b"
>> |  |  |  |  value
>> |  |  |  |  * MATCH "\"hi\""
>> |  |  |  * MATCH "b = \"hi\""
>> |  |  |  pair
>> |  |  |  |  cstr
>> |  |  |  |  * FAIL
>> |  |  |  * FAIL
>> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
>> |  * FAIL
>> * FAIL
>>
>> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect here?
>> Appreciate any insight.
>>
>> Thanks,
>> Paul
>> --
>> __
>>
>> :(){ :|:& };:
>>
>


Re: Grammar Help

2021-12-26 Thread Simon Proctor
Still waking up but I think the issue is your pairlist has a semi colon
divider but this should be after each pair.

So the trailing semi colon after b is causing it to fail.

On Sun, 26 Dec 2021, 06:01 Paul Procacci,  wrote:

> Hey all,
>
> Twas the night of Christmas, when all through the house, not a creature
> was stirring except Paul w/ his mouse.
>
> Hope everyone had a Merry Christmas and takes likings to corny opening
> statements.  ;)
>
> I was writing a little something tonight using Grammars and ran into
> something that I can't seem to wrap my head around.  I'm hoping someone
> could explain in detail.
>
> Given the following data:
>  data -
> objectKey:
> {
> a = "bi";
> b = "hi";
> }
>  end data -
>
>
>  and the following logic partially taken from JSON::Tiny:
>
>  code 
> grammar myTest {
> token TOP{ \s*  \s* }
> rule  object {  '{'  '}' }
> # rule  object {  '{' ~ '}'  }
> rule  objectKey  {  ':' }
> rule  pairlist   {  * % \; }
> rule  pair   {  '='  }
> token cstr   { + }
> token value  { '"' ~ '"' * }
> }
>
> class myTestActions {
> method TOP($/) {
> make $.made.hash.item;
> }
>
> method object($/) {
> say 'hello';
> }
>
> method objectKey($/) {
> make $.made;
> }l
> method pairlist($/) {
> make $>>.made.flat;
> }
>
> method pair($/) {
> make $.made => $.made;
> }
>
> method cstr($/)  { make ~$/ }
> method value($/) { make ~$/ }
> }
>  code 
>
>
> ... it'd be my hopes that this would match.  However, It's not matching on
> 'object' and I can't seem to figure out why.
>
> Adding Grammar::Tracer yields the following:
>
> TOP
> |  object
> |  |  objectKey
> |  |  |  cstr
> |  |  |  * MATCH "objectKey"
> |  |  * MATCH "objectKey:\n"
> |  |  pairlist
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "a"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"bi\""
> |  |  |  * MATCH "a = \"bi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * MATCH "b"
> |  |  |  |  value
> |  |  |  |  * MATCH "\"hi\""
> |  |  |  * MATCH "b = \"hi\""
> |  |  |  pair
> |  |  |  |  cstr
> |  |  |  |  * FAIL
> |  |  |  * FAIL
> |  |  * MATCH "a = \"bi\";\n\tb = \"hi\""
> |  * FAIL
> * FAIL
>
> What exactly am I doing wrong?  Does '{' ~ '}' not work as I expect here?
> Appreciate any insight.
>
> Thanks,
> Paul
> --
> __
>
> :(){ :|:& };:
>