Created
April 17, 2016 18:03
-
-
Save TheSeamau5/386d47acb7c104738e0b2a8dff9f0f36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* type Definition = { | |
* kind: String, | |
* name: String, | |
* properties: [Property] | |
* } | |
* | |
* type Property = { | |
* key: String, | |
* value: [String] | |
* } | |
* | |
*/ | |
start | |
= space* definitions: definitionList space* { | |
return definitions; | |
} | |
character | |
= [a-zA-Z0-9-%] | |
word | |
= chars: character+ { | |
return chars.join(''); | |
} | |
className = '.' name:word { | |
return name; | |
} | |
idName = '#' name:word { | |
return name; | |
} | |
space | |
= [ \t\n\r] | |
propertyValue | |
= first:word rest:(space* word)* { | |
if (rest) { | |
return [first].concat(rest.map(array => array[1])); | |
} else { | |
return first; | |
} | |
} | |
property | |
= key:word space* ':' space* value:propertyValue { | |
return { | |
key: key, | |
value: value | |
}; | |
} | |
propertyList | |
= first:property ';' space* rest:propertyList? { | |
if (rest) { | |
return [first].concat(rest); | |
} else { | |
return [first]; | |
} | |
} | |
definition | |
= name:className space* '{' space* properties:propertyList? space* '}' { | |
return { | |
kind: 'class', | |
name: name, | |
properties: properties ? properties : [] | |
}; | |
} | |
/ name:idName space* '{' space* properties:propertyList? space* '}' { | |
return { | |
kind: 'id', | |
name: name, | |
properties: properties ? properties : [] | |
}; | |
} | |
/ name:word space* '{' space* properties:propertyList? space* '}' { | |
return { | |
kind: 'element', | |
name: name, | |
properties: properties ? properties : [] | |
}; | |
} | |
definitionList | |
= first:definition space* rest:definitionList? { | |
if (rest) { | |
return [first].concat(rest); | |
} else { | |
return [first]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment