# SYNTAX TEST "Packages/Python/Python.sublime-syntax" ############################### # Strings and embedded syntaxes ############################### var = "\x00 \xaa \xAF \070 \r \n \t \\ \a \b \' \v \f \u0aF1 \UFe0a182f \N{SPACE}" # ^ meta.string.python # ^^^^ constant.character.escape.hex # ^^^^ constant.character.escape.hex # ^^^^ constant.character.escape.hex # ^^^^ constant.character.escape.octal # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^ constant.character.escape # ^^^^^^ constant.character.escape.unicode # ^^^^^^^^^^ constant.character.escape.unicode # ^^^^^^^^^ constant.character.escape.unicode conn.execute("SELECT * FROM foobar") # ^ meta.string.python keyword.other.DML.sql conn.execute('SELECT * FROM foobar') # ^ keyword.other.DML.sql conn.execute(U"SELECT * FROM foobar") # ^ keyword.other.DML.sql conn.execute(U'SELECT * FROM foobar') # ^ keyword.other.DML.sql # In this example, the Python string is not raw, so \t is a python escape conn.execute(u"SELECT * FROM foobar WHERE foo = '\t'") # ^ keyword.other.DML.sql # ^ constant.character.escape.python conn.execute(u'SELECT * FROM foobar') # ^ keyword.other.DML.sql # In this example, the Python string is raw, so the \b should be a SQL escape conn.execute(r"SELECT * FROM foobar WHERE baz = '\b") # ^ meta.string.python keyword.other.DML.sql # ^ constant.character.escape.sql # This tests to ensure the Python placeholder will be highlighted even in a raw SQL string conn.execute(r'SELECT * FROM foobar WHERE %s') # ^ keyword.other.DML.sql # ^ constant.other.placeholder.python conn.execute(r"SELECT * FROM foobar") # ^ keyword.other.DML.sql conn.execute(r'SELECT * FROM foobar') # ^ keyword.other.DML.sql conn.execute(r"""SELECT * FROM foobar WHERE %s and foo = '\t'""") # ^ keyword.other.DML.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.sql # Capital R prevents all syntax embedding conn.execute(R'SELECT * FROM foobar') # ^ meta.string.python - keyword.other.DML.sql conn.execute(R"SELECT * FROM foobar") # ^ - keyword.other.DML.sql conn.execute(R"""SELECT * FROM foobar""") # ^ - keyword.other.DML.sql conn.execute(r'''SELECT * FROM foobar''') # ^ keyword.other.DML.sql conn.execute(u"""SELECT * FROM foobar WHERE %s and foo = '\t'""") # ^ keyword.other.DML.sql # ^ constant.other.placeholder.python # ^ constant.character.escape.python regex = r'\b ([fobar]*){1}(?:a|b)?' # ^ meta.string.python keyword.control.anchor.regexp # ^ keyword.operator.quantifier.regexp regex = r'.* # Not a comment (yet)' # ^^^^^^^^^^^^^^^^^^^^^ - comment # ^ punctuation.definition.string.end.python - comment # ^ - invalid regex = r".* # Not a comment (yet)" # ^^^^^^^^^^^^^^^^^^^^^ - comment # ^ punctuation.definition.string.end.python - comment # ^ - invalid regex = r'''\b ([fobar]*){1}(?:a|b)?''' # ^ keyword.control.anchor.regexp # ^ keyword.operator.quantifier.regexp regex = r"""\b ([fobar]*){1}(?:a|b)?""" # ^ keyword.control.anchor.regexp # ^ keyword.operator.quantifier.regexp # Capital R prevents all syntax embedding regex = R'\b ([fobar]*){1}(?:a|b)?' # ^ - keyword.control.anchor.regexp # ^ - keyword.operator.quantifier.regexp regex = R"\b ([fobar]*){1}(?:a|b)?" # ^ - keyword.control.anchor.regexp # ^ - keyword.operator.quantifier.regexp bad_string = 'SELECT * FROM users # ^ invalid.illegal.unclosed-string string = ''' # <- string.quoted.single.block ''' string = """ # <- string.quoted.double.block """ string = """ # ^^^ string.quoted.double.block - string string """ string = r""" # ^^^ meta.string.python string.quoted.double.block """ string = r""" # An indented comment. # ^ - comment # ^ comment.line.number-sign.regexp ### <> @includes some &punctutation. # <- comment.line.number-sign.regexp """ string = ''' # ^^^ string.quoted.single.block ''' string = r''' # ^^^ string.quoted.single.block ''' string = r''' # An indented comment. # ^ - comment # ^ comment.line.number-sign.regexp ### <> @includes some &punctutation. # <- comment.line.number-sign.regexp ''' string = r''' [set] # ^^^^^ constant.other.character-class.set.regexp # ^ punctuation.definition.character-class.begin.regexp # ^ punctuation.definition.character-class.end.regexp (group) # ^^^^^^^ meta.group.regexp # ^ punctuation.definition.group.begin.regexp # ^ punctuation.definition.group.end.regexp (?9,}".format(1000) # ^^^^^^^ constant.other.placeholder "Testing {:j^9,}".format(1000) # ^^^^^^^ constant.other.placeholder # ^^^^^ constant.other.format-spec "result: {value:{width}.{precision}}" # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.other.placeholder # ^^^^^^^^^^^^^^^^^^^^ meta.format-spec.python # ^ punctuation.definition.placeholder.begin # ^^^^^^^ constant.other.placeholder constant.other.placeholder # ^ punctuation.definition.placeholder.begin # ^^^^^^^^^^^ constant.other.placeholder constant.other.placeholder # ^^ punctuation.definition.placeholder.end f"string" # <- storage.type.string #^^^^^^^^ string.quoted.double RF"""string""" #^^ storage.type.string #^^^^^^^^^^^^^^ meta.string.interpolated string.quoted.double.block F'''string''' # <- storage.type.string #^^^^^^^^^^^^ meta.string.interpolated string.quoted.single.block rf'string' #^^ storage.type.string #^^^^^^^^^^ meta.string.interpolated string.quoted.single rf'\r\n' f'\r\n' # ^^^^ - constant # ^^^^ constant.character.escape rf"\r\n" f"\r\n" # ^^^^ - constant # ^^^^ constant.character.escape f"{something}" #^^^^^^^^^^^^ meta.string.interpolated # <- storage.type.string #^ punctuation.definition.string.begin # ^ punctuation.section.interpolation.begin # ^ punctuation.section.interpolation.end # ^ punctuation.definition.string.end # ^^^^^^^^^ source source.python.embedded # ^ source - meta, string, source source f"{True!a:02f}" #^^^^^^^^^^^^^^ meta.string.interpolated # ^ - source source.python.embedded # ^^^^ source source.python.embedded constant.language # ^^^^^^^ - source source.python.embedded # ^^ storage.modifier.conversion - constant.other.format-spec # ^^^^ constant.other.format-spec # ^ punctuation.section.interpolation.end # ^ punctuation.definition.string.end # ^ source - meta, string, source source f"result: {value:{width}.{precision}}\n" # ^ punctuation.section.interpolation.begin.python - source source # ^^^^^ source source.python.embedded # ^^ - source source # ^ punctuation.section.interpolation.begin.python # ^^^^^ source source.python.embedded # ^ punctuation.section.interpolation.end.python # ^ - source source # ^ punctuation.section.interpolation.begin.python # ^^^^^^^^^ source source.python.embedded # ^^ punctuation.section.interpolation.end.python - source source # ^^ constant.character.escape # ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.python # ^^^^^^^^^^^^^^^^^^^^ meta.format-spec.python # ^^^^^^ - meta.interpolation.python meta.interpolation.python # ^^^^^^^ meta.interpolation.python meta.interpolation.python # ^ - meta.interpolation.python meta.interpolation.python # ^^^^^^^^^^^ meta.interpolation.python meta.interpolation.python # ^^^ - meta.interpolation.python meta.interpolation.python rf"{value:{width!s:d}}" #^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated # ^^^^^ source source.python.embedded # ^^ storage.modifier.conversion # ^^ constant.other.format-spec F""" {} {\} } #^^^^^^^^^^^ meta.string.interpolated #^^^ punctuation.definition.string.begin # ^^ invalid.illegal.empty-expression # ^ invalid.illegal.backslash-in-fstring # ^ invalid.illegal.stray-brace """ f" { % ^ invalid.illegal.unclosed-string # TODO make this test pass }" f' \ {1 + 2!a:02f}' #^^^^^^^^^^^^^^ meta.string.interpolated # ^^^^^ source source.python.embedded f' # ^ invalid.illegal.unclosed-string # <- - meta # this test is to ensure we're not matching anything here anymore