Han Pengbo
Han Pengbo

Reputation: 1436

Visual Format String Grammar in auto layout

I want to learn auto layout and see this official document.In Visual Format String Grammar chapter,I don't understand Replacement rule.What does "?" and "*" means?

Upvotes: 1

Views: 311

Answers (1)

Gabriele Petronella
Gabriele Petronella

Reputation: 108159

The definition of the grammar is given in a sort of EBNF form, which is used in computer science to describe context-free grammars.

Specifically,

  • ? expresses optionality, meaning 0 or 1 repetitions
  • * expresses 0 or more repetitions
  • | expresses an alternative

For instance

(<predicate>(,<predicate>)*)

means a <predicate>, followed by an arbitrary number of ,<predicate>, possibly 0.

And

[<viewName>(<predicateListWithParens>)?]

means either [<viewName><predicateListWithParens>] or just [<viewName>]

Finally

H|V

means either H or V.

Upvotes: 2

Related Questions