mirror of https://github.com/patacrep/patacrep.git
Louis
10 years ago
13 changed files with 183 additions and 112 deletions
@ -1,20 +1,3 @@ |
|||||
# -*- coding: utf-8 -*- |
"""Dumb and very very incomplete LaTeX parser.""" |
||||
|
|
||||
"""Very simple LaTeX parser |
from patacrep.latex.syntax import tex2plain, parse_song |
||||
|
|
||||
This module uses an LALR parser to try to parse LaTeX code. LaTeX language |
|
||||
*cannot* be parsed by an LALR parser, so this is a very simple attemps, which |
|
||||
will work on simple cases, but not on complex ones. |
|
||||
""" |
|
||||
|
|
||||
from patacrep.latex.syntax import tex2plain |
|
||||
from patacrep.latex.syntax import parsesong as syntax_parsesong |
|
||||
from patacrep import encoding |
|
||||
|
|
||||
def parsesong(path): |
|
||||
"""Return a dictonary of data read from the latex file `path`. |
|
||||
|
|
||||
""" |
|
||||
data = syntax_parsesong(encoding.open_read(path).read(), path) |
|
||||
data['@path'] = path |
|
||||
return data |
|
||||
|
@ -0,0 +1,9 @@ |
|||||
|
|
||||
|
from patacrep.songs import Song |
||||
|
|
||||
|
class ChordproSong(Song): |
||||
|
pass |
||||
|
|
||||
|
SONG_PARSERS = { |
||||
|
'sgc': ChordproSong, |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
"""Very simple LaTeX parser |
||||
|
|
||||
|
This module uses an LALR parser to try to parse LaTeX code. LaTeX language |
||||
|
*cannot* be parsed by an LALR parser, so this is a very simple attemps, which |
||||
|
will work on simple cases, but not on complex ones. |
||||
|
""" |
||||
|
|
||||
|
import os |
||||
|
|
||||
|
from patacrep import files |
||||
|
from patacrep.latex import parse_song |
||||
|
from patacrep.songs import Song |
||||
|
|
||||
|
class LatexSong(Song): |
||||
|
"""LaTeX song parser.""" |
||||
|
|
||||
|
def parse(self, content): |
||||
|
"""Parse content, and return the dictinory of song data.""" |
||||
|
return parse_song(content, self.fullpath) |
||||
|
|
||||
|
def tex(self, output): |
||||
|
"""Return the LaTeX code rendering the song.""" |
||||
|
return r'\input{{{}}}'.format(files.path2posix( |
||||
|
files.relpath( |
||||
|
self.fullpath, |
||||
|
os.path.dirname(output) |
||||
|
))) |
||||
|
|
||||
|
SONG_PARSERS = { |
||||
|
'is': LatexSong, |
||||
|
'sg': LatexSong, |
||||
|
} |
Loading…
Reference in new issue