Exemple #1
0
 /// <summary>
 /// Returns a sequence of all keywords usable in an expression in a
 /// particular version of Python.
 /// </summary>
 public static IEnumerable<string> Expression(PythonLanguageVersion version = PythonLanguageVersion.None) {
     yield return "and";
     yield return "as";
     if (version.IsNone() || version >= PythonLanguageVersion.V35) {
         yield return "await";
     }
     yield return "else";
     if (version.IsNone() || version.Is3x()) {
         yield return "False";
     }
     yield return "for";
     if (version.IsNone() || version >= PythonLanguageVersion.V33) {
         yield return "from";
     }
     yield return "if";
     yield return "in";
     yield return "is";
     yield return "lambda";
     yield return "None";
     yield return "not";
     yield return "or";
     if (version.IsNone() || version.Is3x()) {
         yield return "True";
     }
     yield return "yield";
 }
        /// <summary>
        /// Returns a sequence of all keywords that are invalid outside of
        /// function definitions in a particular version of Python.
        /// </summary>
        public static IEnumerable <string> InvalidOutsideFunction(PythonLanguageVersion version = PythonLanguageVersion.None)
        {
            if (version.IsNone() || version >= PythonLanguageVersion.V35)
            {
                yield return("await");
            }
            yield return("return");

            if (version.IsNone() || version >= PythonLanguageVersion.V25)
            {
                yield return("yield");
            }
        }
Exemple #3
0
        /// <summary>
        /// Returns a sequence of all keywords usable in an expression in a
        /// particular version of Python.
        /// </summary>
        public static IEnumerable <string> Expression(PythonLanguageVersion version = PythonLanguageVersion.None)
        {
            yield return("and");

            yield return("as");

            if (version.IsNone() || version >= PythonLanguageVersion.V35)
            {
                yield return("await");
            }
            yield return("else");

            if (version.IsNone() || version.Is3x())
            {
                yield return("False");
            }
            yield return("for");

            if (version.IsNone() || version >= PythonLanguageVersion.V33)
            {
                yield return("from");
            }
            yield return("if");

            yield return("in");

            yield return("is");

            yield return("lambda");

            yield return("None");

            yield return("not");

            yield return("or");

            if (version.IsNone() || version.Is3x())
            {
                yield return("True");
            }
            yield return("yield");
        }
        /// <summary>
        /// Returns a sequence of all keywords usable in an expression in a
        /// particular version of Python.
        /// </summary>
        public static IEnumerable <string> Expression(PythonLanguageVersion version = PythonLanguageVersion.None)
        {
            yield return("and");

            yield return("as");

            if (version.IsNone() || version >= PythonLanguageVersion.V35)
            {
                yield return("await");
            }
            yield return("else");

            yield return("False");   // Not technically a keyword in Python 2.x, but may as well be

            yield return("for");

            if (version.IsNone() || version >= PythonLanguageVersion.V33)
            {
                yield return("from");
            }
            yield return("if");

            yield return("in");

            yield return("is");

            yield return("lambda");

            yield return("None");

            yield return("not");

            yield return("or");

            yield return("True");    // Not technically a keyword in Python 2.x, but may as well be

            yield return("yield");
        }
Exemple #5
0
 public static string GetTypeName(this BuiltinTypeId id, PythonLanguageVersion languageVersion)
 => id.GetTypeName(languageVersion.IsNone() || languageVersion.Is3x());
        /// <summary>
        /// Returns sequence of all keywords usable as a statement in a
        /// particular version of Python.
        /// </summary>
        public static IEnumerable <string> Statement(PythonLanguageVersion version = PythonLanguageVersion.None)
        {
            yield return("assert");

            if (version.IsNone() || version >= PythonLanguageVersion.V35)
            {
                yield return("async");

                yield return("await");
            }
            yield return("break");

            yield return("continue");

            yield return("class");

            yield return("def");

            yield return("del");

            if (version.IsNone() || version.Is2x())
            {
                yield return("exec");
            }
            yield return("if");

            yield return("elif");

            yield return("except");

            yield return("finally");

            yield return("for");

            yield return("from");

            yield return("global");

            yield return("import");

            if (version.IsNone() || version.Is3x())
            {
                yield return("nonlocal");
            }
            yield return("pass");

            if (version.IsNone() || version.Is2x())
            {
                yield return("print");
            }
            yield return("raise");

            yield return("return");

            yield return("try");

            yield return("while");

            yield return("with");

            yield return("yield");
        }
Exemple #7
0
 public static string GetModuleName(this BuiltinTypeId id, PythonLanguageVersion languageVersion)
 {
     return(id.GetModuleName(languageVersion.IsNone() || languageVersion.Is3x()));
 }
Exemple #8
0
 /// <summary>
 /// Returns a sequence of all keywords that are invalid outside of
 /// function definitions in a particular version of Python.
 /// </summary>
 public static IEnumerable<string> InvalidOutsideFunction(
     PythonLanguageVersion version = PythonLanguageVersion.None
 ) {
     if (version.IsNone() || version >= PythonLanguageVersion.V35) {
         yield return "await";
     }
     yield return "return";
     if (version.IsNone() || version >= PythonLanguageVersion.V25) {
         yield return "yield";
     }
 }
Exemple #9
0
 /// <summary>
 /// Retuns a sequence of all keywords usable as a statement in a
 /// particular version of Python.
 /// </summary>
 public static IEnumerable<string> Statement(PythonLanguageVersion version = PythonLanguageVersion.None) {
     yield return "assert";
     if (version.IsNone() || version >= PythonLanguageVersion.V35) {
         yield return "async";
         yield return "await";
     }
     yield return "break";
     yield return "continue";
     yield return "class";
     yield return "def";
     yield return "del";
     if (version.IsNone() || version.Is2x()) {
         yield return "exec";
     }
     yield return "if";
     yield return "elif";
     yield return "except";
     yield return "finally";
     yield return "for";
     yield return "from";
     yield return "global";
     yield return "import";
     if (version.IsNone() || version.Is3x()) {
         yield return "nonlocal";
     }
     yield return "pass";
     if (version.IsNone() || version.Is2x()) {
         yield return "print";
     }
     yield return "raise";
     yield return "return";
     yield return "try";
     yield return "while";
     yield return "with";
     yield return "yield";
 }