Skip to content

Instantly share code, notes, and snippets.

@Pikuseru
Created November 6, 2016 16:12
Show Gist options
  • Save Pikuseru/3858038172caea7372e5f635e91b08a2 to your computer and use it in GitHub Desktop.
Save Pikuseru/3858038172caea7372e5f635e91b08a2 to your computer and use it in GitHub Desktop.
Objective-C PEG grammar (first attempt)
interface = "@interface" _ identifier _ (":" _ identifier)? _ protocols? _ (property / selector)* _ "@end" _ eof
protocols = "<" _ identifier (_ "," _ identifier)* _ ">"
property = "@property" _ attributes? _ type _ pointer? _ identifier _ ";" _
attributes = "(" _ attribute (_ "," _ attribute)* _ ")"
attribute = getter / identifier
getter = identifier _ "=" _ identifier
selector = ("+" / "-") _ typereference _ (selectorpart+ / identifier) _ ";" _
selectorpart = identifier _ ":" _ typereference _ identifier _
typereference = "(" _ type _ pointer? _ ")"
type = list / dict / set / identifier
list = "NS" mutable? "Array" _ "<" _ type _ pointer? _ ">"
set = "NS" mutable? "Set" _ "<" _ type _ pointer? _ ">"
dict = "NS" mutable? "Dictionary" _ "<" _ type _ pointer? _ "," _ type _ pointer? _ ">"
mutable = "Mutable"
pointer = "*"
identifier = $([a-zA-Z]+)
_ = ws / eol
ws = $([ \t\n\r]*)
eol = [\n]
eof = !.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment