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