Skip to content

Commit d0c1c70

Browse files
authoredMay 6, 2020
Added support for PureBasic (#2369)
A language based on Basic (BlitzBasic to be precise) with inline assembler also and direct API calls. Can compile on Windows, Linux, and macOS
1 parent 0d65d6c commit d0c1c70

14 files changed

+392
-3
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

+6
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@
848848
],
849849
"owner": "Golmote"
850850
},
851+
"purebasic": {
852+
"title": "PureBasic",
853+
"require": "clike",
854+
"alias": "pbfasm",
855+
"owner": "HeX0R101"
856+
},
851857
"python": {
852858
"title": "Python",
853859
"alias": "py",

‎components/prism-purebasic.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Original Code by Bas Groothedde
3+
!!MANY THANKS!! I never would have made this, regex and me will never be best friends ;)
4+
==> https://codepen.io/ImagineProgramming/details/JYydBy/
5+
slightly changed to pass all tests
6+
*/
7+
8+
9+
// PureBasic support, steal stuff from ansi-c
10+
Prism.languages.purebasic = Prism.languages.extend('clike', {
11+
'comment': /;.*/,
12+
'keyword': /\b(?:declarecdll|declaredll|compilerselect|compilercase|compilerdefault|compilerendselect|compilererror|enableexplicit|disableexplicit|not|and|or|xor|calldebugger|debuglevel|enabledebugger|disabledebugger|restore|read|includepath|includebinary|threaded|runtime|with|endwith|structureunion|endstructureunion|align|newlist|newmap|interface|endinterface|extends|enumeration|endenumeration|swap|foreach|continue|fakereturn|goto|gosub|return|break|module|endmodule|declaremodule|enddeclaremodule|declare|declarec|prototype|prototypec|enableasm|disableasm|dim|redim|data|datasection|enddatasection|to|procedurereturn|debug|default|case|select|endselect|as|import|endimport|importc|compilerif|compilerelse|compilerendif|compilerelseif|end|structure|endstructure|while|wend|for|next|step|if|else|elseif|endif|repeat|until|procedure|proceduredll|procedurec|procedurecdll|endprocedure|protected|shared|static|global|define|includefile|xincludefile|macro|endmacro)\b/i,
13+
'function': /\b\w+(?:\.\w+)?\s*(?=\()/,
14+
'number': /(?:\$[\da-f]+|\b-?\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
15+
'operator': /(?:@\*?|\?|\*)\w+|-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*/@]/
16+
});
17+
18+
Prism.languages.insertBefore('purebasic', 'keyword', {
19+
'tag': /#\w+/,
20+
'asm': {
21+
pattern: /(^\s*)!.*/m,
22+
lookbehind: true,
23+
alias: 'tag',
24+
inside: {
25+
'comment': /;.*/,
26+
'string': {
27+
pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,
28+
greedy: true
29+
},
30+
// Anonymous label references, i.e.: jmp @b
31+
'label-reference-anonymous': {
32+
pattern: /(\s*!\s*j[a-z]+\s+)@[fb]/i,
33+
lookbehind: true,
34+
alias: 'fasm-label'
35+
},
36+
// Named label reference, i.e.: jne label1
37+
'label-reference-addressed': {
38+
pattern: /(\s*!\s*j[a-z]+\s+)[A-Z._?$@][\w.?$@~#]*/i,
39+
lookbehind: true,
40+
alias: 'fasm-label'
41+
},
42+
'function': {
43+
pattern: /^(\s*!\s*)[\da-z]+(?=\s|$)/im,
44+
lookbehind: true
45+
},
46+
'function-inline': {
47+
pattern: /(\s*:\s*)[\da-z]+(?=\s)/i,
48+
lookbehind: true,
49+
alias: 'function'
50+
},
51+
'label': {
52+
pattern: /^(\s*!\s*)[A-Za-z._?$@][\w.?$@~#]*(?=:)/m,
53+
lookbehind: true,
54+
alias: 'fasm-label'
55+
},
56+
'keyword': [
57+
/(?:extern|extern|global)[^;\r\n]*/i,
58+
/(?:CPU|FLOAT|DEFAULT).*/
59+
],
60+
'register': /\b(?:st\d|[xyz]mm\d\d?|[cdt]r\d|r\d\d?[bwd]?|[er]?[abcd]x|[abcd][hl]|[er]?(?:bp|sp|si|di)|[cdefgs]s|mm\d+)\b/i,
61+
'number': /(?:\b|-|(?=\$))(?:0[hx][\da-f]*\.?[\da-f]+(?:p[+-]?\d+)?|\d[\da-f]+[hx]|\$\d[\da-f]*|0[oq][0-7]+|[0-7]+[oq]|0[by][01]+|[01]+[by]|0[dt]\d+|\d*\.?\d+(?:\.?e[+-]?\d+)?[dt]?)\b/i,
62+
'operator': /[\[\]*+\-/%<>=&|$!,.:]/
63+
}
64+
}
65+
});
66+
67+
delete Prism.languages.purebasic['class-name'];
68+
delete Prism.languages.purebasic['boolean'];
69+
70+
Prism.languages.pbfasm = Prism.languages['purebasic'];

‎components/prism-purebasic.min.js

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

‎examples/prism-purebasic.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>Note: PureBasic Examples.</p>
2+
3+
<h2>Comments</h2>
4+
<pre><code>; This is a comment</code></pre>
5+
6+
<h2>Strings</h2>
7+
<pre><code>"This a string."</code></pre>
8+
9+
<h2>Numbers</h2>
10+
<pre><code>42
11+
3.14159
12+
-42
13+
-3.14159
14+
.5
15+
10.
16+
2E10
17+
4.2E-14
18+
-3E+2</code></pre>
19+
20+
<h2>PureBasic example</h2>
21+
<pre><code>Procedure.s Test(s.s)
22+
Protected a$, b$, Result.s
23+
24+
Result = Mid(s, 1, 3)
25+
26+
ProcedureReturn Result
27+
EndProcedure
28+
29+
Test()
30+
End</code></pre>

‎plugins/autoloader/prism-autoloader.js

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"markup",
9797
"javascript"
9898
],
99+
"purebasic": "clike",
99100
"qml": "javascript",
100101
"qore": "clike",
101102
"racket": "scheme",
@@ -182,6 +183,7 @@
182183
"pcode": "peoplecode",
183184
"pq": "powerquery",
184185
"mscript": "powerquery",
186+
"pbfasm": "purebasic",
185187
"py": "python",
186188
"rkt": "racket",
187189
"robot": "robotframework",

‎plugins/autoloader/prism-autoloader.min.js

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

‎plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
"powershell": "PowerShell",
135135
"properties": ".properties",
136136
"protobuf": "Protocol Buffers",
137+
"purebasic": "PureBasic",
138+
"pbfasm": "PureBasic",
137139
"py": "Python",
138140
"q": "Q (kdb+ database)",
139141
"qml": "QML",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;
2+
; comment
3+
4+
a$ = 2 ;Test
5+
6+
----------------------------------------------------
7+
8+
[
9+
["comment", ";"],
10+
["comment", "; comment"],
11+
12+
"\r\n\r\na$ ",
13+
["operator", "="],
14+
["number", "2"],
15+
["comment", ";Test"]
16+
]
17+
18+
----------------------------------------------------
19+
20+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
DECLARECDLL
2+
DECLAREDLL
3+
COMPILERSELECT
4+
COMPILERCASE
5+
COMPILERDEFAULT
6+
COMPILERENDSELECT
7+
COMPILERERROR
8+
ENABLEEXPLICIT
9+
DISABLEEXPLICIT
10+
NOT
11+
AND
12+
OR
13+
XOR
14+
CALLDEBUGGER
15+
DEBUGLEVEL
16+
ENABLEDEBUGGER
17+
DISABLEDEBUGGER
18+
RESTORE
19+
READ
20+
INCLUDEPATH
21+
INCLUDEBINARY
22+
THREADED
23+
RUNTIME
24+
WITH
25+
ENDWITH
26+
STRUCTUREUNION
27+
ENDSTRUCTUREUNION
28+
ALIGN
29+
NEWLIST
30+
NEWMAP
31+
INTERFACE
32+
ENDINTERFACE
33+
EXTENDS
34+
ENUMERATION
35+
ENDENUMERATION
36+
SWAP
37+
FOREACH
38+
CONTINUE
39+
FAKERETURN
40+
GOTO
41+
GOSUB
42+
RETURN
43+
BREAK
44+
MODULE
45+
ENDMODULE
46+
DECLAREMODULE
47+
ENDDECLAREMODULE
48+
DECLARE
49+
DECLAREC
50+
PROTOTYPE
51+
PROTOTYPEC
52+
ENABLEASM
53+
DISABLEASM
54+
DIM
55+
REDIM
56+
DATA
57+
DATASECTION
58+
ENDDATASECTION
59+
TO
60+
PROCEDURERETURN
61+
DEBUG
62+
DEFAULT
63+
CASE
64+
SELECT
65+
ENDSELECT
66+
AS
67+
IMPORT
68+
ENDIMPORT
69+
IMPORTC
70+
COMPILERIF
71+
COMPILERELSE
72+
COMPILERENDIF
73+
COMPILERELSEIF
74+
END
75+
STRUCTURE
76+
ENDSTRUCTURE
77+
WHILE
78+
WEND
79+
FOR
80+
NEXT
81+
STEP
82+
IF
83+
ELSE
84+
ELSEIF
85+
ENDIF
86+
REPEAT
87+
UNTIL
88+
PROCEDURE
89+
PROCEDUREDLL
90+
PROCEDUREC
91+
PROCEDURECDLL
92+
ENDPROCEDURE
93+
PROTECTED
94+
SHARED
95+
STATIC
96+
GLOBAL
97+
DEFINE
98+
INCLUDEFILE
99+
XINCLUDEFILE
100+
MACRO
101+
ENDMACRO
102+
103+
----------------------------------------------------
104+
105+
[
106+
["keyword", "DECLARECDLL"],
107+
["keyword", "DECLAREDLL"],
108+
["keyword", "COMPILERSELECT"],
109+
["keyword", "COMPILERCASE"],
110+
["keyword", "COMPILERDEFAULT"],
111+
["keyword", "COMPILERENDSELECT"],
112+
["keyword", "COMPILERERROR"],
113+
["keyword", "ENABLEEXPLICIT"],
114+
["keyword", "DISABLEEXPLICIT"],
115+
["keyword", "NOT"],
116+
["keyword", "AND"],
117+
["keyword", "OR"],
118+
["keyword", "XOR"],
119+
["keyword", "CALLDEBUGGER"],
120+
["keyword", "DEBUGLEVEL"],
121+
["keyword", "ENABLEDEBUGGER"],
122+
["keyword", "DISABLEDEBUGGER"],
123+
["keyword", "RESTORE"],
124+
["keyword", "READ"],
125+
["keyword", "INCLUDEPATH"],
126+
["keyword", "INCLUDEBINARY"],
127+
["keyword", "THREADED"],
128+
["keyword", "RUNTIME"],
129+
["keyword", "WITH"],
130+
["keyword", "ENDWITH"],
131+
["keyword", "STRUCTUREUNION"],
132+
["keyword", "ENDSTRUCTUREUNION"],
133+
["keyword", "ALIGN"],
134+
["keyword", "NEWLIST"],
135+
["keyword", "NEWMAP"],
136+
["keyword", "INTERFACE"],
137+
["keyword", "ENDINTERFACE"],
138+
["keyword", "EXTENDS"],
139+
["keyword", "ENUMERATION"],
140+
["keyword", "ENDENUMERATION"],
141+
["keyword", "SWAP"],
142+
["keyword", "FOREACH"],
143+
["keyword", "CONTINUE"],
144+
["keyword", "FAKERETURN"],
145+
["keyword", "GOTO"],
146+
["keyword", "GOSUB"],
147+
["keyword", "RETURN"],
148+
["keyword", "BREAK"],
149+
["keyword", "MODULE"],
150+
["keyword", "ENDMODULE"],
151+
["keyword", "DECLAREMODULE"],
152+
["keyword", "ENDDECLAREMODULE"],
153+
["keyword", "DECLARE"],
154+
["keyword", "DECLAREC"],
155+
["keyword", "PROTOTYPE"],
156+
["keyword", "PROTOTYPEC"],
157+
["keyword", "ENABLEASM"],
158+
["keyword", "DISABLEASM"],
159+
["keyword", "DIM"],
160+
["keyword", "REDIM"],
161+
["keyword", "DATA"],
162+
["keyword", "DATASECTION"],
163+
["keyword", "ENDDATASECTION"],
164+
["keyword", "TO"],
165+
["keyword", "PROCEDURERETURN"],
166+
["keyword", "DEBUG"],
167+
["keyword", "DEFAULT"],
168+
["keyword", "CASE"],
169+
["keyword", "SELECT"],
170+
["keyword", "ENDSELECT"],
171+
["keyword", "AS"],
172+
["keyword", "IMPORT"],
173+
["keyword", "ENDIMPORT"],
174+
["keyword", "IMPORTC"],
175+
["keyword", "COMPILERIF"],
176+
["keyword", "COMPILERELSE"],
177+
["keyword", "COMPILERENDIF"],
178+
["keyword", "COMPILERELSEIF"],
179+
["keyword", "END"],
180+
["keyword", "STRUCTURE"],
181+
["keyword", "ENDSTRUCTURE"],
182+
["keyword", "WHILE"],
183+
["keyword", "WEND"],
184+
["keyword", "FOR"],
185+
["keyword", "NEXT"],
186+
["keyword", "STEP"],
187+
["keyword", "IF"],
188+
["keyword", "ELSE"],
189+
["keyword", "ELSEIF"],
190+
["keyword", "ENDIF"],
191+
["keyword", "REPEAT"],
192+
["keyword", "UNTIL"],
193+
["keyword", "PROCEDURE"],
194+
["keyword", "PROCEDUREDLL"],
195+
["keyword", "PROCEDUREC"],
196+
["keyword", "PROCEDURECDLL"],
197+
["keyword", "ENDPROCEDURE"],
198+
["keyword", "PROTECTED"],
199+
["keyword", "SHARED"],
200+
["keyword", "STATIC"],
201+
["keyword", "GLOBAL"],
202+
["keyword", "DEFINE"],
203+
["keyword", "INCLUDEFILE"],
204+
["keyword", "XINCLUDEFILE"],
205+
["keyword", "MACRO"],
206+
["keyword", "ENDMACRO"]
207+
]
208+
209+
----------------------------------------------------
210+
211+
Checks for keywords.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
42
2+
3.14159
3+
2e8
4+
3.4E-9
5+
0.7E+12
6+
7+
----------------------------------------------------
8+
9+
[
10+
["number", "42"],
11+
["number", "3.14159"],
12+
["number", "2e8"],
13+
["number", "3.4E-9"],
14+
["number", "0.7E+12"]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
< <=
2+
> >=
3+
+ - *
4+
5+
----------------------------------------------------
6+
7+
[
8+
["operator", "<"], ["operator", "<="],
9+
["operator", ">"], ["operator", ">="],
10+
["operator", "+"], ["operator", "-"], ["operator", "*"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for operators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
""
2+
"foobar"
3+
4+
----------------------------------------------------
5+
6+
[
7+
["string", "\"\""],
8+
["string", "\"foobar\""]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for strings.

0 commit comments

Comments
 (0)
Please sign in to comment.