--- /dev/null
+The MIT License (MIT)
+
+Copyright (c) 2014 Noah Morrison
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
--- /dev/null
+A python3 implementation of the [mustache templating language](http://mustache.github.io).
+
+Currently it only tokenizes the file, and doesn't have any nice way of changing the target file.
--- /dev/null
+#!/usr/bin/python
+
+
+def tokenize(template):
+ class EOF(Exception):
+ pass
+
+ def get(amount=1):
+ return template[current:current + amount]
+
+ def look(ahead=0, amount=1):
+ idx = current + ahead
+ if idx > len(template):
+ raise EOF()
+
+ return template[idx:idx + amount]
+
+ tag_types = {
+ '!': 'comment',
+ '#': 'section',
+ '^': 'inverted section',
+ '/': 'end',
+ '>': 'partial',
+ '=': 'set delimiter?',
+ '{': 'no escape?',
+ '&': 'no escape'
+ }
+
+ current = 0
+ l_del = '{{'
+ r_del = '}}'
+ while current < len(template):
+ try:
+ size = 0
+ while look(size, 2) != l_del:
+ size += 1
+ except EOF:
+ yield ('literal', get(size))
+ return
+
+ if size != 0:
+ yield ('literal', get(size))
+
+ current += size + 2
+
+ tag_type = tag_types.get(get(), 'variable')
+ if tag_type != 'variable':
+ current += 1
+
+ size = 1
+ while look(size, 2) != r_del:
+ size += 1
+
+ tag_key = get(size).strip()
+ current += size + 2
+
+ if tag_type == 'no escape?':
+ if look(-2, 3) == '}}}':
+ tag_type = 'no escape'
+ current += 1
+
+ elif tag_type == 'set delimiter?':
+ if look(-3) == '=':
+ l_del, r_del = tag_key[:-1].split(' ')
+ continue
+
+ yield (tag_type, tag_key)
+
+ return
+
+
+if __name__ == '__main__':
+ with open('test.mustache', 'r') as f:
+ template = f.read()
+
+ tokens = tokenize(template)
+ for token in tokens:
+ print(token)
--- /dev/null
+{{!
+ mustache comment!
+}}
+
+Hello, {{ thing }}!
+
+{{{<b>NO ESCAPE!</b>}}}
+{{&<i>You understand?</i>}}
+
+{{#show}}
+Show is true!
+{{/show}}
+
+{{^show}}
+Show if false!
+{{/show}}
+
+{{> partial}}
+
+{{=<< >>=}}
+
+<<delimiter>>
+
+<<={{ }}=>>
+
+{{delimiter
+
+That's all folks!