Skip to content

Commit

Permalink
More proper styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinggaard committed Apr 18, 2024
1 parent 2d418f2 commit c87dbb9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
31 changes: 5 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,18 @@ virtualenv venv
source ./venv/bin/activate
pip install Pygments

wget https://raw.githubusercontent.com/DATP4G6/sct-pygments/main/lexer.py
wget https://raw.githubusercontent.com/DATP4G6/sct-pygments/main/SctLexer.py
```


## Use

See [main.tex](./main.tex)
See [example.tex](./example.tex)

```tex
\documentclass{minimal}
\usepackage[cache=false]{minted}
\begin{document}
\begin{minted}{'lexer.py -x'}
class Foo(int x) {
decorator Bar {
x = x - 1;
}
@Bar
state Baz {
if (exists(Foo::?(x: 3))) {
destroy;
}
enter Baz;
}
}
function Setup() -> void {
create Foo::Baz(x: 5);
}
\begin{minted}{'SctLexer.py -x'}
// your code here...
\end{minted}
\end{document}
```

This, will generate a .pdf like the one shown in [main.pdf](./main.pdf)
This, will generate a .pdf like the one shown in [example.pdf](./example.pdf)
24 changes: 17 additions & 7 deletions lexer.py → SctLexer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pygments.lexer import RegexLexer
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *

class CustomLexer(RegexLexer):
Expand All @@ -12,13 +12,10 @@ class CustomLexer(RegexLexer):
(r'//[^\r\n]*', Comment.Single,),
(r'[ \t\r\n]+', Whitespace,),

(r'function', Keyword.Declaration,),
(r'->', Punctuation,),
(r'int', Keyword.Type),
(r'float', Keyword.Type),
(r'void', Keyword.Type),

(r'=', Operator,),
(r'if', Keyword.Reserved,),
(r'else', Keyword.Reserved,),
(r'while', Keyword.Reserved,),
Expand All @@ -29,8 +26,8 @@ class CustomLexer(RegexLexer):
(r'exit', Keyword.Reserved,),
(r'continue', Keyword.Reserved,),
(r'break', Keyword.Reserved,),


(r'=', Operator,),
(r'\*', Operator,),
(r'/', Operator,),
(r'\+', Operator,),
Expand All @@ -47,12 +44,25 @@ class CustomLexer(RegexLexer):
(r'!', Operator,),

(r'class', Keyword.Declaration,),
(r'(?<=class )\w+', Name.Constant,),

# predicates
(r'(\w+)(::)(\w+)', bygroups(Name.Constant, Punctuation, Name.Label),),
(r'(\w+)(::)(\?)', bygroups(Name.Constant, Punctuation, Keyword.Pseudo),),

(r'state', Keyword.Declaration,),
(r'(?<=state )\w+', Name.Label,),
(r'(?<=enter )\w+', Name.Label,),

(r'decorator', Keyword.Declaration,),
(r'@', Punctuation,),
(r'(?<=decorator )\w+', Name.Decorator,),
(r'@\w+', Name.Decorator,),

(r'function', Keyword.Declaration,),
(r'(?<=function )\w+', Name.Function,),
(r'(?<!::)\w+(?=\()', Name.Function,), # invoke function

(r'\?', Name.Builtin,),
(r'->', Punctuation,),
(r'\(', Punctuation,),
(r'\)', Punctuation,),
(r'{', Punctuation,),
Expand Down
Binary file added example.pdf
Binary file not shown.
7 changes: 6 additions & 1 deletion main.tex → example.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
\usepackage[cache=false]{minted}

\begin{document}
\begin{minted}{'lexer.py -x'}
\begin{minted}{'SctLexer.py -x'}
class Foo(int x) {
decorator Bar {
x = x - 1;
}

@Bar
state Baz {
float yess = 3.5;

if (exists(Foo::?(x: 3))) {
destroy;
}
else if (exists(Foo::Baz())) {
create Foo::Baz(x: 6);
}
enter Baz;
}
}
Expand Down
Binary file removed main.pdf
Binary file not shown.

0 comments on commit c87dbb9

Please sign in to comment.