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.InputStream; 020import java.io.InputStreamReader; 021import java.io.Reader; 022import java.nio.charset.Charset; 023import javax.annotation.Nonnull; 024 025/** 026 * A {@link Source} which lexes an {@link InputStream}. 027 * 028 * The input is buffered. 029 * 030 * @see Source 031 */ 032public class InputLexerSource extends LexerSource { 033 034 @Deprecated 035 public InputLexerSource(@Nonnull InputStream input) { 036 this(input, Charset.defaultCharset()); 037 } 038 039 /** 040 * Creates a new Source for lexing the given Reader. 041 * 042 * Preprocessor directives are honoured within the file. 043 */ 044 public InputLexerSource(@Nonnull InputStream input, Charset charset) { 045 this(new InputStreamReader(input, charset)); 046 } 047 048 public InputLexerSource(@Nonnull Reader input, boolean ppvalid) { 049 super(input, true); 050 } 051 052 public InputLexerSource(@Nonnull Reader input) { 053 this(input, true); 054 } 055 056 @Override 057 public String getPath() { 058 return "<standard-input>"; 059 } 060 061 @Override 062 public String getName() { 063 return "standard input"; 064 } 065 066 @Override 067 public String toString() { 068 return String.valueOf(getPath()); 069 } 070}