A simple single line, triple-quoted comment is giving syntax error. Why?

Marko Rauhamaa marko at pacujo.net
Fri Mar 27 01:34:21 EDT 2015


Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> You're arguing whether or not in the following line of code:
>
> spam = "abcd" "efgh"
> # implicitly concatenated to "abcdefgh" at compile time
>
> the right hand side pair of strings counts as a single token or two? Am I
> right, or am I missing something?
>
> If that's all it is, why don't you just run the tokenizer over it and
> see what it says?

Now, someone *could* write a tokenizer that took care of string
concatenation on the spot--as long as it dealt with comments as well:

   ("abc"
   # hello
    "def")

It would be even possible to write a parser that didn't have a separate
lexical analyzer at all.

Arguing about terminology is pretty useless. Both sides in this fight
are correct, namely:

   * string literal concatenation is part of expression syntax

   * what goes on inside an atom stays inside an atom

For example, this expression is illegal:

   "abc" ("def")


Marko



More information about the Python-list mailing list