예제 #1
0
파일: Scanner.cs 프로젝트: otac0n/Therefore
        private int Advance(string source, Span span)
        {
            var offset = span.Start + span.Length;

            while (offset < span.Length && char.IsWhiteSpace(source, offset))
            {
                offset++;
            }

            return offset;
        }
예제 #2
0
파일: Token.cs 프로젝트: otac0n/Therefore
        public Token(TokenType tokenType, string source, Span span)
        {
            this.tokenType = tokenType;

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            this.value = source.Substring(span.Start, span.Length);

            if (span == null)
            {
                throw new ArgumentNullException("span");
            }

            this.span = span;
        }
예제 #3
0
파일: Scanner.cs 프로젝트: otac0n/Therefore
        private Token Accept(TokenType tokenType, Cursor cursor)
        {
            var terminal = this.terminals[tokenType];
            var length = terminal(cursor.Source, cursor.Offset);
            if (length == null)
            {
                return null;
            }

            var span = new Span(cursor.Offset, length.Value);
            cursor.Offset = this.Advance(cursor.Source, span);

            return new Token(tokenType, cursor.Source, span);
        }