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 8204343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:52:14+00:00 2026-06-07T07:52:14+00:00

When I get the token with these rules STRINGA : ” (options {greedy=false;}: ESC

  • 0

When I get the token with these rules

STRINGA :   '"' (options {greedy=false;}: ESC | .)* '"';
STRINGB :   '\'' (options {greedy=false;}: ESC | .)* '\'';

it ends up grabbing 'text' instead of just text. I can easily remove the ' and ' myself but was wondering how I can get ANTLR to remove it?

  • 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-06-07T07:52:17+00:00Added an answer on June 7, 2026 at 7:52 am

    You will need some custom code for that. Also, you shouldn’t be using a . (dot) inside the rule: you should explicitly define you want to match everything except a backslash (assuming that is what your ESQ starts with), a quote and line break chars probably.

    Something like this would do it:

    grammar T;
    
    parse
     : STRING EOF {System.out.println($STRING.text);}
     ;
    
    STRING
     : '"' (ESQ | ~('"' | '\\' | '\r' | '\n'))* '"'
       {
         String matched = getText();
         StringBuilder builder = new StringBuilder();
    
         for(int i = 1; i < matched.length() - 1; i++) {
           char ch = matched.charAt(i);
           if(ch == '\\') {
             i++;
             ch = matched.charAt(i);
             switch(ch) {
               case 'n': builder.append('\n'); break;
               case 't': builder.append('\t'); break;
               default: builder.append(ch); break;
             }
           }
           else {
             builder.append(ch);
           }
         }
    
         setText(builder.toString());
       }
     ;
    
    fragment ESQ
     : '\\' ('n' | 't' | '"' | '\\')
     ;
    

    If you now parse the input "tabs:'\t\t\t'\nquote:\"\nbackslash:\\", the following will be printed to the console:

    tabs:'         '
    quote:"
    backslash:\

    To keep the grammar clean, you could of course move the code in a custom method:

    grammar T;
    
    @lexer::members {
      private String fix(String str) {
        ...
      }
    }
    
    parse
     : STRING EOF {System.out.println($STRING.text);}
     ;
    
    STRING
     : '"' (ESQ | ~('"' | '\\' | '\r' | '\n'))* '"' {setText(fix(getText()));}
     ;
    
    fragment ESQ
     : '\\' ('n' | 't' | '"' | '\\')
     ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get device token in iPad for remote push notifications; registerForRemoteNotificationTypes is
I want to make call to authenticate user and get back token in json
The goal is to let users login via Twitter, get OAuth token and secret
I am editing a script, which authenticates to openstack keystone to get a token.
I'm writing an Android application, which uses AccountManager to get the token. From an
After I get the Auth token from https://www.google.com/accounts/ClientLogin do I need to send 1
I am trying to get the JQuery Token Input prepopulated. var assignUserJson=$('#assignUserJson').val(); console.log(assignUserJson); //[{id:1,name:Andrew},{id:3,name:John}]
I want to to get the access token from LinkedIn. First I send the
I'm finally able to get an Access Token, now I'm very confused as how
I am able to get access_token for multiple permissions like emails, contacts, docs, etc.

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.