Tab indentation support (deviation from yaml spec)

Issue #45 new
created an issue

Can somebody advise as to the effort required in adding tab indentation support or a pointer towards where to make the first change (I can start digging but a first indicator would help)

I am aware that tabs are forbidden by the yaml designers but coming from a Pythonesque background and seeing the semantic value of the tab (and not interested in adapting to the fact that other people can't keep tabs together), I would like to fork the yaml spec to allow tabs.

Any people who wish to join :) in this revolution :D

Comments (7)

  1. eskhool reporter

    Well, PEP 8 recommends it mostly to allow terminal editing of code (legacy I think) and because most existing code out there uses spaces and because of lack of agreement on editors/IDEs.

    We use tabs exclusively in all our code which is whitespace significant.

    Since YAML is whitespace significant having semantic value to tabs is just natural in my opinion.

  2. eskhool reporter

    PEP8 is a style guide with recommendations. If python intended to enforce not having tab as a valid option they would just remove it from the spec (atleast in python 3). It exists because some appreciate the value of the semantical meaning of tab vs 4/2 spaces (even if Guido himself does not now).

    I would like to see the same semantical meaning in a yaml like format which is otherwise very close to the kind of config document format I like (definitely preferred over json), but since yaml otherwise compiles to json it works out.

  3. Antoine Musso

    PyYAML follows the YAML spec 1.1,

    Indentation is described in section 4.2.2 Indentation Spaces :

    [66]    s-indent(n) ::= s-ignored-space x n

    s-ignored-space is described in section 4.1.5. Miscellaneous Characters as (emphasis mine):

    An ignored space character outside scalar content. Such spaces are used for indentation and separation between tokens. To maintain portability, tab characters must not be used in these cases, since different systems treat tabs differently. Note that most modern editors may be configured so that pressing the tab key results in the insertion of an appropriate number of spaces.

    [35]    s-ignored-space ::= #x20 /*SP*/  

    If PyYAML was to support tab for indentation it would no more conform to the specification which would cause headaches and troubles down the road. I love tabs myself since one can set their size however they prefer (2,3,4,8 spaces or whatever), but for multiline indentations it is often awkward.

    I would recommend to dismiss this task on the basis the request does not conform to the YAML v1.1 spec.

  4. Benedikt Reinartz

    The problem is that JSON supports arbitrary whitespace between tokens. So by taking this stance PyYAML is not able to parse perfectly valid JSON files. Not to big of a deal but it would be much nicer if this was at least optionally possible.

  5. Log in to comment