Example #1
0
        private Parser(Tokenizer tokenizer, ErrorSink errorSink, PythonLanguageVersion langVersion, bool verbatim, bool bindRefs, string privatePrefix) {
            Contract.Assert(tokenizer != null);
            Contract.Assert(errorSink != null);

            tokenizer.ErrorSink = new TokenizerErrorSink(this);

            _tokenizer = tokenizer;
            _errors = errorSink;
            _langVersion = langVersion;
            _verbatim = verbatim;
            _bindReferences = bindRefs;
            
            if (langVersion.Is3x()) {
                // 3.x always does true division and absolute import
                _languageFeatures |= FutureOptions.TrueDivision | FutureOptions.AbsoluteImports;
            }

            Reset(FutureOptions.None);

            _privatePrefix = privatePrefix;
        }
Example #2
0
        public void Reset(FutureOptions languageFeatures) {
            _languageFeatures = languageFeatures;
            _token = new TokenWithSpan();
            _lookahead = new TokenWithSpan();
            _fromFutureAllowed = true;
            _classDepth = 0;
            _functions = null;
            _privatePrefix = null;

            _parsingStarted = false;
            _errorCode = 0;
        }
Example #3
0
 override public Future <TResult> Start(FutureOptions options)
 {
     return(new Future <TResult>(this._byusingsupervised, options));
 }
Example #4
0
        private bool ProcessFutureStatements(int start, NameExpression/*!*/[] names, bool fromFuture) {
            if (!_fromFutureAllowed) {
                ReportSyntaxError(start, GetEnd(), "from __future__ imports must occur at the beginning of the file");
            }
            if (names.Length == 1 && names[0].Name == "*") {
                ReportSyntaxError(start, GetEnd(), "future statement does not support import *");
            }
            fromFuture = true;
            foreach (var name in names) {
                if (name.Name == "nested_scopes") {

                    // v2.4
                } else if (name.Name == "division") {
                    _languageFeatures |= FutureOptions.TrueDivision;
                } else if (name.Name == "generators") {

                    // v2.5:
                } else if (_langVersion >= PythonLanguageVersion.V25 && name.Name == "with_statement") {
                    _languageFeatures |= FutureOptions.WithStatement;
                    _tokenizer.WithStatement = true;
                } else if (_langVersion >= PythonLanguageVersion.V25 && name.Name == "absolute_import") {
                    _languageFeatures |= FutureOptions.AbsoluteImports;

                    // v2.6:
                } else if (_langVersion >= PythonLanguageVersion.V26 && name.Name == "print_function") {
                    _languageFeatures |= FutureOptions.PrintFunction;
                    _tokenizer.PrintFunction = true;
                } else if (_langVersion >= PythonLanguageVersion.V26 && name.Name == "unicode_literals") {
                    _tokenizer.UnicodeLiterals = true;
                    _languageFeatures |= FutureOptions.UnicodeLiterals;

                    // v3.5:
                } else if (_langVersion >= PythonLanguageVersion.V35 && name.Name == "generator_stop") {
                    // No behavior change, but we don't want to display an error
                } else {
                    string strName = name.Name;

                    if (strName != "braces") {
                        ReportSyntaxError(start, GetEnd(), "future feature is not defined: " + strName);
                    } else {
                        // match CPython error message
                        ReportSyntaxError(start, GetEnd(), "not a chance");
                    }
                }
            }
            return fromFuture;
        }
Example #5
0
 virtual public Future <TResult> Start(FutureOptions options)
 {
     return(new Future <TResult>(this._byusing, options));
 }