Stefan Falk
Stefan Falk

Reputation: 25367

ANTLR v4 C# : parser::using{ }

I can't find something like that

@parser::using
{
    using System;
    using System.Collections.Generic;
    // ..
}

to generate my parser. Does anybody know how I can include such using lines into my parser?

I need this e.g. for a Dictionary:

@parser::members
{
    protected Dictionary<String, String> m_myDictionary= new Dictionary<String, String>();
}

And I don't want to write the whole namespacefor all objects all the time ..

Upvotes: 1

Views: 151

Answers (1)

Sam Harwell
Sam Harwell

Reputation: 99859

You can use

@parser::header
{
}

and/or this, depending on context.

@lexer::header
{
}

However, I recommend not using this construct, and instead moving all of the C# code to a listener or visitor that executes after the parsing is complete.

Upvotes: 1

Related Questions