Skip to content

Commit 2815f69

Browse files
Added support for METAFONT (#3465)
Includes the METAFONT language to supported languages in Prism. METAFONT is a language for fontdrawing and fontmaking, especially for fonts destined to TeX. While old in various regards its legacy endures in METAPOST or in the TikZ syntax.
1 parent 4c87d41 commit 2815f69

22 files changed

+1072
-40
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@
902902
"title": "Mermaid",
903903
"owner": "RunDevelopment"
904904
},
905+
"metafont": {
906+
"title": "METAFONT",
907+
"owner": "LaeriExNihilo"
908+
},
905909
"mizar": {
906910
"title": "Mizar",
907911
"owner": "Golmote"

components/prism-metafont.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Prism.languages.metafont = {
2+
// Syntax of METAFONT with the added (public) elements of PlainMETAFONT. Except for internal quantities they are expected to be rarely redefined. Freely inspired by the syntax of Christophe Grandsire for the Crimson Editor.
3+
'comment': {
4+
pattern: /%.*/,
5+
greedy: true
6+
},
7+
'string': {
8+
pattern: /"[^\r\n"]*"/,
9+
greedy: true
10+
},
11+
'number': /\d*\.?\d+/,
12+
'boolean': /\b(?:false|true)\b/,
13+
'punctuation': [
14+
/[,;()]/,
15+
{
16+
pattern: /(^|[^{}])(?:\{|\})(?![{}])/,
17+
lookbehind: true
18+
},
19+
{
20+
pattern: /(^|[^[])\[(?!\[)/,
21+
lookbehind: true
22+
},
23+
{
24+
pattern: /(^|[^\]])\](?!\])/,
25+
lookbehind: true
26+
}
27+
],
28+
'constant': [
29+
{
30+
pattern: /(^|[^!?])\?\?\?(?![!?])/,
31+
lookbehind: true
32+
},
33+
{
34+
pattern: /(^|[^/*\\])(?:\\|\\\\)(?![/*\\])/,
35+
lookbehind: true
36+
},
37+
/\b(?:_|blankpicture|bp|cc|cm|dd|ditto|down|eps|epsilon|fullcircle|halfcircle|identity|in|infinity|left|mm|nullpen|nullpicture|origin|pc|penrazor|penspeck|pensquare|penstroke|proof|pt|quartercircle|relax|right|smoke|unitpixel|unitsquare|up)\b/
38+
],
39+
'quantity': {
40+
pattern: /\b(?:autorounding|blacker|boundarychar|charcode|chardp|chardx|chardy|charext|charht|charic|charwd|currentwindow|day|designsize|displaying|fillin|fontmaking|granularity|hppp|join_radius|month|o_correction|pausing|pen_(?:bot|lft|rt|top)|pixels_per_inch|proofing|showstopping|smoothing|time|tolerance|tracingcapsules|tracingchoices|tracingcommands|tracingedges|tracingequations|tracingmacros|tracingonline|tracingoutput|tracingpens|tracingrestores|tracingspecs|tracingstats|tracingtitles|turningcheck|vppp|warningcheck|xoffset|year|yoffset)\b/,
41+
alias: 'keyword'
42+
},
43+
'command': {
44+
pattern: /\b(?:addto|batchmode|charlist|cull|display|errhelp|errmessage|errorstopmode|everyjob|extensible|fontdimen|headerbyte|inner|interim|let|ligtable|message|newinternal|nonstopmode|numspecial|openwindow|outer|randomseed|save|scrollmode|shipout|show|showdependencies|showstats|showtoken|showvariable|special)\b/,
45+
alias: 'builtin'
46+
},
47+
'operator': [
48+
{
49+
pattern: /(^|[^>=<:|])(?:<|<=|=|=:|\|=:|\|=:>|=:\|>|=:\||\|=:\||\|=:\|>|\|=:\|>>|>|>=|:|:=|<>|::|\|\|:)(?![>=<:|])/,
50+
lookbehind: true
51+
},
52+
{
53+
pattern: /(^|[^+-])(?:\+|\+\+|-{1,3}|\+-\+)(?![+-])/,
54+
lookbehind: true
55+
},
56+
{
57+
pattern: /(^|[^/*\\])(?:\*|\*\*|\/)(?![/*\\])/,
58+
lookbehind: true
59+
},
60+
{
61+
pattern: /(^|[^.])(?:\.{2,3})(?!\.)/,
62+
lookbehind: true
63+
},
64+
{
65+
pattern: /(^|[^@#&$])&(?![@#&$])/,
66+
lookbehind: true
67+
},
68+
/\b(?:and|not|or)\b/
69+
],
70+
'macro': {
71+
pattern: /\b(?:abs|beginchar|bot|byte|capsule_def|ceiling|change_width|clear_pen_memory|clearit|clearpen|clearxy|counterclockwise|cullit|cutdraw|cutoff|decr|define_blacker_pixels|define_corrected_pixels|define_good_x_pixels|define_good_y_pixels|define_horizontal_corrected_pixels|define_pixels|define_whole_blacker_pixels|define_whole_pixels|define_whole_vertical_blacker_pixels|define_whole_vertical_pixels|dir|direction|directionpoint|div|dotprod|downto|draw|drawdot|endchar|erase|fill|filldraw|fix_units|flex|font_coding_scheme|font_extra_space|font_identifier|font_normal_shrink|font_normal_space|font_normal_stretch|font_quad|font_size|font_slant|font_x_height|gfcorners|gobble|gobbled|good\.(?:bot|lft|rt|top|x|y)|grayfont|hide|hround|imagerules|incr|interact|interpath|intersectionpoint|inverse|italcorr|killtext|labelfont|labels|lft|loggingall|lowres_fix|makegrid|makelabel(?:\.(?:bot|lft|rt|top)(?:\.nodot)?)?|max|min|mod|mode_def|mode_setup|nodisplays|notransforms|numtok|openit|penlabels|penpos|pickup|proofoffset|proofrule|proofrulethickness|range|reflectedabout|rotatedabout|rotatedaround|round|rt|savepen|screenchars|screenrule|screenstrokes|shipit|showit|slantfont|softjoin|solve|stop|superellipse|tensepath|thru|titlefont|top|tracingall|tracingnone|undraw|undrawdot|unfill|unfilldraw|upto|vround)\b/,
72+
alias: 'function'
73+
},
74+
'builtin': /\b(?:ASCII|angle|char|cosd|decimal|directiontime|floor|hex|intersectiontimes|jobname|known|length|makepath|makepen|mexp|mlog|normaldeviate|oct|odd|pencircle|penoffset|point|postcontrol|precontrol|reverse|rotated|sind|sqrt|str|subpath|substring|totalweight|turningnumber|uniformdeviate|unknown|xpart|xxpart|xypart|ypart|yxpart|yypart)\b/,
75+
'keyword': /\b(?:also|at|atleast|begingroup|charexists|contour|controls|curl|cycle|def|delimiters|doublepath|dropping|dump|else|elseif|end|enddef|endfor|endgroup|endinput|exitif|exitunless|expandafter|fi|for|forever|forsuffixes|from|if|input|inwindow|keeping|kern|of|primarydef|quote|readstring|scaled|scantokens|secondarydef|shifted|skipto|slanted|step|tension|tertiarydef|to|transformed|until|vardef|withpen|withweight|xscaled|yscaled|zscaled)\b/,
76+
'type': {
77+
pattern: /\b(?:boolean|expr|numeric|pair|path|pen|picture|primary|secondary|string|suffix|tertiary|text|transform)\b/,
78+
alias: 'property'
79+
},
80+
'variable': {
81+
pattern: /(^|[^@#&$])(?:@#|#@|#|@)(?![@#&$])|\b(?:aspect_ratio|currentpen|currentpicture|currenttransform|d|extra_beginchar|extra_endchar|extra_setup|h|localfont|mag|mode|screen_cols|screen_rows|w|whatever|x|y|z)\b/,
82+
lookbehind: true
83+
}
84+
};

components/prism-metafont.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-metafont.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<h2>Comments and strings</h2>
2+
<pre><code>%This makes a comment.
3+
"While this is a string."</code></pre>
4+
5+
<h2>Numbers</h2>
6+
<pre><code>0 1.2 .3</code></pre>
7+
8+
<h2>Operators</h2>
9+
<pre><code>eps*256>=1&lt;&gt;true
10+
""&ditto
11+
z1..z2--z3
12+
5+-+4=3</code></pre>
13+
14+
<h2>Types</h2>
15+
<pre><code>path p[],q[]</code></pre>
16+
17+
<h2>Concrete example</h2>
18+
<pre><code>% From plain.mf
19+
vardef penpos@#(expr b,d) =
20+
(x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d;
21+
x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef;</code></pre>

0 commit comments

Comments
 (0)