News for hackers. Stuff that matters.
Re:Google HTML/CSS style guide suggests omitting head and bo... by boomlinde on Wednesday May 22, 2019 @05:00AM (#19979250)
> I can't think of why it would be easier to write software to parse

Maybe you haven't considered it closely enough?

If you look at the specifications, there is a complex set of rules governing the conditions under which a tag may be omitted. These naturally complicate the syntax. Consistency is preferable because it typically results in a simpler syntax.

Consider the following language:

    document ::= tags
    tags     ::= tag { tag }
    tag      ::= '(' symbol [ tags ] ')'
    symbol   ::= 'x' | 'y' | 'z' | 'w'
It encodes a document like the following:

    (x (y) (z) (y (w (x))))
    (z (w (z) (y)))
i.e. a list of trees of tags named by symbols.

Now, try to describe the language that's identical except that the closing bracket is optional if it belongs to a 'w' tag that precedes an 'x' tag. Try even to describe a language where they are not optional, but must be omitted. They'll both be more complex than the language I described above. Now imagine that there are about a hundred such exceptions, as in HTML. Chances are that rather than encoding them as syntax for the parser, you'll complicate the lexer to automagically insert the optional tags, fuzzying the boundary between the lexer and parser.

> Anyway, parsing HTML is a nightmare, and HTML documents are usually broken in the wild

Exactly because the syntax is needlessly complicated.

There are no comments on this comment yet.