ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Pretty Printing Python code
@ 2009-12-29 11:03 Erik Margraf
  2009-12-29 11:59 ` Hans Hagen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Erik Margraf @ 2009-12-29 11:03 UTC (permalink / raw)
  To: ntg-context


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

Hello all,
I wanted to typeset some Python code and stumbled across the
pretty printing feature of ConTeXt. So far, I think I've learned the
following:

   -- There's no pretty printer for python. Neither in MKII nor in MKIV
   -- The wiki has an example implementation for a python pretty printer
      for MKII, i guess.

I decided to play a little bit with pretty printing (maybe implement a
Python pretty printer on my own) and failed at the start ;-)
I tried the following:
  -- Copied the filename pret-lua.lua to pret-py.lua
  -- Added a print statement to verify that the respective lua
    code (pret-lua.lua, pret-py.lua) is actually called.
When I ran context on the file below, I could see that "pret-lua.lua"
had been called, but "pret-py.lua" had not.  I guess, I did wrong something
very fundamental.

Thanks in advance for any hint

Erik Margraf

[-- Attachment #1.2: Type: text/html, Size: 976 bytes --]

[-- Attachment #2: yyy.tex --]
[-- Type: application/x-tex, Size: 1513 bytes --]

[-- Attachment #3: Type: text/plain, Size: 486 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] 4+ messages in thread

* Re: Pretty Printing Python code
  2009-12-29 11:03 Pretty Printing Python code Erik Margraf
@ 2009-12-29 11:59 ` Hans Hagen
  2009-12-29 17:09 ` luigi scarso
  2009-12-29 17:34 ` luigi scarso
  2 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2009-12-29 11:59 UTC (permalink / raw)
  To: erik.margraf, mailing list for ConTeXt users, luigi.scarso

On 29-12-2009 12:03, Erik Margraf wrote:
> Hello all,
> I wanted to typeset some Python code and stumbled across the
> pretty printing feature of ConTeXt. So far, I think I've learned the
> following:
>
>     -- There's no pretty printer for python. Neither in MKII nor in MKIV
>     -- The wiki has an example implementation for a python pretty printer
>        for MKII, i guess.
>
> I decided to play a little bit with pretty printing (maybe implement a
> Python pretty printer on my own) and failed at the start ;-)
> I tried the following:
>    -- Copied the filename pret-lua.lua to pret-py.lua
>    -- Added a print statement to verify that the respective lua
>      code (pret-lua.lua, pret-py.lua) is actually called.
> When I ran context on the file below, I could see that "pret-lua.lua"
> had been called, but "pret-py.lua" had not.  I guess, I did wrong something
> very fundamental.

you need to post all relevant files

luigi is the python expert here so i'm sure he'll figure out what's wrong


Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 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] 4+ messages in thread

* Re: Pretty Printing Python code
  2009-12-29 11:03 Pretty Printing Python code Erik Margraf
  2009-12-29 11:59 ` Hans Hagen
@ 2009-12-29 17:09 ` luigi scarso
  2009-12-29 17:34 ` luigi scarso
  2 siblings, 0 replies; 4+ messages in thread
From: luigi scarso @ 2009-12-29 17:09 UTC (permalink / raw)
  To: erik.margraf, mailing list for ConTeXt users

On Tue, Dec 29, 2009 at 12:03 PM, Erik Margraf
<erik.margraf@googlemail.com> wrote:
> Hello all,
> I wanted to typeset some Python code and stumbled across the
> pretty printing feature of ConTeXt. So far, I think I've learned the
> following:
>
>    -- There's no pretty printer for python. Neither in MKII nor in MKIV
>    -- The wiki has an example implementation for a python pretty printer
>       for MKII, i guess.
>
> I decided to play a little bit with pretty printing (maybe implement a
> Python pretty printer on my own) and failed at the start ;-)
> I tried the following:
>   -- Copied the filename pret-lua.lua to pret-py.lua
>   -- Added a print statement to verify that the respective lua
>     code (pret-lua.lua, pret-py.lua) is actually called.
> When I ran context on the file below, I could see that "pret-lua.lua"
> had been called, but "pret-py.lua" had not.  I guess, I did wrong something
> very fundamental.
>
> Thanks in advance for any hint
>
> Erik Margraf
First, I have made some changes to  pret-py.lua

< if not modules then modules = { } end modules ['pret-lua'] = {
---
> if not modules then modules = { } end modules ['pret-py'] = {
17c17
< local visualizer = buffers.newvisualizer("lua")
---
> local visualizer = buffers.newvisualizer("py")
105c105
< local function flush_lua_word(state, word)
---
> local function flush_python_word(state, word)
196c196
<                         state = flush_lua_word(state,word)
---
>                         state = flush_python_word(state,word)
234c234
<                     state = flush_lua_word(state,word)
---
>                     state = flush_python_word(state,word)
242c242
<         state = flush_lua_word(state,word)
---
>         state = flush_python_word(state,word)

but  *no*  other changes related to python's grammar

Next I believe that PYTHON is better than PY

\setupcolors[state=start]
\definecolor[colorprettyone]  [r=.9, g=.0, b=.0] % red
\definecolor[colorprettytwo]  [r=.0, g=.8, b=.0] % green
\definecolor[colorprettythree][r=.0, g=.0, b=.9] % blue
\definecolor[colorprettyfour] [s=0.60]           % gray
\definecolor[colorprettyfive] [orange]


\definepalet[colorpretty]
            [prettyone=colorprettyone,
            prettytwo=colorprettytwo,
            prettythree=colorprettythree,
            prettyfour=colorprettyfour,
            prettyfive=colorprettyfive]
% Python listings

\definepalet      [PYcolorpretty] [colorpretty]
\setuptyping      [PYTHON]            [bodyfont=10pt,option=color]
\installprettytype[PYTHON]  [PY]
\definetyping     [PYTHON]            [option=PYTHON]


\starttext
\section{Python sample}
\startPYTHON
#!/usr/local/bin/python

import os.path, sys

# Just a comment
foo = os.environ.get('FOO')
bar = os.environ.get('BAR')

if foo:
    foo = os.path.realpath(foobar)
elif bar:
    bar = os.path.realpath(bar)
else:
    print >> sys.stderr, '''
    FOO or BAR need to be set!
    '''
\stopPYTHON
\stoptext

It seems the option=color  is setted by default to TEX

\setvalue{\??tp:\c!option:\v!color    }{\setupprettiesintype{TEX}%
                                        \let\obeycharacters\setupprettytype
                                        \let\obeytabs\ignoretabs}



-- 
luigi
___________________________________________________________________________________
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] 4+ messages in thread

* Re: Pretty Printing Python code
  2009-12-29 11:03 Pretty Printing Python code Erik Margraf
  2009-12-29 11:59 ` Hans Hagen
  2009-12-29 17:09 ` luigi scarso
@ 2009-12-29 17:34 ` luigi scarso
  2 siblings, 0 replies; 4+ messages in thread
From: luigi scarso @ 2009-12-29 17:34 UTC (permalink / raw)
  To: erik.margraf, mailing list for ConTeXt users

On Tue, Dec 29, 2009 at 12:03 PM, Erik Margraf
<erik.margraf@googlemail.com> wrote:
> Hello all,
> I wanted to typeset some Python code and stumbled across the
> pretty printing feature of ConTeXt. So far, I think I've learned the
> following:

Also
http://wiki.contextgarden.net/Verbatim_text
http://wiki.contextgarden.net/Custom_pretty_printer
-- 
luigi
___________________________________________________________________________________
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] 4+ messages in thread

end of thread, other threads:[~2009-12-29 17:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-29 11:03 Pretty Printing Python code Erik Margraf
2009-12-29 11:59 ` Hans Hagen
2009-12-29 17:09 ` luigi scarso
2009-12-29 17:34 ` luigi scarso

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).