compile parboiled parser with clojure

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

compile parboiled parser with clojure

Bartek
Hello,

I'm having hard times trying to compile parboiled parser with clojure using gen-class, because:
* It doesn't support generic types
* It doesn't allow to use annotations

I made workaround for the first point (just extended class like

public class ClojureBaseParser extends BaseParser {

)

but I cannot run annotations (@BuildParseTree) in compilation time.
The result of simple clojure class compilation and running it is runtime error.
Is there a way to rewrite parser bytecode programmatically?

thanks,
Bartek
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

mathias
Administrator
Bartek,

I don't know enough of clojure's support for generating classes that I could be of help with regard to your question.

> Is there a way to rewrite parser bytecode programmatically?

Parboiled for Java *does* rewrite the parser byte code programmatically.
I'm not sure I fully understand your question.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 12.01.2013, at 10:44, "Bartek [via parboiled users]" <[hidden email]> wrote:

>
>
> Hello,
>
> I'm having hard times trying to compile parboiled parser with clojure using
> gen-class, because:
> * It doesn't support generic types
> * It doesn't allow to use annotations
>
> I made workaround for the first point (just extended class like
>
> public class ClojureBaseParser extends BaseParser {
>
> )
>
> but I cannot run annotations (@BuildParseTree) in compilation time.
> The result of simple clojure class compilation and running it is runtime
> error.
> Is there a way to rewrite parser bytecode programmatically?
>
> thanks,
> Bartek
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

Bartek
Thanks Mathias,

Ok, let me be more specific:

Wiadomość napisana przez mathias [via parboiled users] <[hidden email]> w dniu 13 sty 2013, o godz. 15:16:

Bartek,

I don't know enough of clojure's support for generating classes that I could be of help with regard to your question.

> Is there a way to rewrite parser bytecode programmatically?

Parboiled for Java *does* rewrite the parser byte code programmatically.

Could you point me java code snippet that does this step? I'd like to take it and use it in my own context.

best wishes,
Bartek

I'm not sure I fully understand your question. 

Cheers,
Mathias

---
<a href="x-msg://23/user/SendEmail.jtp?type=node&amp;node=4024127&amp;i=0" target="_top" rel="nofollow" link="external">[hidden email]
http://www.parboiled.org

On 12.01.2013, at 10:44, "Bartek [via parboiled users]" <<a href="x-msg://23/user/SendEmail.jtp?type=node&amp;node=4024127&amp;i=1" target="_top" rel="nofollow" link="external">[hidden email]> wrote:

>
>
> Hello,
>
> I'm having hard times trying to compile parboiled parser with clojure using
> gen-class, because:
> * It doesn't support generic types
> * It doesn't allow to use annotations
>
> I made workaround for the first point (just extended class like
>
> public class ClojureBaseParser extends BaseParser {
>
> )
>
> but I cannot run annotations (@BuildParseTree) in compilation time.
> The result of simple clojure class compilation and running it is runtime
> error.
> Is there a way to rewrite parser bytecode programmatically?
>
> thanks,
> Bartek
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
> To start a new topic under parboiled users, email <a href="x-msg://23/user/SendEmail.jtp?type=node&amp;node=4024127&amp;i=2" target="_top" rel="nofollow" link="external">[hidden email]
> To unsubscribe from parboiled users, visit <a href="x-msg://23/" target="_top" rel="nofollow" link="external">


<a href="x-msg://23/" target="_top" rel="nofollow" link="external">
If you reply to this email, your message will be added to the discussion below:
http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024127.html
To unsubscribe from compile parboiled parser with clojure, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

mathias
Administrator
Bartek,

>>> Is there a way to rewrite parser bytecode programmatically?
>>
>> Parboiled for Java *does* rewrite the parser byte code programmatically.
>
> Could you point me java code snippet that does this step? I'd like to take it and use it in my own context.

parboiled does it internally.
parser extension (as I call the bytecode analysis and rewriting of your parser class) is a mandatory step of parboiled for Java.
This doc page explains it in more detail: https://github.com/sirthias/parboiled/wiki/Parser-Extension-in-Detail

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 13.01.2013, at 15:23, Bartek [via parboiled users] <[hidden email]> wrote:

>
>
> Thanks Mathias,
>
> Ok, let me be more specific:
>
> Wiadomość napisana przez mathias [via parboiled users] <[hidden email]> w dniu 13 sty 2013, o godz. 15:16:
>
>> Bartek,
>>
>> I don't know enough of clojure's support for generating classes that I could be of help with regard to your question.
>>
>>> Is there a way to rewrite parser bytecode programmatically?
>>
>> Parboiled for Java *does* rewrite the parser byte code programmatically.
>
> Could you point me java code snippet that does this step? I'd like to take it and use it in my own context.
>
> best wishes,
> Bartek
>
>> I'm not sure I fully understand your question.
>
>>
>> Cheers,
>> Mathias
>>
>> ---
>> [hidden email]
>> http://www.parboiled.org
>>
>> On 12.01.2013, at 10:44, "Bartek [via parboiled users]" <[hidden email]> wrote:
>>
>>>
>>>
>>> Hello,
>>>
>>> I'm having hard times trying to compile parboiled parser with clojure using
>>> gen-class, because:
>>> * It doesn't support generic types
>>> * It doesn't allow to use annotations
>>>
>>> I made workaround for the first point (just extended class like
>>>
>>> public class ClojureBaseParser extends BaseParser {
>>>
>>> )
>>>
>>> but I cannot run annotations (@BuildParseTree) in compilation time.
>>> The result of simple clojure class compilation and running it is runtime
>>> error.
>>> Is there a way to rewrite parser bytecode programmatically?
>>>
>>> thanks,
>>> Bartek
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> If you reply to this email, your message will be added to the discussion below:
>>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
>>> To start a new topic under parboiled users, email [hidden email]
>>> To unsubscribe from parboiled users, visit
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024127.html
>> To unsubscribe from compile parboiled parser with clojure, click here.
>> NAML
>
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024128.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

Bartek


2013/1/13 mathias [via parboiled users] <[hidden email]>
Bartek,

>>> Is there a way to rewrite parser bytecode programmatically?
>>
>> Parboiled for Java *does* rewrite the parser byte code programmatically.
>
> Could you point me java code snippet that does this step? I'd like to take it and use it in my own context.

parboiled does it internally.
parser extension (as I call the bytecode analysis and rewriting of your parser class) is a mandatory step of parboiled for Java.
This doc page explains it in more detail: https://github.com/sirthias/parboiled/wiki/Parser-Extension-in-Detail


So let me state how I get it: there is no pipeline like: [Java code] -> [.class] -> [rewritten .class], so I cannot do something like: [Java code] -> [extend it with clojure gen-class] -> [.class] -> [rewritten .class], because rewriting is embedded very internally and cannot be extracted as single step?

thanks,
Bartek

 
On <a href="tel:13.01.2013" value="+4813012013" target="_blank">13.01.2013, at 15:23, Bartek [via parboiled users] <[hidden email]> wrote:

>
>
> Thanks Mathias,
>
> Ok, let me be more specific:
>
> Wiadomość napisana przez mathias [via parboiled users] <[hidden email]> w dniu 13 sty 2013, o godz. 15:16:
>

>> Bartek,
>>
>> I don't know enough of clojure's support for generating classes that I could be of help with regard to your question.
>>
>>> Is there a way to rewrite parser bytecode programmatically?
>>
>> Parboiled for Java *does* rewrite the parser byte code programmatically.
>
> Could you point me java code snippet that does this step? I'd like to take it and use it in my own context.
>
> best wishes,
> Bartek
>
>> I'm not sure I fully understand your question.
>
>>
>> Cheers,
>> Mathias
>>
>> ---
>> [hidden email]
>> http://www.parboiled.org
>>
>> On <a href="tel:12.01.2013" value="+4812012013" target="_blank">12.01.2013, at 10:44, "Bartek [via parboiled users]" <[hidden email]> wrote:
>>
>>>
>>>
>>> Hello,
>>>
>>> I'm having hard times trying to compile parboiled parser with clojure using
>>> gen-class, because:
>>> * It doesn't support generic types
>>> * It doesn't allow to use annotations
>>>
>>> I made workaround for the first point (just extended class like
>>>
>>> public class ClojureBaseParser extends BaseParser {
>>>
>>> )
>>>
>>> but I cannot run annotations (@BuildParseTree) in compilation time.
>>> The result of simple clojure class compilation and running it is runtime
>>> error.
>>> Is there a way to rewrite parser bytecode programmatically?
>>>
>>> thanks,
>>> Bartek
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> If you reply to this email, your message will be added to the discussion below:
>>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
>>> To start a new topic under parboiled users, email [hidden email]
>>> To unsubscribe from parboiled users, visit
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024127.html
>> To unsubscribe from compile parboiled parser with clojure, click here.
>> NAML
>
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024128.html

> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit



To unsubscribe from compile parboiled parser with clojure, click here.
NAML



--
pozdrawiam,
Bartek Krupa
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

mathias
Administrator
Bartek,

I don't know what exactly clojure gen-class does or doesn't do.

The entry point to parboiled parser creation is this:
https://github.com/sirthias/parboiled/blob/master/parboiled-java/src/main/java/org/parboiled/Parboiled.java#L51

If you follow the code from this point on you'll see that parboiled tries to load the classes byte code (for analysis and rewriting via ASM) here:
https://github.com/sirthias/parboiled/blob/master/parboiled-java/src/main/java/org/parboiled/transform/AsmUtils.java#L49

So, if you can provide a .class file on the classpath things should work.
Otherwise you'll have to find another way to provide parboiled with the bytecode, which probably requires you to apply some kind of patch.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 14.01.2013, at 11:37, "Bartek [via parboiled users]" <[hidden email]> wrote:

>
>
> 2013/1/13 mathias [via parboiled users] <
> [hidden email]>
>
>> Bartek,
>>
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>
>>>> Parboiled for Java *does* rewrite the parser byte code
>> programmatically.
>>>
>>> Could you point me java code snippet that does this step? I'd like to
>> take it and use it in my own context.
>>
>> parboiled does it internally.
>> parser extension (as I call the bytecode analysis and rewriting of your
>> parser class) is a mandatory step of parboiled for Java.
>> This doc page explains it in more detail:
>> https://github.com/sirthias/parboiled/wiki/Parser-Extension-in-Detail
>>
>>
> So let me state how I get it: there is no pipeline like: [Java code] ->
> [.class] -> [rewritten .class], so I cannot do something like: [Java code]
> -> [extend it with clojure gen-class] -> [.class] -> [rewritten .class],
> because rewriting is embedded very internally and cannot be extracted as
> single step?
>
> thanks,
> Bartek
>
>
>
>>
>> Cheers,
>> Mathias
>>
>> ---
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=4024129&i=0>
>> http://www.parboiled.org
>>
>> On 13.01.2013, at 15:23, Bartek [via parboiled users] <[hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=1>>
>> wrote:
>>
>>>
>>>
>>> Thanks Mathias,
>>>
>>> Ok, let me be more specific:
>>>
>>> Wiadomość napisana przez mathias [via parboiled users] <[hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=2>>
>> w dniu 13 sty 2013, o godz. 15:16:
>>>
>>>> Bartek,
>>>>
>>>> I don't know enough of clojure's support for generating classes that I
>> could be of help with regard to your question.
>>>>
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>
>>>> Parboiled for Java *does* rewrite the parser byte code
>> programmatically.
>>>
>>> Could you point me java code snippet that does this step? I'd like to
>> take it and use it in my own context.
>>>
>>> best wishes,
>>> Bartek
>>>
>>>> I'm not sure I fully understand your question.
>>>
>>>>
>>>> Cheers,
>>>> Mathias
>>>>
>>>> ---
>>>> [hidden email]
>>>> http://www.parboiled.org
>>>>
>>>> On 12.01.2013, at 10:44, "Bartek [via parboiled users]" <[hidden
>> email]> wrote:
>>>>
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I'm having hard times trying to compile parboiled parser with clojure
>> using
>>>>> gen-class, because:
>>>>> * It doesn't support generic types
>>>>> * It doesn't allow to use annotations
>>>>>
>>>>> I made workaround for the first point (just extended class like
>>>>>
>>>>> public class ClojureBaseParser extends BaseParser {
>>>>>
>>>>> )
>>>>>
>>>>> but I cannot run annotations (@BuildParseTree) in compilation time.
>>>>> The result of simple clojure class compilation and running it is
>> runtime
>>>>> error.
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>>
>>>>> thanks,
>>>>> Bartek
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> If you reply to this email, your message will be added to the
>> discussion below:
>>>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
>>>>> To start a new topic under parboiled users, email [hidden email]
>>>>> To unsubscribe from parboiled users, visit
>>>>
>>>> If you reply to this email, your message will be added to the
>> discussion below:
>>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024127.html
>>>> To unsubscribe from compile parboiled parser with clojure, click here.
>>>> NAML
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> If you reply to this email, your message will be added to the discussion
>> below:
>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024128.html
>>
>>> To start a new topic under parboiled users, email [hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=3>
>>> To unsubscribe from parboiled users, visit
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024129.html
>> To unsubscribe from compile parboiled parser with clojure, click here<
>> .
>> NAML<
http://users.parboiled.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
> --
> pozdrawiam,
> Bartek Krupa
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024130.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: compile parboiled parser with clojure

Bartek


2013/1/14 mathias [via parboiled users] <[hidden email]>
Bartek,

I don't know what exactly clojure gen-class does or doesn't do.

The entry point to parboiled parser creation is this:
https://github.com/sirthias/parboiled/blob/master/parboiled-java/src/main/java/org/parboiled/Parboiled.java#L51

If you follow the code from this point on you'll see that parboiled tries to load the classes byte code (for analysis and rewriting via ASM) here:
https://github.com/sirthias/parboiled/blob/master/parboiled-java/src/main/java/org/parboiled/transform/AsmUtils.java#L49

So, if you can provide a .class file on the classpath things should work.
Otherwise you'll have to find another way to provide parboiled with the bytecode, which probably requires you to apply some kind of patch.

Thanks, that answer fully satisfy me :) Probably you shouldn't be concerned about what gen-class does - important information for me is that its output is .class file that can be rewritten using 'createParser' function that you've pointed to me.

I'll let know how does this chaining work in real wold.

best wishes,
Bartek

 
On <a href="tel:14.01.2013" value="+4814012013" target="_blank">14.01.2013, at 11:37, "Bartek [via parboiled users]" <[hidden email]> wrote:

>
>
> 2013/1/13 mathias [via parboiled users] <
> [hidden email]>
>

>> Bartek,
>>
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>
>>>> Parboiled for Java *does* rewrite the parser byte code
>> programmatically.
>>>
>>> Could you point me java code snippet that does this step? I'd like to
>> take it and use it in my own context.
>>
>> parboiled does it internally.
>> parser extension (as I call the bytecode analysis and rewriting of your
>> parser class) is a mandatory step of parboiled for Java.
>> This doc page explains it in more detail:
>> https://github.com/sirthias/parboiled/wiki/Parser-Extension-in-Detail
>>
>>
> So let me state how I get it: there is no pipeline like: [Java code] ->
> [.class] -> [rewritten .class], so I cannot do something like: [Java code]
> -> [extend it with clojure gen-class] -> [.class] -> [rewritten .class],
> because rewriting is embedded very internally and cannot be extracted as
> single step?
>
> thanks,
> Bartek
>
>
>
>>
>> Cheers,
>> Mathias
>>
>> ---
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=4024129&i=0>
>> http://www.parboiled.org
>>
>> On <a href="tel:13.01.2013" value="+4813012013" target="_blank">13.01.2013, at 15:23, Bartek [via parboiled users] <[hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=1>>
>> wrote:
>>
>>>
>>>
>>> Thanks Mathias,
>>>
>>> Ok, let me be more specific:
>>>
>>> Wiadomość napisana przez mathias [via parboiled users] <[hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=2>>
>> w dniu 13 sty 2013, o godz. 15:16:

>>>
>>>> Bartek,
>>>>
>>>> I don't know enough of clojure's support for generating classes that I
>> could be of help with regard to your question.
>>>>
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>
>>>> Parboiled for Java *does* rewrite the parser byte code
>> programmatically.
>>>
>>> Could you point me java code snippet that does this step? I'd like to
>> take it and use it in my own context.
>>>
>>> best wishes,
>>> Bartek
>>>
>>>> I'm not sure I fully understand your question.
>>>
>>>>
>>>> Cheers,
>>>> Mathias
>>>>
>>>> ---
>>>> [hidden email]
>>>> http://www.parboiled.org
>>>>
>>>> On <a href="tel:12.01.2013" value="+4812012013" target="_blank">12.01.2013, at 10:44, "Bartek [via parboiled users]" <[hidden
>> email]> wrote:
>>>>
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I'm having hard times trying to compile parboiled parser with clojure
>> using
>>>>> gen-class, because:
>>>>> * It doesn't support generic types
>>>>> * It doesn't allow to use annotations
>>>>>
>>>>> I made workaround for the first point (just extended class like
>>>>>
>>>>> public class ClojureBaseParser extends BaseParser {
>>>>>
>>>>> )
>>>>>
>>>>> but I cannot run annotations (@BuildParseTree) in compilation time.
>>>>> The result of simple clojure class compilation and running it is
>> runtime
>>>>> error.
>>>>> Is there a way to rewrite parser bytecode programmatically?
>>>>>
>>>>> thanks,
>>>>> Bartek
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> If you reply to this email, your message will be added to the
>> discussion below:
>>>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126.html
>>>>> To start a new topic under parboiled users, email [hidden email]
>>>>> To unsubscribe from parboiled users, visit
>>>>
>>>> If you reply to this email, your message will be added to the
>> discussion below:
>>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024127.html
>>>> To unsubscribe from compile parboiled parser with clojure, click here.

>>>> NAML
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> If you reply to this email, your message will be added to the discussion
>> below:
>>>
>> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024128.html
>>
>>> To start a new topic under parboiled users, email [hidden email]<http://user/SendEmail.jtp?type=node&node=4024129&i=3>
>>> To unsubscribe from parboiled users, visit
>>
>>
>> ------------------------------
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/compile-parboiled-parser-with-clojure-tp4024126p4024130.html

> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit



To unsubscribe from compile parboiled parser with clojure, click here.
NAML



--
pozdrawiam,
Bartek Krupa
Loading...