diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index f18bd395..ff0bc4cb 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -3,8 +3,11 @@ # pylint: disable=too-few-public-methods from collections import OrderedDict +import functools import logging +from patacrep.songs import errors + LOGGER = logging.getLogger() def _indent(string): @@ -223,7 +226,7 @@ class Song(AST): "tag": "add_cumulative", } - def __init__(self, filename, directives, *, errors=None): + def __init__(self, filename, directives, *, error_builders=None): super().__init__() self.content = [] self.meta = OrderedDict() @@ -231,10 +234,10 @@ class Song(AST): self._titles = [] self._subtitles = [] self.filename = filename - if errors is None: + if error_builders is None: self.error_builders = [] else: - self.error_builders = errors + self.error_builders = error_builders for directive in directives: self.add(directive) @@ -265,7 +268,13 @@ class Song(AST): # Add a metadata directive. Some of them are added using special # methods listed in ``METADATA_ADD``. if data.keyword not in AVAILABLE_DIRECTIVES: - LOGGER.warning("Ignoring unknown directive '{}'.".format(data.keyword)) + message = "Ignoring unknown directive '{}'.".format(data.keyword) + LOGGER.warning("File {}, line {}: {}".format(self.filename, data.lineno, message)) + self.error_builders.append(functools.partial( + errors.SongSyntaxError, + line=data.lineno, + message=message, + )) if data.keyword in self.METADATA_ADD: getattr(self, self.METADATA_ADD[data.keyword])(data) else: diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 0315ad1f..04104ac6 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -49,7 +49,7 @@ class ChordproParser(Parser): symbols[0] = ast.Song( self.filename, directives=self._directives, - errors=self._errors, + error_builders=self._errors, ) else: symbols[0] = symbols[2].add(symbols[1])