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);
            }
Esempio n. 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;
 }
Esempio n. 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)
         );
     }
 }
Esempio n. 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;
                }
            }
Esempio n. 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++;
                }
            }
Esempio n. 9
0
 int? IMatch.Match(SourcePosn sourcePosn)
     => _func(sourcePosn.Current) != _isTrue ? null : (int?) 1;
Esempio n. 10
0
 int? IMatch.Match(SourcePosn sourcePosn)
 {
     var result = _data.Match(sourcePosn);
     return result == null ? 1 : (int?) null;
 }
Esempio n. 11
0
 int? IMatch.Match(SourcePosn sourcePosn)
 {
     var result = _data.Length;
     return sourcePosn.StartsWith(_data) ? (int?) result : null;
 }
Esempio n. 12
0
 int? WhiteSpace(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _whiteSpace);
Esempio n. 13
0
 public Exception(SourcePosn sourcePosn, IError error)
 {
     SourcePosn = sourcePosn;
     Error = error;
 }
Esempio n. 14
0
 internal int? Any(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _any);
Esempio n. 15
0
 internal int? Text(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _text);
Esempio n. 16
0
 internal int? Number(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _number);
Esempio n. 17
0
 int? IMatch.Match(SourcePosn sourcePosn)
     => _data.Match(sourcePosn) ?? _other.Match(sourcePosn);
Esempio n. 18
0
 int? IMatch.Match(SourcePosn sourcePosn)
     => _data.Contains(sourcePosn.Current) ? (int?) 1 : null;
Esempio n. 19
0
 int? IMatch.Match(SourcePosn sourcePosn) => sourcePosn.IsEnd ? 0 : (int?) null;
Esempio n. 20
0
 int? LineEnd(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineEnd);
Esempio n. 21
0
 public int? Match(SourcePosn sourcePosn)
 {
     Tracer.TraceBreak();
     return 0;
 }
Esempio n. 22
0
 public Exception(SourcePosn sourcePosn, IScannerTokenType syntaxError)
 {
     SourcePosn = sourcePosn;
     SyntaxError = syntaxError;
 }
Esempio n. 23
0
 int? IMatch.Match(SourcePosn sourcePosn) => _data.Match(sourcePosn);
Esempio n. 24
0
 internal Worker(TwoLayerScanner parent, SourcePosn sourcePosn)
 {
     Tracer.Assert(sourcePosn.IsValid);
     Parent = parent;
     SourcePosn = sourcePosn;
 }
Esempio n. 25
0
 int? Comment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _comment);
Esempio n. 26
0
 internal int? Number(SourcePosn sourcePosn) => sourcePosn.Match(_number);
Esempio n. 27
0
 IItem[] IScanner.GetNextTokenGroup(SourcePosn sourcePosn)
     => new Worker(this, sourcePosn).GetNextTokenGroup().ToArray();
Esempio n. 28
0
 internal int? WhiteSpace(SourcePosn sourcePosn) => sourcePosn.Match(_whiteSpaces);
Esempio n. 29
0
 int? LineComment(SourcePosn sourcePosn) => GuardedMatch(sourcePosn, _lineComment);
Esempio n. 30
0
 internal int? Any(SourcePosn sourcePosn) => sourcePosn.Match(_any);