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

  • Home
  • SEARCH
  • 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 7699979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:36:08+00:00 2026-05-31T22:36:08+00:00

A Tcl nested String can be something like this: {abc {xyz foo {hello world}}}

  • 0

A Tcl nested String can be something like this:

{abc {xyz foo {hello world}}}

The braces above are used to enclose the content of string, they are not part of the string(Similar to double quotes). And they can be escaped using "\{" and "\}" to change string "foo" to "foo{}":

{abc {xyz foo\{\} {hello world}}}

I have a working lexical rule for the one without the brace escaping:

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

I am trying to find a way to add the escaping part while keeping the nested syntax, and haven’t succeeded so far.

  • 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-31T22:36:09+00:00Added an answer on May 31, 2026 at 10:36 pm

    Try this:

    NestedBraces
     : '{' (~('{' | '}' | '\\') | '\\' ('{' | '}') | NestedBraces)* '}'
     ;
    

    In the inner loop, you match:

    ~('{' | '}' | '\\')   // anything other than a '{', '}' and '\'
    |                     // OR
    '\\' ('{' | '}')      // an escaped '{' or '}' 
    |                     // OR
    NestedBraces          // recursive call: '{' ... '}'
    

    And if you want to strip the un-escaped braces from the tokens in one go, do something like this:

    NestedBraces
     : Helper {setText($text.replaceAll("\\\\(.)|[{}]", "$1"));}
     ;
    
    fragment Helper
     : '{' (~('{' | '}' | '\\') | '\\' ('{' | '}') | Helper)* '}'
     ;
    

    which will create a token with inner text "abc xyz foo{ hello world" for the input "{abc {xyz foo\{ {hello world}}}". Note that you need a helper rule: you can’t do the replacement and also the recursive call in one rule.

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

Sidebar

Related Questions

I'm learning Tcl. In Perl I can do this: $ perl -e 'for ($i
Working with TCL and I'd like to implement something like the Strategy Pattern .
I have used some TCL, but this construction stumps me. When $res = Table
I'm a complete beginner in the tcl/tk world, but I've tried to research this
I haven't used tcl before and just need to do one trick, I can
Tcl 8.4. I have this namespace tree: namespace eval menu_tree { #-------------------------------------------------------------------------- ## Main
I have a Tcl/Tk app that generates many forms and would like to be
How do I remove a tcl procedure? One can unset a variable, override an
I have a tcl script which 'exec' rpmbuild. When doing so, the 'topdir' used
I am learning TCL and wanted to know how can I find out errors

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.