Top Description Inners Fields Constructors Methods
org.python.core

public Class ParserFacade

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedReader, .ByteArrayInputStream, .IOException, .InputStream, .InputStreamReader, .Reader, .StringReader, java.nio.ByteBuffer, java.nio.charset.CharacterCodingException, .Charset, .CharsetDecoder, .CodingErrorAction, .UnsupportedCharsetException, java.util.regex.Matcher, .Pattern, org.antlr.runtime.CharStream, .CommonTokenStream, org.python.antlr.BaseParser, .NoCloseReaderStream, .ParseException, .PythonPartialLexer, .PythonPartialParser, .PythonTokenSource, .PythonTree, org.python.antlr.base.mod, org.python.core.io.StreamIO, .TextIOInputStream, .UniversalIOWrapper, org.python.core.util.StringUtil

Facade for the classes in the org.python.antlr package.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static int
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

true if a BOM was found and skipped.
adjustForBOM
(InputStream stream)

Check for a BOM mark at the beginning of stream.

private static void
private static String
encodingMap(String encoding)

private static String

Returns:

The declared encoding, or null if no encoding declaration is found
findEncoding
(BufferedReader br)

Reads the first two lines of the reader, searching for an encoding declaration.

public static PyException
private static String
private static String
private static mod
parse(ParserFacade.ExpectedEncodingBufferedReader reader, CompileMode kind, String filename, CompilerFlags cflags)

Internal parser entry point.

public static mod
parse(Reader reader, CompileMode kind, String filename, CompilerFlags cflags)

public static mod
parse(InputStream stream, CompileMode kind, String filename, CompilerFlags cflags)

public static mod
parse(String string, CompileMode kind, String filename, CompilerFlags cflags)

public static mod
parseExpressionOrModule(Reader reader, String filename, CompilerFlags cflags)

Parse Python source as either an expression (if possible) or module.

public static mod
partialParse(String string, CompileMode kind, String filename, CompilerFlags cflags, boolean stdprompt)

private static ParserFacade.ExpectedEncodingBufferedReader
prepBufReader(Reader reader, CompilerFlags cflags, String filename)

private static ParserFacade.ExpectedEncodingBufferedReader
prepBufReader(InputStream input, CompilerFlags cflags, String filename, boolean fromString)

private static ParserFacade.ExpectedEncodingBufferedReader
prepBufReader(InputStream input, CompilerFlags cflags, String filename, boolean fromString, boolean universalNewlines)

private static ParserFacade.ExpectedEncodingBufferedReader
prepBufReader(String string, CompilerFlags cflags, String filename)

private static String
private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MARK_LIMITback to summary
private static int MARK_LIMIT
pep263EncodingPatternback to summary
private static final Pattern pep263EncodingPattern

Constructor Detail

ParserFacadeback to summary
private ParserFacade()

Method Detail

adjustForBOMback to summary
private static boolean adjustForBOM(InputStream stream) throws IOException

Check for a BOM mark at the beginning of stream. If there is a BOM mark, advance the stream passed it. If not, reset() to start at the beginning of the stream again. Only checks for EF BB BF right now, since that is all that CPython 2.5 Checks.

Returns:boolean

true if a BOM was found and skipped.

Exceptions
ParseException:
if only part of a BOM is matched.

closeback to summary
private static void close(BufferedReader reader)
encodingMapback to summary
private static String encodingMap(String encoding)
findEncodingback to summary
private static String findEncoding(BufferedReader br) throws IOException

Reads the first two lines of the reader, searching for an encoding declaration. Note that reseting the reader (if needed) is responsibility of the caller.

Returns:String

The declared encoding, or null if no encoding declaration is found

fixParseErrorback to summary
public static PyException fixParseError(ParserFacade.ExpectedEncodingBufferedReader reader, Throwable t, String filename)
getLineback to summary
private static String getLine(ParserFacade.ExpectedEncodingBufferedReader reader, int line)
matchEncodingback to summary
private static String matchEncoding(String inputStr)
parseback to summary
private static mod parse(ParserFacade.ExpectedEncodingBufferedReader reader, CompileMode kind, String filename, CompilerFlags cflags) throws Throwable

Internal parser entry point. Users of this method should call fixParseError on any Throwable thrown from it, to translate ParserExceptions into PySyntaxErrors or PyIndentationErrors.

parseback to summary
public static mod parse(Reader reader, CompileMode kind, String filename, CompilerFlags cflags)
parseback to summary
public static mod parse(InputStream stream, CompileMode kind, String filename, CompilerFlags cflags)
parseback to summary
public static mod parse(String string, CompileMode kind, String filename, CompilerFlags cflags)
parseExpressionOrModuleback to summary
public static mod parseExpressionOrModule(Reader reader, String filename, CompilerFlags cflags)

Parse Python source as either an expression (if possible) or module. Designed for use by a JSR 223 implementation: "the Scripting API does not distinguish between scripts which return values and those which do not, nor do they make the corresponding distinction between evaluating or executing objects." (SCR.4.2.1)

partialParseback to summary
public static mod partialParse(String string, CompileMode kind, String filename, CompilerFlags cflags, boolean stdprompt)
prepBufReaderback to summary
private static ParserFacade.ExpectedEncodingBufferedReader prepBufReader(Reader reader, CompilerFlags cflags, String filename) throws IOException
prepBufReaderback to summary
private static ParserFacade.ExpectedEncodingBufferedReader prepBufReader(InputStream input, CompilerFlags cflags, String filename, boolean fromString) throws IOException
prepBufReaderback to summary
private static ParserFacade.ExpectedEncodingBufferedReader prepBufReader(InputStream input, CompilerFlags cflags, String filename, boolean fromString, boolean universalNewlines) throws IOException
prepBufReaderback to summary
private static ParserFacade.ExpectedEncodingBufferedReader prepBufReader(String string, CompilerFlags cflags, String filename) throws IOException
readEncodingback to summary
private static String readEncoding(InputStream stream) throws IOException
validPartialSentenceback to summary
private static boolean validPartialSentence(BufferedReader bufreader, CompileMode kind, String filename)
org.python.core back to summary

private Class ParserFacade.ExpectedEncodingBufferedReader

extends BufferedReader
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final String
encoding

The encoding from the source file, or null if none was specified and ascii is being used.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.io.BufferedReader:
closelinesmarkmarkSupportedreadreadreadLinereadyresetskip

Field Detail

encodingback to summary
public final String encoding

The encoding from the source file, or null if none was specified and ascii is being used.

Constructor Detail

ExpectedEncodingBufferedReaderback to summary
public ExpectedEncodingBufferedReader(Reader in, String encoding)