static void Advance(SourcePosn sourcePosn, int position) { var wasEnd = sourcePosn.IsEnd; sourcePosn.Position += position; if(wasEnd) sourcePosn.IsValid = false; }
int? IMatch.Match(SourcePosn sourcePosn) { var positionFactory = _error as IPositionExceptionFactory; if(positionFactory != null) throw positionFactory.Create(sourcePosn); throw new Match.Exception(sourcePosn, _error); }
int? IMatch.Match(SourcePosn sourcePosn) { var length = sourcePosn.Match(Target); if (length != null) OnMatch(sourcePosn.SubString(0, length.Value)); else OnMismatch?.Invoke(); return length; }
int? IMatch.Match(SourcePosn sourcePosn) { var result = _data.Match(sourcePosn); if(result == null) return null; var otherResult = _other.Match(sourcePosn + result.Value); if(otherResult == null) return null; return result.Value + otherResult.Value; }
public int? GuardedMatch(SourcePosn sourcePosn, IMatch match) { try { return sourcePosn.Match(match); } catch(Match.Exception exception) { throw new TwoLayerScanner.Exception ( exception.SourcePosn, Convert(exception.Error) ); } }
int? IMatch.Match(SourcePosn sourcePosn) { var current = sourcePosn.Clone; while(true) { var result = _data.Match(current); if(result != null) return current - sourcePosn + result; if(current.IsEnd) return null; current.Position += 1; } }
int? IMatch.Match(SourcePosn sourcePosn) { var length = _data.Match(sourcePosn); if(length == null) return null; var value = sourcePosn.SubString(0, length.Value); var funcResult = _func(value).Match(sourcePosn + length.Value); return funcResult == null ? null : length.Value + funcResult; }
int? IMatch.Match(SourcePosn sourcePosn) { var count = 0; var current = sourcePosn; while(true) { var result = current - sourcePosn; if(count == _maxCount) return result; var length = _data.Match(current); if(length == null) return count < _minCount ? null : (int?) result; if(current.IsEnd) return null; current += length.Value; count++; } }
int? IMatch.Match(SourcePosn sourcePosn) => _func(sourcePosn.Current) != _isTrue ? null : (int?) 1;
int? IMatch.Match(SourcePosn sourcePosn) { var result = _data.Match(sourcePosn); return result == null ? 1 : (int?) null; }
int? IMatch.Match(SourcePosn sourcePosn) { var result = _data.Length; return sourcePosn.StartsWith(_data) ? (int?) result : null; }
int? WhiteSpace(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _whiteSpace);
public Exception(SourcePosn sourcePosn, IError error) { SourcePosn = sourcePosn; Error = error; }
internal int? Any(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _any);
internal int? Text(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _text);
internal int? Number(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _number);
int? IMatch.Match(SourcePosn sourcePosn) => _data.Match(sourcePosn) ?? _other.Match(sourcePosn);
int? IMatch.Match(SourcePosn sourcePosn) => _data.Contains(sourcePosn.Current) ? (int?) 1 : null;
int? IMatch.Match(SourcePosn sourcePosn) => sourcePosn.IsEnd ? 0 : (int?) null;
int? LineEnd(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineEnd);
public int? Match(SourcePosn sourcePosn) { Tracer.TraceBreak(); return 0; }
public Exception(SourcePosn sourcePosn, IScannerTokenType syntaxError) { SourcePosn = sourcePosn; SyntaxError = syntaxError; }
int? IMatch.Match(SourcePosn sourcePosn) => _data.Match(sourcePosn);
internal Worker(TwoLayerScanner parent, SourcePosn sourcePosn) { Tracer.Assert(sourcePosn.IsValid); Parent = parent; SourcePosn = sourcePosn; }
int? Comment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _comment);
internal int? Number(SourcePosn sourcePosn) => sourcePosn.Match(_number);
IItem[] IScanner.GetNextTokenGroup(SourcePosn sourcePosn) => new Worker(this, sourcePosn).GetNextTokenGroup().ToArray();
internal int? WhiteSpace(SourcePosn sourcePosn) => sourcePosn.Match(_whiteSpaces);
int? LineComment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineComment);
internal int? Any(SourcePosn sourcePosn) => sourcePosn.Match(_any);