|
using System;
using System.Collections.Generic;
namespace Bird.Recognizers
{
public class CCommentRecognizer : ICommentRecognizer
{
public static string[] Strings = new string[] { "//", "/*" };
public static string[] EndStrings = new string[] { "*/" };
public bool Process(CompilerState State, CodeString Code)
{
var File = Code.File;
var StringRecognizer = State.Language.Root.GetObject<StringRecognizer>();
var SkippingHandlers = new IResultSkippingHandler[] { StringRecognizer };
var Line = Code.Line;
while (Code.HasLine(Line))
{
var LineStr = Code.GetLine(Line);
var Result = LineStr.Find(Strings, Handlers: SkippingHandlers);
if (Result.Index == 0)
{
var Index = LineStr.Index + Result.Position;
var Length = LineStr.FirstLineLength - Result.Position;
File.RemoveCode(Index, Length, Line);
}
else if (Result.Index == 1)
{
var Index = LineStr.Index + Result.Position;
var Right = Code.Substring(LineStr.Index + Result.NextChar);
var EndRes = Right.Find(EndStrings);
if (EndRes.Position == -1)
{
State.Messages.Add(MessageId.DeficientExpr, Right.Substring(EndRes));
return false;
}
var Length = Right.Index + EndRes.NextChar - Index;
File.RemoveCode(Index, Length, Line);
}
Line++;
}
return true;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.