A Pygments shell lexer to lex shell scripts used as package build scripts and package manifests such as autotools, ebuild, PKGBUILD or APKBUILD. This used as an input to further parse and extract metadata.
| 31 | |
| 32 | |
| 33 | class BashShellLexer(RegexLexer): |
| 34 | """ |
| 35 | A Pygments shell lexer to lex shell scripts used as package build scripts |
| 36 | and package manifests such as autotools, ebuild, PKGBUILD or APKBUILD. |
| 37 | This used as an input to further parse and extract metadata. |
| 38 | """ |
| 39 | |
| 40 | name = 'Shell' |
| 41 | aliases = ['shell'] |
| 42 | # for info, as this is not used here otherwise |
| 43 | filenames = ['*.ebuild', 'PKGBUILD', 'APKBUILD', ] |
| 44 | mimetypes = [] |
| 45 | |
| 46 | tokens = { |
| 47 | 'root': [ |
| 48 | include('basic'), |
| 49 | include('data'), |
| 50 | ], |
| 51 | 'basic': [ |
| 52 | (r'#.*$', Comment), |
| 53 | # variable declaration and assignment |
| 54 | (r'^(\b\w+)(\+?=)', bygroups(Name.Variable, Equal)), |
| 55 | ], |
| 56 | 'data': [ |
| 57 | (r'\(', ArrayStart), |
| 58 | (r'\)', ArrayEnd), |
| 59 | # (?s) is re.DOTALL e.g. across lines |
| 60 | (r'(?s)"(\\.|[^"])*"', String.Double), |
| 61 | (r"(?s)'(\\.|[^'])*'", String.Single), |
| 62 | (r'\n+', LF), |
| 63 | (r'\s+', WS), |
| 64 | (r'\S+', Text), |
| 65 | ], |
| 66 | } |