Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke multi-level namespace grammars from rules #421

Closed
p6rt opened this issue Nov 21, 2008 · 7 comments
Closed

invoke multi-level namespace grammars from rules #421

p6rt opened this issue Nov 21, 2008 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 21, 2008

Migrated from rt.perl.org#60716 (status was 'resolved')

Searchable as RT60716$

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @chrisdolan

This code works in Rakudo rev 32970​:

  grammar GrammarOne { token foo { 'foo' }; }
  grammar GrammarTwo { token foobar { <GrammarOne​::foo> 'bar' }; }
  'foobar' ~~ GrammarTwo​::foobar or die 'failed one-level namespace
grammar';

But this code does dies​:

  grammar Grammar​::A { token foo { 'foo' }; }
  grammar Grammar​::B { token foobar { <Grammar​::A​::foo> 'bar' }; }
  'foobar' ~~ Grammar​::B​::foobar or die 'failed two-level namespace
grammar';

The attached patch fixes the latter problem. The patch changes the
implementation of !keyword_grammar to be much more like !
keyword_class, which has had more recent attention. If this patch is
applied, I recommend that somebody do the analogous work for !
keyword_role too.

  guts.pir | 12 ++----------
  1 files changed, 2 insertions(+), 10 deletions(-)

@p6rt
Copy link
Author

p6rt commented Nov 21, 2008

From @chrisdolan

grammar_namespace.patch
Index: languages/perl6/src/builtins/guts.pir
===================================================================
--- languages/perl6/src/builtins/guts.pir	(revision 32970)
+++ languages/perl6/src/builtins/guts.pir	(working copy)
@@ -352,17 +352,9 @@
     .param string name
     .local pmc info, grammar
 
-    # Need to make sure it ends up attached to the right
-    # namespace.
-    info = new 'Hash'
-    info['name'] = name
-    $P0 = new 'ResizablePMCArray'
-    $P0[0] = name
-    info['namespace'] = $P0
+    $P0 = split "::", name
+    grammar = newclass $P0
 
-    # Create grammar class..
-    grammar = new 'Class', info
-
     .return(grammar)
 .end
 

@p6rt
Copy link
Author

p6rt commented Nov 25, 2008

From @pmichaud

On Thu Nov 20 19​:59​:03 2008, chris@​chrisdolan.net wrote​:

This code works in Rakudo rev 32970​:

grammar GrammarOne { token foo { 'foo' }; }
grammar GrammarTwo { token foobar { <GrammarOne​::foo> 'bar' }; }
'foobar' ~~ GrammarTwo​::foobar or die 'failed one-level namespace
grammar';

But this code does dies​:

grammar Grammar​::A { token foo { 'foo' }; }
grammar Grammar​::B { token foobar { <Grammar​::A​::foo> 'bar' }; }
'foobar' ~~ Grammar​::B​::foobar or die 'failed two-level namespace
grammar';

The attached patch fixes the latter problem.

Patch rejected, as neither

  'foobar' ~~ GrammarTwo​::foobar

nor

  'foobar' ~~ Grammar​::B​::foobar

are correct syntax for invoking a regex inside of a grammar. We don't
know what the correct syntax is yet, but we know that this isn't it.

Rakudo implements the first syntax from an earlier synopsis spec that
has since been changed. We should probably adjust Rakudo so that it
doesn't accept that form either.

So, I'm converting this ticket to indicate a "todo" of remove the
incorrect regex invocation syntax.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 25, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 29, 2008

From @chrisdolan

On Tue Nov 25 13​:37​:09 2008, pmichaud wrote​:

On Thu Nov 20 19​:59​:03 2008, chris@​chrisdolan.net wrote​:

This code works in Rakudo rev 32970​:

grammar GrammarOne { token foo { 'foo' }; }
grammar GrammarTwo { token foobar { <GrammarOne​::foo> 'bar' }; }
'foobar' ~~ GrammarTwo​::foobar or die 'failed one-level namespace
grammar';

But this code does dies​:

grammar Grammar​::A { token foo { 'foo' }; }
grammar Grammar​::B { token foobar { <Grammar​::A​::foo> 'bar' }; }
'foobar' ~~ Grammar​::B​::foobar or die 'failed two-level namespace
grammar';

The attached patch fixes the latter problem.

Patch rejected, as neither

'foobar' ~~ GrammarTwo&#8203;::foobar

nor

'foobar' ~~ Grammar&#8203;::B&#8203;::foobar

are correct syntax for invoking a regex inside of a grammar. We don't
know what the correct syntax is yet, but we know that this isn't it.

Rakudo implements the first syntax from an earlier synopsis spec that
has since been changed. We should probably adjust Rakudo so that it
doesn't accept that form either.

So, I'm converting this ticket to indicate a "todo" of remove the
incorrect regex invocation syntax.

Thanks!

Pm

I appreciate the feedback, and you're right, but I believe your comment
focuses on an incidental detail of my report (the smart match), not on
the actual problem addressed.

So, let me rephrase, with apologies for the distraction​:

Without my patch, the first of the following succeeds but the second
fails. With the patch, they both succeed. My patch allows you to use
more than one "​::" in a <> element *inside* a regex.

grammar GrammarOne { token foo { 'foo' }; }
grammar GrammarTwo { token TOP { <GrammarOne​::foo> 'bar' }; }
'foobar' ~~ GrammarTwo or die 'failed one-level namespace grammar';

grammar Grammar​::Deep { token foo { 'foo' }; }
grammar GrammarShallow { token TOP { <Grammar​::Deep​::foo> 'bar' }; }
'foobar' ~~ GrammarShallow or die 'failed mixed-level namespace grammar';

So, the feature enabled by this patch is the <Grammar​::Deep​::foo>

@p6rt
Copy link
Author

p6rt commented Dec 17, 2008

From @jnthn

On Sat Nov 29 08​:34​:39 2008, chrisdolan wrote​:

Without my patch, the first of the following succeeds but the second
fails. With the patch, they both succeed. My patch allows you to use
more than one "​::" in a <> element *inside* a regex.

grammar Grammar​::Deep { token foo { 'foo' }; }
grammar GrammarShallow { token TOP { <Grammar​::Deep​::foo> 'bar' }; }

Yup, this patch is needed, so applied in r34045.

'foobar' ~~ GrammarShallow or die 'failed mixed-level namespace grammar';

So, the feature enabled by this patch is the <Grammar​::Deep​::foo>

'foobar' ~~ GrammarShallow isn't spec'd as doing this (we have a ticket
on that elsewhere), so the test I added does 'foobar' ~~
/<GrammarShallow​::TOP>/ which is, uh, spec'dish... ;-)

Thanks!

Jonathan

@p6rt
Copy link
Author

p6rt commented Dec 17, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Dec 17, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant