Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for METAFONT #3465

Merged
merged 7 commits into from Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -902,6 +902,11 @@
"title": "Mermaid",
"owner": "RunDevelopment"
},
"metafont": {
"title": "METAFONT",
"alias": "mf",
"owner": "LaeriExNihilo"
},
"mizar": {
"title": "Mizar",
"owner": "Golmote"
Expand Down
85 changes: 85 additions & 0 deletions components/prism-metafont.js
@@ -0,0 +1,85 @@
Prism.languages.metafont = {
// 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.
'comment': {
pattern: /%.*/,
greedy: true
},
'string': {
pattern: /"[^\r\n"]*"/,
greedy: true
},
'number': /\d*\.?\d+/,
'boolean': /\b(?:false|true)\b/,
'punctuation': [
/[,;()]/,
{
pattern: /(^|[^{}])(?:{|})(?![{}])/,
lookbehind: true
},
{
pattern: /(^|[^[])\[(?![[])/,
lookbehind: true
},
{
pattern: /(^|[^\]])](?![\]])/,
lookbehind: true
}
],
'constant': [
{
pattern: /(^|[^!?])\?\?\?(?![!?])/,
lookbehind: true
},
{
pattern: /(^|[^/*\\])(?:\\|\\\\)(?![/*\\])/,
lookbehind: true
},
/\b(?:blankpicture|bp|cc|cm|dd|ditto|down|eps|epsilon|fullcircle|halfcircle|identity|in|infinity|left|mm|nullpen|nullpicture|origin|pc|pencircle|penrazor|penspeck|pensquare|penstroke|proof|pt|quartercircle|relax|right|smoke|unitpixel|unitsquare|up)\b/
],
'quantity': {
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|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/,
alias: 'keyword'
},
'command': {
pattern: /\b(?:batchmode|errorstopmode|nonstopmode|scrollmode|charlist|addto|cull|display|errhelp|errmessage|message|everyjob|extensible|fontdimen|headerbyte|inner|interim|let|ligtable|newinternal|numspecial|openwindow|outer|randomseed|save|show|showdependencies|showstats|showtoken|showvariable|shipout|special)\b/,
alias: 'builtin'
},
'operator': [
{
pattern: /(^|[^>=<:|])(?:<|<=|=|=:|\|=:|\|=:>|=:|=:\|>|\|=:\||\|=:\|>|\|=:\|>>|>|>=|:|:=|<>|::)(?![>=<:|])/,
lookbehind: true
},
{
pattern: /(^|[^+-])(?:\+|\+\+|-{1,3}|\+-\+)(?![+-])/,
lookbehind: true
},
{
pattern: /(^|[^/*\\])(?:\*|\*\*|\/)(?![/*\\])/,
lookbehind: true
},
{
pattern: /(^|[^.])(?:\.{2,3})(?![.])/,
lookbehind: true
},
{
pattern: /(^|[^@#&$])&(?![@#&$])/,
lookbehind: true
},
/\b(?:and|or|not)\b/
],
'macro': {
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_space|font_normal_stretch|font_normal_shrink|font_quad|font_size|font_slant|font_x_height|gfcorners|gobble|gobbled|good\.(?:x|y|lft|rt|top|bot)|grayfont|hide|hround|imagerules|incr|interact|interpath|intersectionpoint|inverse|italcorr|killtext|labelfont|labels|lft|loggingall|lowres_fix|makegrid|makelabel(?:\.(?:top|bot|rt|lft)(?:\.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|showit|shipit|slantfont|softjoin|solve|stop|superellipse|tensepath|thru|titlefont|top|tracingall|tracingnone|undraw|undrawdot|unfill|unfilldraw|upto|vround)\b/,
alias: 'function'
},
'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/,
'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/,
'type': {
pattern: /\b(?:boolean|expr|numeric|pair|path|pen|picture|primary|secondary|string|suffix|tertiary|text|transform)\b/,
alias: 'property'
},
'variable': {
pattern: /(^|[^@#&$])(?:@#|#@|#|@)(?![@#&$])|\b(?:aspect_ratio|currentpen|currentpicture|currenttransform|d|extra_beginchar|extra_endchar|extra_setup|h|localfont|mag|mode|screen_cols|screen_rows|whatever|w|x|y|z)\b/,
lookbehind: true
}
};
Prism.languages.mf=Prism.languages['metafont'];
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions components/prism-metafont.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/prism-metafont.html
@@ -0,0 +1,21 @@
<h2>Comments and strings</h2>
<pre><code>%This makes a comment.
"While this is a string."</code></pre>

<h2>Numbers</h2>
<pre><code>0 1.2 .3</code></pre>

<h2>Operators</h2>
<pre><code>eps*256>=1&lt;&gt;true
""&ditto
z1..z2--z3
5+-+4=3</code></pre>

<h2>Types</h2>
<pre><code>path p[],q[]</code></pre>

<h2>Concrete example</h2>
<pre><code>% From plain.mf
vardef penpos@#(expr b,d) =
(x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d;
x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef;</code></pre>