예제 #1
0
        public static string AsString(this TokenSpan span, string source)
        {
            var sb = new StringBuilder(span.Size);

            var reader = new CharReader(source, span.Left, span.Size);

            switch (span.Token)
            {
            case Token.String:
                reader.MoveNext();

                while (reader.MoveNext() && reader.Current != '\'')
                {
                    sb.Append(reader.Current);
                }
                break;

            default:
                //should use reader here as above!!!
                //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                return(source.Substring(span.Left, span.Right - span.Left));
            }

            return(sb.ToString());
        }
예제 #2
0
            public TokenSpan Emit(Token type)
            {
                var token = TokenSpan.Of(type, Left, Right);

                Left = Right;

                return(token);
            }
예제 #3
0
        public static int AsInt(this TokenSpan span, string source)
        {
            span.Token.MustBe(Token.Number);

            var reader = new CharReader(source, span.Left, span.Size);

            int acc = 0;

            while (reader.MoveNext())
            {
                acc *= 10;
                acc += reader.Current.DecodeAsDecimal();
            }

            return(acc);
        }
예제 #4
0
 public static bool Match(this TokenSpan span, string from, string comp)
 => string.Compare(from, span.Left, comp, 0, span.Right - span.Left) == 0;