FAQ
Is there a way to invoke the Go compiler on an AST (as defined in 'go/ast')
instead of just on a file tree?

I'm trying to write a code rewriting tool that allows you to write Go using
keywords in other languages. I've successfully created an AST by wrapping a
scanner and transforming keywords as necessary, but given this AST, my only
option as I see it now is to write the transformed source back out to the
filesystem. This gets me most of the way, but it prevents me from allowing
variable or function or type names which are traditional keywords since I
have no way of transforming them that would maintain the semantics of the
program (so, for example, if I have a spanish-language Go in which "for"
isn't a keyword, you couldn't have a variable called "for").

Cheers,
Josh

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Robert Griesemer at Aug 31, 2014 at 7:54 pm
    No, there's no way to do that (invoke the compiler of an ast) at the
    moment. Russ is in the process of translating the gc Go compiler from C to
    Go, at which point it might be easier to make changes to the compiler since
    it's written in Go. And perhaps in the future, the Go compiler is going to
    use a (modified) version of the go/ast. But you could also change the
    existing C code to get the same effect.

    That said, why do you want to use keywords from other languages? There's
    only 25 of them, it's hardly going to make it easier for a non-English
    speaker to be able to use native-language keywords, and it will make it
    difficult for others to read that code.

    The usual mechanism for getting identifiers that are conflicting with
    keywords is to introduce a translation scheme. For instance, add _ after
    those identifiers: for -> for_, etc. This ways you can print the Go names
    for keywords, and conflicting identifiers get a special translation.

    - gri



    On Sat, Aug 30, 2014 at 2:46 PM, wrote:

    Is there a way to invoke the Go compiler on an AST (as defined in
    'go/ast') instead of just on a file tree?

    I'm trying to write a code rewriting tool that allows you to write Go
    using keywords in other languages. I've successfully created an AST by
    wrapping a scanner and transforming keywords as necessary, but given this
    AST, my only option as I see it now is to write the transformed source back
    out to the filesystem. This gets me most of the way, but it prevents me
    from allowing variable or function or type names which are traditional
    keywords since I have no way of transforming them that would maintain the
    semantics of the program (so, for example, if I have a spanish-language Go
    in which "for" isn't a keyword, you couldn't have a variable called "for").

    Cheers,
    Josh

    --
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Joshua Liebow-Feeser at Aug 31, 2014 at 8:10 pm
    There's no compelling reason - just for fun.

    As for the translation - that's definitely a possibility, although my
    concern there is that it would break reflection code that relied on
    variable names (assuming they were hard-coded as strings).

    On Sun, Aug 31, 2014 at 3:54 PM, Robert Griesemer wrote:

    No, there's no way to do that (invoke the compiler of an ast) at the
    moment. Russ is in the process of translating the gc Go compiler from C to
    Go, at which point it might be easier to make changes to the compiler since
    it's written in Go. And perhaps in the future, the Go compiler is going to
    use a (modified) version of the go/ast. But you could also change the
    existing C code to get the same effect.

    That said, why do you want to use keywords from other languages? There's
    only 25 of them, it's hardly going to make it easier for a non-English
    speaker to be able to use native-language keywords, and it will make it
    difficult for others to read that code.

    The usual mechanism for getting identifiers that are conflicting with
    keywords is to introduce a translation scheme. For instance, add _ after
    those identifiers: for -> for_, etc. This ways you can print the Go names
    for keywords, and conflicting identifiers get a special translation.

    - gri



    On Sat, Aug 30, 2014 at 2:46 PM, wrote:

    Is there a way to invoke the Go compiler on an AST (as defined in
    'go/ast') instead of just on a file tree?

    I'm trying to write a code rewriting tool that allows you to write Go
    using keywords in other languages. I've successfully created an AST by
    wrapping a scanner and transforming keywords as necessary, but given this
    AST, my only option as I see it now is to write the transformed source back
    out to the filesystem. This gets me most of the way, but it prevents me
    from allowing variable or function or type names which are traditional
    keywords since I have no way of transforming them that would maintain the
    semantics of the program (so, for example, if I have a spanish-language Go
    in which "for" isn't a keyword, you couldn't have a variable called "for").

    Cheers,
    Josh

    --
    You received this message because you are subscribed to the Google Groups
    "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedAug 31, '14 at 10:04a
activeAug 31, '14 at 8:10p
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase