コード例 #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);
        }