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

A grammar can be made not to inherit from Grammar in Rakudo #2078

Closed
p6rt opened this issue Aug 19, 2010 · 6 comments
Closed

A grammar can be made not to inherit from Grammar in Rakudo #2078

p6rt opened this issue Aug 19, 2010 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 19, 2010

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

Searchable as RT77322$

@p6rt
Copy link
Author

p6rt commented Aug 19, 2010

From @masak

From <http://use.perl.org/~JonathanWorthington/journal/39856>&#8203;:

] Added handling of the grammar package declarator back in. Now the
] "inherit from Grammar by default and not Any" stuff is just done by
] us having a metaclass for grammars - GrammarHOW - that subclasses
] the metaclass for classes - ClassHOW. It simply overrides the
] compose method (what we call when we're finished defining a package)
] and checks if there are any explicit parents, and if not adds Grammar
] as a parent, then delegates up to the superclass to do the rest of the work.

<masak> rakudo​: class A {}; grammar G is A { regex TOP { foo } }; G.parse("foo")
<p6eval> rakudo 90637b​: OUTPUT«Method 'parse' not found for invocant
of class '' [...]
<masak> I know, that's a bit of "doctor, it hurts when I do this"...
<moritz_> masak​: I'd say it's a bug. 'grammar' should add Grammar to
the list of its parents, unless one of the explicit parents is Grammar
already
<moritz_> at least I think that's what it should do.
<masak> oh, good.
* masak submits rakudobug
<moritz_> and I know where to fix it
<moritz_> src/metamodel/GrammarHow.pir around line 41
<jnthn> :-)
<jnthn> Yes, that's HOW.
<moritz_> if it were written in Perl 6, I'd say if
none(@​parents>>.isa(Grammar)) { $P0.add_parent(Grammar, $P0) }
<jnthn> It'll be written in NQP at some point.
<moritz_> jnthn​: how hard would it be to rewrite it now?
<jnthn> moritz_​: Probably quite easy.
<jnthn> Though a bit messy, since for now you'd still need pir​::foo I guess

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

From @cognominal

patch attached

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

From @cognominal

0001-fixes-77322-changed-sub-compose-in-GrammarHOW.pir-so.patch
From 4bfe94e440eccb22490fe7b97064428b204e00f2 Mon Sep 17 00:00:00 2001
From: Stephane cognominal Payrard <cognominal@gmail.com>
Date: Sat, 21 Aug 2010 11:10:01 +0200
Subject: [PATCH] fixes #77322 : changed sub compose in GrammarHOW.pir so that grammars always inherit from Grammar

---
 src/metamodel/GrammarHOW.pir |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/metamodel/GrammarHOW.pir b/src/metamodel/GrammarHOW.pir
index 6c36a64..c5b7110 100644
--- a/src/metamodel/GrammarHOW.pir
+++ b/src/metamodel/GrammarHOW.pir
@@ -26,20 +26,28 @@ Grammar by default.
 
 =item compose(meta)
 
-If there is no explicit parent, makes Grammar the default parent and then
+If none of the parents is a Grammar, add Grammar as a parent and then
 delegates to ClassHOW.
 
 =cut
 
 .sub 'compose' :method
     .param pmc obj
-    .local pmc parrotclass
+    .local pmc parrotclass, grammarclass
+    grammarclass = get_hll_global 'Grammar'
     parrotclass = getattribute self, 'parrotclass'
     $P0 = inspect parrotclass, 'parents'
-    if $P0 goto have_parents
-    $P0 = get_hll_global 'Grammar'
-    self.'add_parent'(obj, $P0)
-  have_parents:
+    unless $P0 goto add_grammar_as_parent
+    $P1 = iter $P0
+loop_on_parents:
+    unless $P1 goto add_grammar_as_parent
+    $P2 = shift $P1
+    $I0 = $P2.'isa'(grammarclass)
+    if $I0 goto loop_on_parents_done
+    goto loop_on_parents
+  add_grammar_as_parent:  
+    self.'add_parent'(obj, grammarclass)
+  loop_on_parents_done:
     $P0 = get_hll_global 'ClassHOW'
     $P0 = find_method $P0, 'compose'
     .tailcall $P0(self, obj)
-- 
1.7.0.3.291.g5e4f6

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

From @moritz

thanks, applied the patch, and added tests to S05-grammar/inheritance.t

@p6rt p6rt closed this as completed Aug 21, 2010
@p6rt
Copy link
Author

p6rt commented Aug 21, 2010

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

@p6rt p6rt added the Bug 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