Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created April 17, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSeamau5/386d47acb7c104738e0b2a8dff9f0f36 to your computer and use it in GitHub Desktop.
Save TheSeamau5/386d47acb7c104738e0b2a8dff9f0f36 to your computer and use it in GitHub Desktop.
/*
* 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