Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6126463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:22:39+00:00 2026-05-23T16:22:39+00:00

I am creating a translator from my language into many (all?) other object oriented

  • 0

I am creating a translator from my language into many (all?) other object oriented languages. As part of the language I want to support being able to insert target language code sections into the file. This is actually rather similar to how Antlr supports actions in rules.

So I would like to be able to have the sections begin and end with curlies like this:

{ ...target lang code... }

The issue is that it is quite possible { … } can show up in the target language code so I need to be able match pairs of curlies.

What I want to be able to do is something like this fragment that I’ve pulled into its own grammar:

grammar target_lang_block;

options
{
    output = AST;
}

entry   
    :   target_lang_block;

target_lang_block
    :   '{' target_lang_code* '}'
    ;


target_lang_code
    :   target_lang_block
    |   NO_CURLIES 
    ;       

WS
    :  (' ' | '\r' | '\t' | '\n')+ {$channel = HIDDEN;}
    ;

NO_CURLIES  
    :   ~('{'|'}')+
    ;

This grammar works by itself (at least to the extent I have tested it).

However, when I put these rules into the larger language, NO_CURLIES seems to eat everything and cause MismatchedTokenExceptions.

I’m not sure how to deal with this situation, but it seems that what I want is to be able to turn NO_CURILES on and off based on if I’m in target_lang_block, but it does not seem that is possible.

Is it possible? Is there another way?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:22:39+00:00Added an answer on May 23, 2026 at 4:22 pm

    Handle the target_lang_block inside the lexer instead:

    Target_lang_block
      :  '{' (~('{' | '}') | Target_lang_block)* '}'
      ;
    

    And remove NO_CURLIES, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get a type of a BasePage object that I am creating.
I'm running through an XML document, selecting all the elements, and creating links based
I've created a category to help me deal with creating dates from year, month,
I am creating Grid elements dynamically onto a stack panel. When an object is
I'm trying to get into generating 3D graphics in F# (as was apparent from
When creating Active Directory users from a script, I also need to set the
I'm following Steve Sanderson's example from this ASP.NET MVC book on creating a model
I observed some unexpected behavior with TTLauncherView from Three20. After creating a standard view
After creating a div on the fly with this markup: $('.circuit').prepend(<div class='component' draggable='true'>TRANSISTOR</div>); It
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.