Skip to content

Commit

Permalink
Added support for PureBasic (#2369)
Browse files Browse the repository at this point in the history
A language based on Basic (BlitzBasic to be precise) with inline assembler also and direct API calls. Can compile on Windows, Linux, and macOS
  • Loading branch information
HeX0R101 authored May 6, 2020
1 parent 0d65d6c commit d0c1c70
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@
],
"owner": "Golmote"
},
"purebasic": {
"title": "PureBasic",
"require": "clike",
"alias": "pbfasm",
"owner": "HeX0R101"
},
"python": {
"title": "Python",
"alias": "py",
Expand Down
70 changes: 70 additions & 0 deletions components/prism-purebasic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Original Code by Bas Groothedde
!!MANY THANKS!! I never would have made this, regex and me will never be best friends ;)
==> https://codepen.io/ImagineProgramming/details/JYydBy/
slightly changed to pass all tests
*/


// PureBasic support, steal stuff from ansi-c
Prism.languages.purebasic = Prism.languages.extend('clike', {
'comment': /;.*/,
'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,
'function': /\b\w+(?:\.\w+)?\s*(?=\()/,
'number': /(?:\$[\da-f]+|\b-?\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
'operator': /(?:@\*?|\?|\*)\w+|-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|?\||[~^%?*/@]/
});

Prism.languages.insertBefore('purebasic', 'keyword', {
'tag': /#\w+/,
'asm': {
pattern: /(^\s*)!.*/m,
lookbehind: true,
alias: 'tag',
inside: {
'comment': /;.*/,
'string': {
pattern: /(["'`])(?:\\.|(?!\1)[^\\\r\n])*\1/,
greedy: true
},
// Anonymous label references, i.e.: jmp @b
'label-reference-anonymous': {
pattern: /(\s*!\s*j[a-z]+\s+)@[fb]/i,
lookbehind: true,
alias: 'fasm-label'
},
// Named label reference, i.e.: jne label1
'label-reference-addressed': {
pattern: /(\s*!\s*j[a-z]+\s+)[A-Z._?$@][\w.?$@~#]*/i,
lookbehind: true,
alias: 'fasm-label'
},
'function': {
pattern: /^(\s*!\s*)[\da-z]+(?=\s|$)/im,
lookbehind: true
},
'function-inline': {
pattern: /(\s*:\s*)[\da-z]+(?=\s)/i,
lookbehind: true,
alias: 'function'
},
'label': {
pattern: /^(\s*!\s*)[A-Za-z._?$@][\w.?$@~#]*(?=:)/m,
lookbehind: true,
alias: 'fasm-label'
},
'keyword': [
/(?:extern|extern|global)[^;\r\n]*/i,
/(?:CPU|FLOAT|DEFAULT).*/
],
'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,
'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,
'operator': /[\[\]*+\-/%<>=&|$!,.:]/
}
}
});

delete Prism.languages.purebasic['class-name'];
delete Prism.languages.purebasic['boolean'];

Prism.languages.pbfasm = Prism.languages['purebasic'];
1 change: 1 addition & 0 deletions components/prism-purebasic.min.js

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

30 changes: 30 additions & 0 deletions examples/prism-purebasic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<p>Note: PureBasic Examples.</p>

<h2>Comments</h2>
<pre><code>; This is a comment</code></pre>

<h2>Strings</h2>
<pre><code>"This a string."</code></pre>

<h2>Numbers</h2>
<pre><code>42
3.14159
-42
-3.14159
.5
10.
2E10
4.2E-14
-3E+2</code></pre>

<h2>PureBasic example</h2>
<pre><code>Procedure.s Test(s.s)
Protected a$, b$, Result.s

Result = Mid(s, 1, 3)

ProcedureReturn Result
EndProcedure

Test()
End</code></pre>
2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"markup",
"javascript"
],
"purebasic": "clike",
"qml": "javascript",
"qore": "clike",
"racket": "scheme",
Expand Down Expand Up @@ -182,6 +183,7 @@
"pcode": "peoplecode",
"pq": "powerquery",
"mscript": "powerquery",
"pbfasm": "purebasic",
"py": "python",
"rkt": "racket",
"robot": "robotframework",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
"powershell": "PowerShell",
"properties": ".properties",
"protobuf": "Protocol Buffers",
"purebasic": "PureBasic",
"pbfasm": "PureBasic",
"py": "Python",
"q": "Q (kdb+ database)",
"qml": "QML",
Expand Down
Loading

0 comments on commit d0c1c70

Please sign in to comment.