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

camlp4: handling string constants

Expand Messages
  • Dmitry Bely
    I would like to create a simple camlp4 syntax extension that will substitute all string literals with some specific expression. Surprisingly is turn be a hard:
    Message 1 of 2 , Aug 25, 2011
      I would like to create a simple camlp4 syntax extension that will
      substitute all string literals with some specific expression.
      Surprisingly is turn be a hard: I cannot even replicate the standard
      parser behavior. The naive approach:

      DELETE_RULE Gram expr: a_STRING END;
      EXTEND Gram
      GLOBAL: expr;
      expr:
      [
      [ e = a_STRING -> <:expr< $str:e$ >>
      ] ];
      END

      transforms

      let _ = print_string "123"

      to

      let _ = print_string
      let _ = "123"

      Any idea what I am doing wrong?

      - Dmitry Bely
    • Dmitry Bely
      ... OK, figured it out myself. For the record: LEVEL simple should be added to expr: - Dmitry Bely
      Message 2 of 2 , Aug 26, 2011
        On Thu, Aug 25, 2011 at 4:07 PM, Dmitry Bely <dmitry.bely@...> wrote:
        >
        > I would like to create a simple camlp4 syntax extension that will
        > substitute all string literals with some specific expression.
        > Surprisingly is turn be a hard: I cannot even replicate the standard
        > parser behavior. The naive approach:
        >
        > DELETE_RULE Gram expr: a_STRING END;
        > EXTEND Gram
        > GLOBAL: expr;
        > expr:
        > [
        > [ e = a_STRING -> <:expr< $str:e$ >>
        > ] ];
        > END
        >
        > transforms
        >
        > let _ = print_string "123"
        >
        > to
        >
        > let _ = print_string
        > let _ = "123"
        >
        > Any idea what I am doing wrong?

        OK, figured it out myself. For the record:

        LEVEL "simple" should be added to expr:

        - Dmitry Bely
      Your message has been successfully submitted and would be delivered to recipients shortly.