本文整理汇总了C#中ISourceStream.MatchSymbol方法的典型用法代码示例。如果您正苦于以下问题:C# ISourceStream.MatchSymbol方法的具体用法?C# ISourceStream.MatchSymbol怎么用?C# ISourceStream.MatchSymbol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISourceStream
的用法示例。
在下文中一共展示了ISourceStream.MatchSymbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryMatch
public override TokenAst TryMatch(CompilerContext context, ISourceStream source)
{
if (!source.MatchSymbol(_startSymbol, false)) return null;
source.Position += _startSymbol.Length;
while (!source.EOF())
{
int firstCharPos = source.Text.IndexOf(_endSymbol, source.Position);
if (firstCharPos < 0)
{
source.Position = source.Text.Length;
if (_isLineComment)
return TokenAst.Create(this, context, source.TokenStart, source.GetLexeme());
else
return Grammar.CreateSyntaxErrorToken(context, source.TokenStart, "Unclosed comment block");
}
source.Position = firstCharPos;
if (source.MatchSymbol(_endSymbol, false))
{
source.Position += _endSymbol.Length;
return TokenAst.Create(this, context, source.TokenStart, source.GetLexeme());
}
source.Position++;
}
throw new NotSupportedException();
}
示例2: TryMatch
public override Token TryMatch(CompilerContext context, ISourceStream source)
{
bool ignoreCase = !Grammar.CaseSensitive;
//Check starting symbol
if (!source.MatchSymbol(StartSymbol, ignoreCase)) return null;
//Find end symbol
source.Position += StartSymbol.Length;
while(!source.EOF()) {
int firstCharPos;
if (EndSymbols.Count == 1)
firstCharPos = source.Text.IndexOf(EndSymbols[0], source.Position);
else
firstCharPos = source.Text.IndexOfAny(_endSymbolsFirsts, source.Position);
if (firstCharPos < 0) {
source.Position = source.Text.Length;
if (_isLineComment) //if it is LineComment, it is ok to hit EOF without final line-break; just return all until end.
return Token.Create(this, context, source.TokenStart, source.GetLexeme());
else
return Grammar.CreateSyntaxErrorToken(context, source.TokenStart, "Unclosed comment block");
}
//We found a character that might start an end symbol; let's see if it is true.
source.Position = firstCharPos;
foreach (string endSymbol in EndSymbols)
if (source.MatchSymbol(endSymbol, ignoreCase)) {
//We found end symbol
source.Position += endSymbol.Length;
return Token.Create(this, context, source.TokenStart, source.GetLexeme());
}//if
source.Position++; //move to the next char and try again
}//while
return null; //never happens
}
示例3: BeginMatch
private bool BeginMatch(ParsingContext context, ISourceStream source)
{
//Check starting symbol
if (!source.MatchSymbol(StartSymbol)) return false;
source.PreviewPosition += StartSymbol.Length;
return true;
}
示例4: ReadBody
protected override string ReadBody(ParsingContext context, ISourceStream source) {
if (!source.MatchSymbol(StartSymbol)) return null; //this will result in null returned from TryMatch, no token
var start = source.Location.Position + StartSymbol.Length;
var end = source.Text.IndexOf(EndSymbol, start);
if (end < 0) return null;
var body = source.Text.Substring(start, end - start);
source.PreviewPosition = end + EndSymbol.Length; //move beyond the end of EndSymbol
return body;
}
示例5: TryMatchPrefixes
private bool TryMatchPrefixes(ParsingContext context, ISourceStream source) {
if (Firsts.Count == 0)
return true;
foreach (var first in Firsts)
if (source.MatchSymbol(first)) {
source.PreviewPosition += first.Length;
return true;
}
return false;
}
示例6: CheckEscape
private bool CheckEscape(ISourceStream source, ref string tokenText) {
foreach (var dictEntry in Escapes) {
if (source.MatchSymbol(dictEntry.Key, !Grammar.CaseSensitive)) {
source.PreviewPosition += dictEntry.Key.Length;
tokenText += dictEntry.Value;
return true;
}
}//foreach
return false;
}
示例7: TryMatch
public override TokenAst TryMatch(CompilerContext context, ISourceStream source)
{
if (!source.MatchSymbol(Symbol, false))
return null;
source.Position += Symbol.Length;
TokenAst tokenAst = TokenAst.Create(this, context, source.TokenStart, Symbol);
return tokenAst;
}
示例8: BeginMatch
private bool BeginMatch(ISourceStream source, int startFrom, char lookAhead) {
foreach (var startSymbol in StartSymbols.Skip(startFrom)) {
if (startSymbol[0] != lookAhead)
continue;
if (source.MatchSymbol(startSymbol, !Grammar.CaseSensitive)) {
source.PreviewPosition += startSymbol.Length;
return true;
}
}
return false;
}
示例9: BeginMatch
private bool BeginMatch(ParsingContext context, ISourceStream source, ref byte level)
{
if (!source.MatchSymbol(StartSymbol))
return false;
string text = source.Text.Substring(source.PreviewPosition + StartSymbol.Length);
var match = Regex.Match(text, @"^(=*)\[");
if(match.Value != string.Empty)
{
level = (byte)match.Groups[1].Value.Length;
return true;
}
return false;
}
示例10: TryMatch
public override Token TryMatch(ParsingContext context, ISourceStream source) {
if (!source.MatchSymbol(OpenTag, true)) return null;
source.PreviewPosition += OpenTag.Length;
var endPos = source.Text.IndexOf(CloseTag, source.PreviewPosition);
string content;
if(endPos > 0) {
content = source.Text.Substring(source.PreviewPosition, endPos - source.PreviewPosition);
source.PreviewPosition = endPos + CloseTag.Length;
} else {
content = source.Text.Substring(source.PreviewPosition, source.Text.Length - source.PreviewPosition);
source.PreviewPosition = source.Text.Length;
}
var token = source.CreateToken(this.OutputTerminal, content);
return token;
}
示例11: TryMatch
public override Token TryMatch(ParsingContext context, ISourceStream source) {
bool isHeadingOrList = TermType == WikiTermType.Heading || TermType == WikiTermType.List;
if(isHeadingOrList) {
bool isAfterNewLine = (context.PreviousToken == null || context.PreviousToken.Terminal == Grammar.NewLine);
if(!isAfterNewLine) return null;
}
if(!source.MatchSymbol(OpenTag)) return null;
source.PreviewPosition += OpenTag.Length;
//For headings and lists require space after
if(TermType == WikiTermType.Heading || TermType == WikiTermType.List) {
const string whitespaces = " \t\r\n\v";
if (!whitespaces.Contains(source.PreviewChar)) return null;
}
var token = source.CreateToken(this.OutputTerminal);
return token;
}
示例12: BeginMatch
private bool BeginMatch(ParsingContext context, ISourceStream source, ref byte level)
{
//Check starting symbol
if (!source.MatchSymbol(StartSymbol, !Grammar.CaseSensitive))
return false;
//Found starting --, now determine whether this is a long comment.
string text = source.Text.Substring(source.PreviewPosition + StartSymbol.Length);
var match = Regex.Match(text, @"^(=*)\[");
if(match.Value != string.Empty)
{
level = (byte)match.Groups[1].Value.Length;
return true;
}
return false;
}
示例13: Match_compile_end_tag
Token Match_compile_end_tag(Terminal terminal, ParsingContext context, ISourceStream source) {
if (source.MatchSymbol("__End")) {
var p = source.Location.Position;
var lineEnd = source.Text.IndexOf("\n", p);
var text = source.Text.Substring(p, lineEnd - p + 1);
return new Token(_comment, source.Location, text, text);
}
//otherwise return null
return null;
}
示例14: ReadStartSymbol
private bool ReadStartSymbol(ISourceStream source, ScanDetails details)
{
if (_startEndFirsts.IndexOf(source.CurrentChar) < 0)
return false;
bool ignoreCase = IsSet(TermOptions.SpecialIgnoreCase);
foreach (string startEnd in _startEndSymbols) {
if (!source.MatchSymbol(startEnd, ignoreCase))
continue;
//We found start symbol
details.ControlSymbol = startEnd;
details.Flags |= StartEndSymbolTable[startEnd];
source.Position += startEnd.Length;
return true;
}//foreach
return false;
}
示例15: CheckTerminators
private bool CheckTerminators(ISourceStream source, ref string tokenText) {
foreach(var term in Terminators)
if(source.MatchSymbol(term, !Grammar.CaseSensitive)) {
if (IsSet(FreeTextOptions.IncludeTerminator))
tokenText += term;
if (IsSet(FreeTextOptions.ConsumeTerminator | FreeTextOptions.IncludeTerminator))
source.PreviewPosition += term.Length;
return true;
}
return false;
}