Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.7
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      2

      Description

      A visitor class that prints out the AST types. Useful when learning about the compiler and writing custom macros or attributes.

      Additionally you could show the AST tree after each compiler step to visually show what each step did (you might use a "diff" tool to show differences between the tree at each step).

      1. astgen.boo
        20 kB
        Doug H
      2. astserialize.patch
        2 kB
        Doug H

        Activity

        Hide
        Doug H added a comment -

        It looks like just a simple change was needed to make this work. Other changes can be made to make the xml output prettier. And you can create xslt to make it compatible with other AST representations out there like JavaML or .NET CodeDom, or do things like transfer the AST XML back into boo code.

        Changes:

        • In boo.lang.compiler/ast/node.cs, add an [System.Xml.Serialization.XmlIgnore] above the Entity property (line 95). (otherwise you get an error because an interface type (IEntity) can't be serialized)
        • Add this to boo.lang.compiler/ast/statement.cs
          [System.Xml.Serialization.XmlInclude(typeof(MacroStatement))]

        Optional to make the XML a little prettier:

        • Insert this at line 255 in scripts/astgen.boo:
          if field.Name == "Name":
          writer.WriteLine("""
          [System.Xml.Serialization.XmlAttribute]""")
        • Add an [System.Xml.Serialization.XmlAttribute] or [System.Xml.Serialization.XmlIgnore] above the IsSynthetic property in Node.cs.

        I'll post a note to boo-dev with a sample script and its output.

        Show
        Doug H added a comment - It looks like just a simple change was needed to make this work. Other changes can be made to make the xml output prettier. And you can create xslt to make it compatible with other AST representations out there like JavaML or .NET CodeDom, or do things like transfer the AST XML back into boo code. Changes: In boo.lang.compiler/ast/node.cs, add an [System.Xml.Serialization.XmlIgnore] above the Entity property (line 95). (otherwise you get an error because an interface type (IEntity) can't be serialized) Add this to boo.lang.compiler/ast/statement.cs [System.Xml.Serialization.XmlInclude(typeof(MacroStatement))] Optional to make the XML a little prettier: Insert this at line 255 in scripts/astgen.boo: if field.Name == "Name": writer.WriteLine(""" [System.Xml.Serialization.XmlAttribute] """) Add an [System.Xml.Serialization.XmlAttribute] or [System.Xml.Serialization.XmlIgnore] above the IsSynthetic property in Node.cs. I'll post a note to boo-dev with a sample script and its output.
        Hide
        Rodrigo B. de Oliveira added a comment -

        Hi, Doug,

        Looks good to me. Can you provide a patch (diff) with the proposed changes?

        Best wishes,
        Rodrigo

        Show
        Rodrigo B. de Oliveira added a comment - Hi, Doug, Looks good to me. Can you provide a patch (diff) with the proposed changes? Best wishes, Rodrigo
        Hide
        Doug H added a comment -

        Right after I uploaded the patch, I realized I forgot to change writer.WriteLine to writer.Write in astgen.boo. Otherwise there is an extra (harmless) line break after the attribute.

        + if field.Name == "Name":
        + writer.Write("""
        + [System.Xml.Serialization.XmlAttribute]""")
        +

        Show
        Doug H added a comment - Right after I uploaded the patch, I realized I forgot to change writer.WriteLine to writer.Write in astgen.boo. Otherwise there is an extra (harmless) line break after the attribute. + if field.Name == "Name": + writer.Write(""" + [System.Xml.Serialization.XmlAttribute] """) +
        Hide
        Doug H added a comment -

        Here is my copy of astgen.boo to make a few other improvements to the xml output, like printing out the modifiers of a class or method (i.e. private, public, abstract...).

        Also I made this one other change:

        • In node.cs, add an [System.ComponentModel.DefaultValue(false)] attribute above the IsSynthetic property to suppress all those issynthetic values in the xml output.
        Show
        Doug H added a comment - Here is my copy of astgen.boo to make a few other improvements to the xml output, like printing out the modifiers of a class or method (i.e. private, public, abstract...). Also I made this one other change: In node.cs, add an [System.ComponentModel.DefaultValue(false)] attribute above the IsSynthetic property to suppress all those issynthetic values in the xml output.
        Hide
        Doug H added a comment -

        You also need to add this line to Boo.Lang.Compiler/Ast/Expression.cs:

        [System.Xml.Serialization.XmlInclude(typeof(TypeofExpression))]

        Show
        Doug H added a comment - You also need to add this line to Boo.Lang.Compiler/Ast/Expression.cs: [System.Xml.Serialization.XmlInclude(typeof(TypeofExpression))]

          People

          • Assignee:
            Unassigned
            Reporter:
            Doug H
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: