Skip to content
Snippets Groups Projects
Commit ee3b3916 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Merge branch 'feature/user-doc' into 'develop'

Add a simple pygmentize lexer for syntax coloring of pugs examples

See merge request !150
parents 87403871 df91ba6e
No related branches found
No related tags found
1 merge request!150Add a simple pygmentize lexer for syntax coloring of pugs examples
......@@ -78,6 +78,8 @@ if (EMACS)
DEPENDS
"${PUGS_SOURCE_DIR}/doc/userdoc.org"
"${PUGS_SOURCE_DIR}/doc/lisp/userdoc-pdf.el"
"${PUGS_SOURCE_DIR}/tools/pgs-pygments.sh"
"${PUGS_SOURCE_DIR}/tools/pgs-pygments.py"
pugs
pugsdoc-dir
pugsdoc-download-elpa
......
......@@ -43,8 +43,7 @@
(custom-set-variables
'(org-export-html-postamble nil)
;; By now pugs is not known by Pygments raw text is better
'(org-latex-minted-langs '((pugs "Text") (pugs-error "Text")))
'(org-latex-minted-langs '((pugs "Pugs") (pugs-error "Pugs")))
'(org-confirm-babel-evaluate nil)
'(org-html-validation-link nil)
'(org-src-fontify-natively t)
......
......@@ -43,6 +43,9 @@
#+LATEX_HEADER_EXTRA: \BeforeBeginEnvironment{warning}{\begin{mdframed}[linecolor=red,backgroundcolor=red!10]}
#+LATEX_HEADER_EXTRA: \AfterEndEnvironment{warning}{\end{mdframed}}
#+LATEX_HEADER_EXTRA: \usemintedstyle{perldoc}
#+LATEX_HEADER_EXTRA: \renewcommand{\MintedPygmentize}{${PUGS_SOURCE_DIR}/tools/pgs-pygments.sh}
#+begin_src latex :exports results
\let\OldTexttt\texttt
\renewcommand{\texttt}[1]{\fcolorbox{gray!50}{gray!5}{\OldTexttt{#1}}}
......
from pygments.lexer import *
from pygments.token import *
class PugsLexer(RegexLexer):
name = 'Pugs'
aliases = ['pgs']
filenames = ['*.pgs']
tokens = {
'root': [
(r'([Ll]?)(")', bygroups(String.Affix, String.Double), 'string'),
(r'([Ll]?)(\')(\\[^\']+)(\')', bygroups(String.Affix, String.Char, String.Escape, String.Char)),
(r'\s+', Whitespace),
(r'/\*', Comment.Multiline, 'comment'),
(r'//.*?$', Comment.Singleline),
(r'/', Text),
(words(('B', 'N', 'Z', 'R', 'R^1', 'R^2','R^3', 'R^1x1', 'R^2x2', 'R^3x3', 'string'), suffix=r'\b'), Keyword.Type),
(words(('let', 'import', 'do', 'while', 'for', 'if', 'else' 'break'), suffix=r'\b'), Keyword.Reserved),
(words(('and', 'or', 'xor', 'not', 'true', 'false'), suffix=r'\b'), Keyword.Reserved),
(words(('cout', 'cerr', 'clog'), suffix=r'\b'), Name.Variable),
(r'[,~!%&*+=|?:<>/-]', Operator),
(r'[+-]?\d+(\.\d*)?[Ee][+-]?\d+', Number.Float),
(r'[+-]?(\d+\.\d*)|(\d*\.\d+)([Ee][+-]?\d+)?', Number.Float),
(r'\d+[LlUu]*', Number.Integer),
(r'[\(\)\[\];.]', Punctuation),
(r'[{}]', Punctuation),
(r'\w+', Name),
],
'comment': [
(r'[^*/]+', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
],
'string': [
(r'"', String, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
(r'\\\n', String.Escape), # line continuation
(r'[^\\"]+', String), # all other characters
(r'\\', String), # stray backslash
],
}
#!/bin/env bash
arguments=()
while [[ "$#" -ne 0 ]]; do
case "$1" in
-l)
arguments+=("$1")
shift
lexer=$1
if [[ "$lexer" == "Pugs" ]]; then
arguments+=("${PUGS_SOURCE_DIR}/tools/pgs-pygments.py:PugsLexer")
arguments+=("-x")
else
arguments+=("${lexer}")
fi
;;
*)
arguments+=("$1")
;;
esac
shift
done
pygmentize -Ostyle=colorful "${arguments[@]}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment