def outputargs(self): """Returns a list of output arguments in our document. See ly.parse.outputargs(). """ return list(ly.parse.outputargs(tokeniter.allTokens(self.document())))
def includeargs(self): """Returns a list of \\include arguments in our document. See ly.parse.includeargs(). """ return list(ly.parse.includeargs(tokeniter.allTokens(self.document())))
def version(self): """Returns the LilyPond version if set in the document, as a tuple of ints. First the functions searches inside LilyPond syntax. Then it looks at the 'version' document variable. Then, if the document is not a LilyPond document, it simply searches for a \\version command string, possibly embedded in a comment. The version is cached until the documents contents change. """ mkver = lambda strings: tuple(map(int, strings)) version = ly.parse.version(tokeniter.allTokens(self.document())) if version: return mkver(re.findall(r"\d+", version)) # look at document variables version = variables.get(self.document(), "version") if version: return mkver(re.findall(r"\d+", version)) # parse whole document for non-lilypond documents if self.mode() != "lilypond": m = re.search(r'\\version\s*"(\d+\.\d+(\.\d+)*)"', self.document().toPlainText()) if m: return mkver(m.group(1).split('.'))
def words(document): """Harvests words from strings, lyrics, markup and comments.""" for t in tokeniter.allTokens(document): if isinstance(t, _word_types): for m in _words(t): yield m.group()
def schemewords(document): """Harvests all schemewords from the document.""" for t in tokeniter.allTokens(document): if type(t) is ly.lex.scheme.Word: yield t