Loading ...
Sorry, an error occurred while loading the content.
 

pretty printing

Expand Messages
  • sasecp@wnt.sas.com
    I have an ANTLR java parser that I m using successfully, and I d like to add some pretty-printing capabilities to it. At the moment, the lexer throws away
    Message 1 of 4 , Mar 1, 1999
      I have an ANTLR java parser that I'm using successfully, and I'd like to add some pretty-printing capabilities to it. At the moment, the lexer throws away comments and whitespace, but I'd like to keep the comments and maybe some of the whitespace depending on user configuration. I'm wondering if there's a good hook that would allow me to not throw away the whitespace in the lexer, but deal with it in the parser somehow. I certainly don't want to modify every rule with information about where whitespace can occur. I will probably be adding actions to every rule to generate the text, I just don't want pollute the entire grammar.

      Is there a good way to do this?

      I'm using Antlr 2.5.0 with VC++ 5.0.

      Thanks,
      Ernest
    • Terence Parr
      ... 2.6.0 will have token streams that are perfect for this...not sure if Pete Wells will be able to get the C++ output updated soon and I m still working on
      Message 2 of 4 , Mar 1, 1999
        sasecp@... hath spoken:
        >From: sasecp@...
        >
        >I have an ANTLR java parser that I'm using successfully, and I'd like to add
        >some pretty-printing capabilities to it. At the moment, the lexer throws
        >away comments and whitespace, but I'd like to keep the comments and maybe
        >some of the whitespace depending on user configuration. I'm wondering if
        >there's a good hook that would allow me to not throw away the whitespace in
        >the lexer, but deal with it in the parser somehow. I certainly don't want
        >to modify every rule with information about where whitespace can occur. I
        >will probably be adding actions to every rule to generate the text, I just
        >don't want pollute the entire grammar.
        >
        >
        >
        >Is there a good way to do this?
        >
        >
        >
        >I'm using Antlr 2.5.0 with VC++ 5.0.

        2.6.0 will have token streams that are perfect for this...not sure if Pete
        Wells will be able to get the C++ output updated soon and I'm still working
        on doc.

        Terence
      • Cristian Amitroaie
        Hello guys, I am thinking about using antlr for pretty printing. Did anybody use another approach besides filling a TreeWalker with print actions? I looked
        Message 3 of 4 , Mar 30, 2004
          Hello guys,

          I am thinking about using antlr for pretty printing. Did anybody use another
          approach besides filling a TreeWalker with print actions?

          I looked over StringTemplate but it doesn't look like the thing I need. Do I
          miss something?

          Another thought I have is to use some "pretty" code snapshots that I may parse
          and learn from, instead of using misc controls in the app (dangling curleys,
          white space around "()", ...). Yet I still need to experiment this one.

          10x,
          Cristian
        • Monty Zukowski
          A tree walker is the main way I ve done it. You might get some mileage out of Terence s latest article on simple transformations -- Syntax Directed
          Message 4 of 4 , Mar 30, 2004
            A tree walker is the main way I've done it. You might get some mileage
            out of Terence's latest article on simple transformations -- "Syntax
            Directed TokenStream Rewriting"
            http://www.antlr.org/article/rewrite.engine/index.tml

            Monty

            On Mar 30, 2004, at 2:07 AM, Cristian Amitroaie wrote:

            > Hello guys,
            >
            > I am thinking about using antlr for pretty printing. Did anybody use
            > another
            > approach besides filling a TreeWalker with print actions?
            >
            > I looked over StringTemplate but it doesn't look like the thing I
            > need. Do I
            > miss something?
            >
            > Another thought I have is to use some "pretty" code snapshots that I
            > may parse
            > and learn from, instead of using misc controls in the app (dangling
            > curleys,
            > white space around "()", ...). Yet I still need to experiment this one.
            >
            > 10x,
            > Cristian
            >
            >
            >
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.