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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:34:08+00:00 2026-05-22T03:34:08+00:00

I have the following token definition in my lexer defining a CharacterString (e.g. ‘abcd’):

  • 0

I have the following token definition in my lexer defining a CharacterString (e.g. ‘abcd’):

CharacterString:
  Apostrophe
  (Alphanumeric)*
  Apostrophe
;

Is it possible to ignore the two apostrophes to then be able to get the token string without them in the lexer (via $CharacterString.text->chars)?

I tried …

CharacterString:
  Apostrophe { $channel = HIDDEN; }
  (Alphanumeric)*
  Apostrophe { $channel = HIDDEN; }
;

… without success… This case does not even match my string anymore (e.g. ‘oiu’ will fail in the parser – Missmatched Set Exception).

Thank you 🙂

  • 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-22T03:34:09+00:00Added an answer on May 22, 2026 at 3:34 am

    The inline code {$channel=HIDDEN;} affects the entire CharacterString, so you can’t do it like the way you tried.

    You will need to add some custom code and remove the quotes yourself. Here’s a small C demo:

    grammar T;
    
    options {
      language=C;
    }
    
    parse
      :  (t=. {printf(">\%s<\n", $t.text->chars);})+ EOF
      ;
    
    CharacterString
      :  '\'' ~'\''* '\''
         {
           pANTLR3_STRING quoted = GETTEXT();
           SETTEXT(quoted->subString(quoted, 1, quoted->len-1));
         }
      ;
    
    Any
      :  .
      ;
    

    and a little test function:

    #include "TLexer.h"
    #include "TParser.h"
    
    int main(int argc, char *argv[])
    {
      pANTLR3_UINT8 fName = (pANTLR3_UINT8)"input.txt";
      pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
    
      if(input == NULL)
      {
        fprintf(stderr, "Failed to open file %s\n", (char *)fName);
        exit(1);
      }
    
      pTLexer lexer = TLexerNew(input);
    
      if(lexer == NULL)
      {
        fprintf(stderr, "Unable to create the lexer due to malloc() failure1\n");
        exit(1);
      }
    
      pANTLR3_COMMON_TOKEN_STREAM tstream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lexer));
    
      if(tstream == NULL)
      {
        fprintf(stderr, "Out of memory trying to allocate token stream\n");
        exit(1);
      }
    
      pTParser parser = TParserNew(tstream);
    
      if(parser == NULL)
      {
        fprintf(stderr, "Out of memory trying to allocate parser\n");
        exit(ANTLR3_ERR_NOMEM);
      }
    
      parser->parse(parser);
    
      parser->free(parser);   parser = NULL;
      tstream->free(tstream); tstream = NULL;
      lexer->free(lexer);     lexer = NULL;
      input->close(input);    input = NULL;
    
      return 0;
    }
    

    and the test input.txt file contains:

    'abc'
    

    If you now 1) generate the lexer and parser, 2) compile all .c source files, and 3) run main:

    # 1
    java -cp antlr-3.3.jar org.antlr.Tool T.g
    
    # 2
    gcc -Wall main.c TLexer.c TParser.c -l antlr3c -o main
    
    # 3
    ./main
    

    you’ll see that abc (without the quotes) is being printed to the console.

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

Sidebar

Related Questions

On my node.js server I have the following code: //Generate a token var token
I hope you can help... Let's assume I have following XML: <data> <token> <sessionId>12345</sessionId>
I have the following code. private void LoopThroughDependsIssues(JIRAOperations jiraOps, string jiraURL, string token, string
i have following in my url http://www.foo.com/?token=foo&tokenid=fooid now i want to get those token
I have the following class(prototipe): class Token { public: //members, etc. friend std::stringstream& operator<<
In ANTLR, I have a MismatchedTokenException with the following definition: type : IDENTIFIER ('<'
I have the following code: $.ajax({ headers: {'X-CSRF-Token': $('meta[name=csrf-token]').attr('content'), 'Content-Type': 'application/json; charset=utf-8'}, url:'/monitoring', type:'POST',
I have the following on a web servlet: EDITED: public String tryGoogleAuthentication(String auth_token){ HttpURLConnection
I have taken following array; to fill-up gallery: private Integer[] mImageIds = { R.drawable.one,
I have taken the following object as an example: var questions = { 1:

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.