public override object VisitDirective_new_line_or_sharp(CSharpPreprocessorParser.Directive_new_line_or_sharpContext context)
    {
        var tokens = context.GetTokens(103).ToList();

        List <string> data = new List <string>();

        foreach (var token in tokens)
        {
            var stopIndex  = token.Symbol.StopIndex;
            var outputText = string.Empty;

            for (int i = stopIndex + 1; i <= token.Symbol.InputStream.Size; i++)
            {
                if (token.Symbol.InputStream.GetText(new Interval(i, i)) == ";")
                {
                    break;
                }
                else
                {
                    outputText += token.Symbol.InputStream.GetText(new Interval(i, i));
                }
            }

            data.Add(outputText);
        }

        csharpValues.Add(new CSharpTokenValue {
            Token = tokens[0].GetText(), Value = new List <string>(data)
        });

        return(csharpValues);
    }
Exemple #2
0
        public List <CSharpTokenValue> ProcessUsings(StringBuilder text)
        {
            var result = new List <CSharpTokenValue>();

            try
            {
                ICharStream inputStream = new AntlrInputStream(text.ToString());
                CSharpLexer csharpLexer = new CSharpLexer(inputStream);

                CommonTokenStream        commonTokenStream = new CommonTokenStream(csharpLexer);
                CSharpPreprocessorParser csharpParser      = new CSharpPreprocessorParser(commonTokenStream);

                CSharpPreprocessorParser.Directive_new_line_or_sharpContext preprocessorContext = csharpParser.directive_new_line_or_sharp();

                CSharpPreprocessorParserVisitor visitor = new CSharpPreprocessorParserVisitor();
                visitor.Visit(preprocessorContext);

                result = visitor.csharpValues;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
            }
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CSharpPreprocessorParser.directive_new_line_or_sharp"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitDirective_new_line_or_sharp([NotNull] CSharpPreprocessorParser.Directive_new_line_or_sharpContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="CSharpPreprocessorParser.directive_new_line_or_sharp"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitDirective_new_line_or_sharp([NotNull] CSharpPreprocessorParser.Directive_new_line_or_sharpContext context)
 {
 }