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

i have following in my url http://www.foo.com/?token=foo&tokenid=fooid now i want to get those token
Say I have the following XML: <root> <tokens> <token ID=t1>blah</token> <token ID=t2>blabla</token> <token ID=t3>shovel</token>
I have the following code: CancellationTokenSource cancelSource = new CancellationTokenSource(); _cancelTokenList.Add(cancelSource); CancellationToken token =
I have the following access token: 161551960578281 |2.AQDCjxLBWAwdLle6.3600.1311602400.0- 544419103231 |0L0tcyKgGA0WT3SPJ29CVXqChwk From this access_token: App_id
I have the following code: token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost:3000') response = token.get('https://api.foursquare.com/v2/users/self/checkins',
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party

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.