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);
            }
Beispiel #3
0
 int? IMatch.Match(SourcePosn sourcePosn)
 {
     var length = sourcePosn.Match(Target);
     if (length != null)
         OnMatch(sourcePosn.SubString(0, length.Value));
     else
         OnMismatch?.Invoke();
     return length;
 }
Beispiel #4
0
            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)
         );
     }
 }
Beispiel #6
0
            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;
                }
            }
Beispiel #7
0
            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++;
                }
            }
Beispiel #9
0
 int? IMatch.Match(SourcePosn sourcePosn)
     => _func(sourcePosn.Current) != _isTrue ? null : (int?) 1;
Beispiel #10
0
 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;
 }
Beispiel #12
0
 int? WhiteSpace(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _whiteSpace);
Beispiel #13
0
 public Exception(SourcePosn sourcePosn, IError error)
 {
     SourcePosn = sourcePosn;
     Error = error;
 }
Beispiel #14
0
 internal int? Any(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _any);
Beispiel #15
0
 internal int? Text(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _text);
Beispiel #16
0
 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;
Beispiel #19
0
 int? IMatch.Match(SourcePosn sourcePosn) => sourcePosn.IsEnd ? 0 : (int?) null;
Beispiel #20
0
 int? LineEnd(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineEnd);
Beispiel #21
0
 public int? Match(SourcePosn sourcePosn)
 {
     Tracer.TraceBreak();
     return 0;
 }
 public Exception(SourcePosn sourcePosn, IScannerTokenType syntaxError)
 {
     SourcePosn = sourcePosn;
     SyntaxError = syntaxError;
 }
Beispiel #23
0
 int? IMatch.Match(SourcePosn sourcePosn) => _data.Match(sourcePosn);
 internal Worker(TwoLayerScanner parent, SourcePosn sourcePosn)
 {
     Tracer.Assert(sourcePosn.IsValid);
     Parent = parent;
     SourcePosn = sourcePosn;
 }
Beispiel #25
0
 int? Comment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _comment);
Beispiel #26
0
 internal int? Number(SourcePosn sourcePosn) => sourcePosn.Match(_number);
 IItem[] IScanner.GetNextTokenGroup(SourcePosn sourcePosn)
     => new Worker(this, sourcePosn).GetNextTokenGroup().ToArray();
Beispiel #28
0
 internal int? WhiteSpace(SourcePosn sourcePosn) => sourcePosn.Match(_whiteSpaces);
Beispiel #29
0
 int? LineComment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineComment);
Beispiel #30
0
 internal int? Any(SourcePosn sourcePosn) => sourcePosn.Match(_any);