ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [callbacks] proper registration, node subtypes
@ 2012-06-25 13:39 Philipp Gesang
  2012-06-25 14:21 ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Gesang @ 2012-06-25 13:39 UTC (permalink / raw)
  To: ConTeXt ML


[-- Attachment #1.1.1: Type: text/plain, Size: 1033 bytes --]

Hi all,

I need a (pre-linebreak) callback to behave the same way with the
Context and Plain formats. *The sequence that nodes are traversed
in is very important.* Afaict the callback will have to be
registered as a “processors”/“before” nodes task. However, the
behavior is not identical:

1.  If the list contains a vlist or hlist, the callback is
    applied first on the inner list and then on the outer list.
    (Guess: it’s applied on the hpack_filter as well?)

2.  In Plain, glyph nodes have subtype 0 (GLYPH_CHARACTER), while
    in Context it’s 1 (GLYPH_LIGATURE).

Example code is appended.

Questions:
  - Which node task gets me a behavior similar to the raw
    pre_linebreak_filter?[*]
  - Does the difference wrt node subtype matter assuming I only
    (a) copy glyph nodes and (b) manipulate their .char field?

Any insights on this matter would be greatly appreciated. Regards
Philipp

[*] If this is not possible|recommended, what would a clean
    solution look like?



[-- Attachment #1.1.2: nlist-context.tex --]
[-- Type: application/x-tex, Size: 1499 bytes --]

[-- Attachment #1.1.3: nlist-plain.tex --]
[-- Type: application/x-tex, Size: 968 bytes --]

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [callbacks] proper registration, node subtypes
  2012-06-25 13:39 [callbacks] proper registration, node subtypes Philipp Gesang
@ 2012-06-25 14:21 ` Hans Hagen
  2012-06-25 14:50   ` Philipp Gesang
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2012-06-25 14:21 UTC (permalink / raw)
  To: ConTeXt ML

On 25-6-2012 15:39, Philipp Gesang wrote:

>    - Which node task gets me a behavior similar to the raw
>      pre_linebreak_filter?[*]

depends on what plain does ... anyway, 'before' is pretty raw i guess

>    - Does the difference wrt node subtype matter assuming I only
>      (a) copy glyph nodes and (b) manipulate their .char field?

not that much, it's just a state signal for font processing

> Any insights on this matter would be greatly appreciated. Regards
> Philipp

it all depends on what you want to do

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [callbacks] proper registration, node subtypes
  2012-06-25 14:21 ` Hans Hagen
@ 2012-06-25 14:50   ` Philipp Gesang
  2012-06-26 11:13     ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Gesang @ 2012-06-25 14:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 980 bytes --]

···<date: 2012-06-25, Monday>···<from: Hans Hagen>···

> On 25-6-2012 15:39, Philipp Gesang wrote:
> 
> >   - Does the difference wrt node subtype matter assuming I only
> >     (a) copy glyph nodes and (b) manipulate their .char field?
>
> not that much, it's just a state signal for font processing

Good to know.

> >Any insights on this matter would be greatly appreciated. Regards
> >Philipp
> 
> it all depends on what you want to do

Traverse the node list of a paragraph before line break from head
to tail in sequential order, recursing into sublists where they
appear. The callback removes and inserts nodes: which ones
depends on the nodes already processed (has a state).

Using the previous example code,

  \startfoo
    a\hbox{b}c
  \stopfoo

should result in the traversal <glyph a>, <hlist ...>, <glyph c>.

Philipp

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [callbacks] proper registration, node subtypes
  2012-06-25 14:50   ` Philipp Gesang
@ 2012-06-26 11:13     ` Hans Hagen
  2012-06-26 12:08       ` Philipp Gesang
  0 siblings, 1 reply; 6+ messages in thread
From: Hans Hagen @ 2012-06-26 11:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 25-6-2012 16:50, Philipp Gesang wrote:
> ···<date: 2012-06-25, Monday>···<from: Hans Hagen>···
>
>> On 25-6-2012 15:39, Philipp Gesang wrote:
>>
>>>    - Does the difference wrt node subtype matter assuming I only
>>>      (a) copy glyph nodes and (b) manipulate their .char field?
>>
>> not that much, it's just a state signal for font processing
>
> Good to know.
>
>>> Any insights on this matter would be greatly appreciated. Regards
>>> Philipp
>>
>> it all depends on what you want to do
>
> Traverse the node list of a paragraph before line break from head
> to tail in sequential order, recursing into sublists where they
> appear. The callback removes and inserts nodes: which ones
> depends on the nodes already processed (has a state).
>
> Using the previous example code,
>
>    \startfoo
>      a\hbox{b}c
>    \stopfoo
>
> should result in the traversal <glyph a>, <hlist ...>, <glyph c>.

\starttext

\startluacode

local function processnestedlist(head,n)
     local current, done = head, false
     while current do
         local id = current.id
         if id == nodes.nodecodes.hlist or id == nodes.nodecodes.vlist then
             local _, d = processnestedlist(current.list,n)
             if d then
                 done = true
             end
         elseif id == nodes.nodecodes.hglue_code and current.leader then
             local _, d = processnestedlist(current.leader,n)
             if d then
                 done = true
             end
         elseif id == nodes.nodecodes.glyph then -- todo: dics nodes
             n = n + 1
             print(n,utf.char(current.char))
         end
         current = current.next
     end
     return head, done, n
end


thirddata      = thirddata      or {}
thirddata.test = thirddata.test or { }

thirddata.test.one = function(head)
     local head, done, n = processnestedlist(head,0)
     print("n of glyphs",n)
     return head, done
end

nodes.tasks.appendaction ("processors","before","thirddata.test.one")

\stopluacode

\ruledhbox to 10cm {\strut hello \ruledhbox{brave new} world 
\cleaders\hbox{!}\hfil}

\stoptext

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [callbacks] proper registration, node subtypes
  2012-06-26 11:13     ` Hans Hagen
@ 2012-06-26 12:08       ` Philipp Gesang
  2012-06-26 12:50         ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Gesang @ 2012-06-26 12:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4030 bytes --]

···<date: 2012-06-26, Tuesday>···<from: Hans Hagen>···

> On 25-6-2012 16:50, Philipp Gesang wrote:
> >···<date: 2012-06-25, Monday>···<from: Hans Hagen>···
> >
> >>On 25-6-2012 15:39, Philipp Gesang wrote:
> >>
> >>>   - Does the difference wrt node subtype matter assuming I only
> >>>     (a) copy glyph nodes and (b) manipulate their .char field?
> >>
> >>not that much, it's just a state signal for font processing
> >
> >Good to know.
> >
> >>>Any insights on this matter would be greatly appreciated. Regards
> >>>Philipp
> >>
> >>it all depends on what you want to do
> >
> >Traverse the node list of a paragraph before line break from head
> >to tail in sequential order, recursing into sublists where they
> >appear. The callback removes and inserts nodes: which ones
> >depends on the nodes already processed (has a state).
> >
> >Using the previous example code,
> >
> >   \startfoo
> >     a\hbox{b}c
> >   \stopfoo
> >
> >should result in the traversal <glyph a>, <hlist ...>, <glyph c>.
> 
> \starttext
> 
> \startluacode
> 
> local function processnestedlist(head,n)
>     local current, done = head, false
>     while current do
>         local id = current.id
>         if id == nodes.nodecodes.hlist or id == nodes.nodecodes.vlist then
>             local _, d = processnestedlist(current.list,n)
>             if d then
>                 done = true
>             end
>         elseif id == nodes.nodecodes.hglue_code and current.leader then
>             local _, d = processnestedlist(current.leader,n)
>             if d then
>                 done = true
>             end
>         elseif id == nodes.nodecodes.glyph then -- todo: dics nodes
>             n = n + 1
>             print(n,utf.char(current.char))
>         end
>         current = current.next
>     end
>     return head, done, n
> end
> 
> 
> thirddata      = thirddata      or {}
> thirddata.test = thirddata.test or { }
> 
> thirddata.test.one = function(head)
>     local head, done, n = processnestedlist(head,0)
>     print("n of glyphs",n)
>     return head, done
> end
> 
> nodes.tasks.appendaction ("processors","before","thirddata.test.one")
> 
> \stopluacode
> 
> \ruledhbox to 10cm {\strut hello \ruledhbox{brave new} world
> \cleaders\hbox{!}\hfil}
> 
> \stoptext

First of all, thanks for the snippet. It’s insightful already wrt
to the fact that nodes.installattributehandler is considered
unnecessary. But the problem persists. With the code

  a\hbox{b}c

I get the following output:

  1   b
  n of glyphs 1
  1   a
  2   b
  2   c
  n of glyphs 2

So the sequence is <char b>, <char a>, <char b>, <char c> where
it should be <char a>, <char b>, <char c> --- the hbox is still
processed first, which I was attempting to avoid. (Also, the
invisible string “context” follows if the callback is active
until the end of file.)

Regards
Philipp


> 
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
>                                              | www.pragma-pod.nl
> -----------------------------------------------------------------
> 
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [callbacks] proper registration, node subtypes
  2012-06-26 12:08       ` Philipp Gesang
@ 2012-06-26 12:50         ` Hans Hagen
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2012-06-26 12:50 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 26-6-2012 14:08, Philipp Gesang wrote:
> ···<date: 2012-06-26, Tuesday>···<from: Hans Hagen>···
>
>> On 25-6-2012 16:50, Philipp Gesang wrote:
>>> ···<date: 2012-06-25, Monday>···<from: Hans Hagen>···
>>>
>>>> On 25-6-2012 15:39, Philipp Gesang wrote:
>>>>
>>>>>    - Does the difference wrt node subtype matter assuming I only
>>>>>      (a) copy glyph nodes and (b) manipulate their .char field?
>>>>
>>>> not that much, it's just a state signal for font processing
>>>
>>> Good to know.
>>>
>>>>> Any insights on this matter would be greatly appreciated. Regards
>>>>> Philipp
>>>>
>>>> it all depends on what you want to do
>>>
>>> Traverse the node list of a paragraph before line break from head
>>> to tail in sequential order, recursing into sublists where they
>>> appear. The callback removes and inserts nodes: which ones
>>> depends on the nodes already processed (has a state).
>>>
>>> Using the previous example code,
>>>
>>>    \startfoo
>>>      a\hbox{b}c
>>>    \stopfoo
>>>
>>> should result in the traversal <glyph a>, <hlist ...>, <glyph c>.
>>
>> \starttext
>>
>> \startluacode
>>
>> local function processnestedlist(head,n)
>>      local current, done = head, false
>>      while current do
>>          local id = current.id
>>          if id == nodes.nodecodes.hlist or id == nodes.nodecodes.vlist then
>>              local _, d = processnestedlist(current.list,n)
>>              if d then
>>                  done = true
>>              end
>>          elseif id == nodes.nodecodes.hglue_code and current.leader then
>>              local _, d = processnestedlist(current.leader,n)
>>              if d then
>>                  done = true
>>              end
>>          elseif id == nodes.nodecodes.glyph then -- todo: dics nodes
>>              n = n + 1
>>              print(n,utf.char(current.char))
>>          end
>>          current = current.next
>>      end
>>      return head, done, n
>> end
>>
>>
>> thirddata      = thirddata      or {}
>> thirddata.test = thirddata.test or { }
>>
>> thirddata.test.one = function(head)
>>      local head, done, n = processnestedlist(head,0)
>>      print("n of glyphs",n)
>>      return head, done
>> end
>>
>> nodes.tasks.appendaction ("processors","before","thirddata.test.one")
>>
>> \stopluacode
>>
>> \ruledhbox to 10cm {\strut hello \ruledhbox{brave new} world
>> \cleaders\hbox{!}\hfil}
>>
>> \stoptext
>
> First of all, thanks for the snippet. It’s insightful already wrt
> to the fact that nodes.installattributehandler is considered
> unnecessary. But the problem persists. With the code
>
>    a\hbox{b}c
>
> I get the following output:
>
>    1   b
>    n of glyphs 1
>    1   a
>    2   b
>    2   c
>    n of glyphs 2
>
> So the sequence is <char b>, <char a>, <char b>, <char c> where
> it should be <char a>, <char b>, <char c> --- the hbox is still
> processed first, which I was attempting to avoid. (Also, the
> invisible string “context” follows if the callback is active
> until the end of file.)

it all depends on what callback you use ... you can try a finalizer 
instead of a processor as processors normally are called once

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-26 12:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-25 13:39 [callbacks] proper registration, node subtypes Philipp Gesang
2012-06-25 14:21 ` Hans Hagen
2012-06-25 14:50   ` Philipp Gesang
2012-06-26 11:13     ` Hans Hagen
2012-06-26 12:08       ` Philipp Gesang
2012-06-26 12:50         ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).