Skip to content

Instantly share code, notes, and snippets.

@ChillyBwoy
Created October 20, 2015 10:51
Show Gist options
  • Save ChillyBwoy/b2c32d1add02df216026 to your computer and use it in GitHub Desktop.
Save ChillyBwoy/b2c32d1add02df216026 to your computer and use it in GitHub Desktop.
peg.js rules for parsing fest-templates
start =
element
validchar = [0-9a-zA-Z\-_\{\}\.\:\/]
_ = [ \t\r\n]*
tagAttrs =
_ name:validchar+ '="' value:validchar+ '"' _ {
return [name.join(''), value.join('')];
}
tagOpen =
_ "<fest:" chars:validchar+ attrs:tagAttrs* ">" _ {
return {
name: chars.join(''),
attrs: attrs.reduce(function (prev, curr) {
prev[curr[0]] = curr[1];
return prev;
}, {})
};
}
tagClose =
_ "</fest:" chars:validchar+ ">" _ {
return {
name: chars.join('')
};
}
tagSelf =
_ "<fest:" chars:validchar+ attrs:tagAttrs* "/>" _ {
return {
name: chars.join(''),
attrs: attrs.reduce(function (prev, curr) {
prev[curr[0]] = curr[1];
return prev;
}, {})
};
}
element =
text:validchar {
return '';
}
/ tag:tagSelf{
return tag;
}
/ open:tagOpen close:tagClose {
return open;
}
/ open:tagOpen all:element+ close:tagClose {
return [open].concat([all]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment