Chain processors - can we ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Chain processors - can we ?

ch007m
This post was updated on .
Hi

Can we chain the processors in such a way that BlockProcessor will be processed after the TreeProcessor ? The reason why I'm asking this question is because I would like to pospulate a hashMap using TreeProcessor and reuse it with the BlockProcessor

Example:
        // Include the Table extension
        asciidoctor.javaExtensionRegistry()
                .treeprocessor(FindRolesTreeProcessor.class)
                .block(GenerateTableBlockProcessor.class);
...

Best

Charles



Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

David Jencks
No.  However the processors are registered has no effect on what stage of parsing they are called during.

David Jencks

On Apr 9, 2020, at 9:38 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Hi

Can we chain the processors in such a way that BlockProcessor will be processed after the TreeProcessor ?

Example:
        // Include the Table extension
        asciidoctor.javaExtensionRegistry()
                .treeprocessor(FindRolesTreeProcessor.class)
                .block(GenerateTableBlockProcessor.class);
...

Best

Charles



Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

ch007m
So, How can I share a HashMap created by the TreeProcessor with the BlockProcessor ?
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

David Jencks
I’m not familiar with the java API for the extension registry.  If you really can only register a class rather than an instance as a processor, then I think you’ll need to use a static variable in one class, accessed by the other.

David Jencks

On Apr 9, 2020, at 9:46 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:

So, How can I share a HashMap created by the TreeProcessor with the BlockProcessor ?
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7872.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

Alexander Schwartz
The API allows to register instances of classes as well. One solution could be
  1. create the HashMap
  2. pass it to the constructor of each processor
  3. register the processor instances
Regards, Alexander
Alexander Schwartz (alexander.schwartz@gmx.net)
https://www.ahus1.de
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

ch007m
I can share the HashMap using a static method between the classes. But, as we cannot define the order of the execution of the processors, then I must try to use another approach where I will use first a preprocessor to calculate the hashmap and next using a Blockprocessor to generate the table with the hashmap values

asciidoctor.javaExtensionRegistry()
                .preprocessor(FindRolesPreProcessor.class)
                .block(GenerateTableBlockProcessor.class);

Remark: the problem that I have is that we cannot use a document AST tree with the preprocessor but instead read lines to navigate ...
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

David Jencks
If registering objects rather than classes is supported, I would use a single object implementing both interfaces.

You may not want to do it, but the sequence suggested by Dan of having a block processor first do something to locate where the table is going to be, either by inserting a table or, much easier, as I did, locating an existing table, and then having the tree processor add rows, will definitely work and IMO would be considerably simpler and more reliable than using a preprocessor.  If you use a tree processor you can rely on asciidoctor actually correctly finding the structure of your document; if you use a preprocessor you are rewriting the parser, probably with bugs.  I’m not sure what problem you see with this structure.

David Jencks

On Apr 9, 2020, at 11:50 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:

I can share the HashMap using a static method between the classes. But, as we cannot define the order of the execution of the processors, then I must try to use another approach where I will use first a preprocessor to calculate the hashmap and next using a Blockprocessor to generate the table with the hashmap values

asciidoctor.javaExtensionRegistry()
                .preprocessor(FindRolesPreProcessor.class)
                .block(GenerateTableBlockProcessor.class);

Remark: the problem that I have is that we cannot use a document AST tree with the preprocessor but instead read lines to navigate ...
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7876.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

LightGuardjp
A preprocessor will be the first step in the chain of processors regardless.

On Thu, Apr 9, 2020 at 1:17 PM David Jencks [via Asciidoctor :: Discussion] <[hidden email]> wrote:
If registering objects rather than classes is supported, I would use a single object implementing both interfaces.

You may not want to do it, but the sequence suggested by Dan of having a block processor first do something to locate where the table is going to be, either by inserting a table or, much easier, as I did, locating an existing table, and then having the tree processor add rows, will definitely work and IMO would be considerably simpler and more reliable than using a preprocessor.  If you use a tree processor you can rely on asciidoctor actually correctly finding the structure of your document; if you use a preprocessor you are rewriting the parser, probably with bugs.  I’m not sure what problem you see with this structure.

David Jencks

On Apr 9, 2020, at 11:50 AM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:

I can share the HashMap using a static method between the classes. But, as we cannot define the order of the execution of the processors, then I must try to use another approach where I will use first a preprocessor to calculate the hashmap and next using a Blockprocessor to generate the table with the hashmap values

asciidoctor.javaExtensionRegistry()
                .preprocessor(FindRolesPreProcessor.class)
                .block(GenerateTableBlockProcessor.class);

Remark: the problem that I have is that we cannot use a document AST tree with the preprocessor but instead read lines to navigate ...
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7876.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML




If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7878.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

ch007m
In reply to this post by David Jencks
Can you share your example please where you locate an existing table using a BlockProcessor and then having the tree processor to add the rows ?

Question: Can we first use the treeProcessor to iterate through the document to create the HashMap and next use a BlockProcessor to insert a Table generated using the hashmap ?
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard
Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

David Jencks
(moved to asciidoctor/asciidoctor gitter channel)

On Apr 9, 2020, at 12:51 PM, ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Can you share your example please where you locate an existing table using a BlockProcessor and then having the tree processor to add the rows ?

Question: Can we first use the treeProcessor to iterate through the document to create the HashMap and next use a BlockProcessor to insert a Table generated using the hashmap ?
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7880.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Chain processors - can we ?

LightGuardjp
In reply to this post by ch007m
I don't have an example that does that. Ah, a treeprocessor and a block processor, I thought you had said a preprocessor. I'm not sure the relationship of when those are called. What do you need from the tree processor?

On Thu, Apr 9, 2020 at 1:51 PM ch007m [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Can you share your example please where you locate an existing table using a BlockProcessor and then having the tree processor to add the rows ?

Question: Can we first use the treeProcessor to iterate through the document to create the HashMap and next use a BlockProcessor to insert a Table generated using the hashmap ?
Charles Moulliard
Apache Committer / Technologist Evangelist / Blogger / MiddleWare Specialist
Twitter : @cmoulliard



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Chain-processors-can-we-tp7870p7880.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--