UNPKG

2.08 kBJavaScriptView Raw
1/*
2Language: OpenSCAD
3Author: Dan Panzarella <alsoelp@gmail.com>
4Description: OpenSCAD is a language for the 3D CAD modeling software of the same name.
5Website: https://www.openscad.org
6Category: scientific
7*/
8
9function openscad(hljs) {
10 const SPECIAL_VARS = {
11 className: 'keyword',
12 begin: '\\$(f[asn]|t|vp[rtd]|children)'
13 };
14 const LITERALS = {
15 className: 'literal',
16 begin: 'false|true|PI|undef'
17 };
18 const NUMBERS = {
19 className: 'number',
20 begin: '\\b\\d+(\\.\\d+)?(e-?\\d+)?', // adds 1e5, 1e-10
21 relevance: 0
22 };
23 const STRING = hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null });
24 const PREPRO = {
25 className: 'meta',
26 keywords: { keyword: 'include use' },
27 begin: 'include|use <',
28 end: '>'
29 };
30 const PARAMS = {
31 className: 'params',
32 begin: '\\(',
33 end: '\\)',
34 contains: [
35 'self',
36 NUMBERS,
37 STRING,
38 SPECIAL_VARS,
39 LITERALS
40 ]
41 };
42 const MODIFIERS = {
43 begin: '[*!#%]',
44 relevance: 0
45 };
46 const FUNCTIONS = {
47 className: 'function',
48 beginKeywords: 'module function',
49 end: /=|\{/,
50 contains: [
51 PARAMS,
52 hljs.UNDERSCORE_TITLE_MODE
53 ]
54 };
55
56 return {
57 name: 'OpenSCAD',
58 aliases: [ 'scad' ],
59 keywords: {
60 keyword: 'function module include use for intersection_for if else \\%',
61 literal: 'false true PI undef',
62 built_in: 'circle square polygon text sphere cube cylinder polyhedron translate rotate scale resize mirror multmatrix color offset hull minkowski union difference intersection abs sign sin cos tan acos asin atan atan2 floor round ceil ln log pow sqrt exp rands min max concat lookup str chr search version version_num norm cross parent_module echo import import_dxf dxf_linear_extrude linear_extrude rotate_extrude surface projection render children dxf_cross dxf_dim let assign'
63 },
64 contains: [
65 hljs.C_LINE_COMMENT_MODE,
66 hljs.C_BLOCK_COMMENT_MODE,
67 NUMBERS,
68 PREPRO,
69 STRING,
70 SPECIAL_VARS,
71 MODIFIERS,
72 FUNCTIONS
73 ]
74 };
75}
76
77module.exports = openscad;