001/*
002 * Anarres C Preprocessor
003 * Copyright (c) 2007-2015, Shevek
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014 * or implied.  See the License for the specific language governing
015 * permissions and limitations under the License.
016 */
017package org.anarres.cpp;
018
019import java.io.StringReader;
020
021/**
022 * A Source for lexing a String.
023 *
024 * This class is used by token pasting, but can be used by user
025 * code.
026 */
027public class StringLexerSource extends LexerSource {
028
029    /**
030     * Creates a new Source for lexing the given String.
031     *
032     * @param string The input string to lex.
033     * @param ppvalid true if preprocessor directives are to be
034     *  honoured within the string.
035     */
036    public StringLexerSource(String string, boolean ppvalid) {
037        super(new StringReader(string), ppvalid);
038    }
039
040    /**
041     * Creates a new Source for lexing the given String.
042     *
043     * Equivalent to calling <code>new StringLexerSource(string, false)</code>.
044     *
045     * By default, preprocessor directives are not honoured within
046     * the string.
047     *
048     * @param string The input string to lex.
049     */
050    public StringLexerSource(String string) {
051        this(string, false);
052    }
053
054    @Override
055    public String toString() {
056        return "string literal";
057    }
058}