Skip to content

Commit

Permalink
Add support for IchigoJam BASIC (#1246)
Browse files Browse the repository at this point in the history
* Add support for IchigoJam BASIC

Hi. This PR adds support for [IchigoJam](https://ichigojam.net/), which is a board that using its own BASIC language, so I was not extending this from `basic`, but submit as a standalone language.

If there're anything necessary to change, please reply to me and I'll respond to you ASAP.

* Requested modifications have been made.

And after digging into the docs, IchigoJam actually use a very small set of ```basic``` and it adds a different set of markers to its own ```basic``` language, so I just keep this as a standalone language.

* fixed the regexp for comment, number, operator and punctuation

For IchigoJam, the space is not required to be appeared after the ```'``` or ```REM```.

Add support for binary and hex numbers

Specified for IchigoJam

Add ```[``` and  ```]``` for IchigoJam

* Add example code for IchigoJam.

* Add test-suite for IchigoJam

* Add prism-ichigojam.min.js
  • Loading branch information
BlueCocoa authored and Golmote committed Dec 19, 2017
1 parent 2ece18b commit cf840be
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ var components = {
"title": "HTTP",
"owner": "danielgtaylor"
},
"ichigojam": {
"title": "IchigoJam",
"owner": "BlueCocoa"
},
"icon": {
"title": "Icon",
"owner": "Golmote"
Expand Down
12 changes: 12 additions & 0 deletions components/prism-ichigojam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// according to the offical reference (EN)
// https://ichigojam.net/IchigoJam-en.html
Prism.languages.ichigojam = {
'string': /"(?:""|[!#$%&'()*,\/:;<=>?^_ +\-.A-Z\d])*"/i,
'comment': /(?:\B'|REM)(?:[^\n\r]*)/i,
'number': /(?:\B#[0-9A-F]+)|(?:\B`[01]+)|(?:\b|\B[.-])(?:\d+\.?\d*)(?:E[+-]?\d+)?/i,
'keyword': /\b(?:BEEP|BPS|CASE|CLEAR|CLK|CLO|CLP|CLS|CLT|CLV|CONT|COPY|ELSE|END|FILE|FILES|FOR|GOSUB|GSB|GOTO|IF|INPUT|KBD|LED|LET|LIST|LOAD|LOCATE|LRUN|NEW|NEXT|OUT|RIGHT|PLAY|POKE|PRINT|PWM|REM|RENUM|RESET|RETURN|RTN|RUN|SAVE|SCROLL|SLEEP|SRND|STEP|STOP|SUB|TEMPO|THEN|TO|UART|VIDEO|WAIT)(?:\$|\b)/i,
'function': /\b(?:ABS|ANA|ASC|BIN|BTN|DEC|END|FREE|HELP|HEX|I2CR|I2CW|IN|INKEY|LEN|LINE|PEEK|RND|SCR|SOUND|STR|TICK|USR|VER|VPEEK|ZER)(?:\$|\b)/i,
'label': /(?:\B@[^\s]+)/i,
'operator': /<[=>]?|>=?|\|\||&&|[+\-*\/=\|&^~!]|\b(?:AND|NOT|OR)\b/i,
'punctuation': /[\[,;:()\]]/
};
1 change: 1 addition & 0 deletions components/prism-ichigojam.min.js

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

43 changes: 43 additions & 0 deletions examples/prism-ichigojam.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<h1>IchigoJam</h1>
<p>To use this language, use the class "language-ichigojam".</p>

<p>Note: this component focuses on IchigoJam, which uses a small subset of basic and introduces its own markers.</p>

<h2>Comments</h2>
<pre><code>' This is a comment
REM This is a remark
'NoSpaceIsOK
REMNOSPACE</code></pre>

<h2>Strings</h2>
<pre><code>"This a string."
"This is a string with ""quotes"" in it."</code></pre>

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

<h2>IchigoJam Basic example</h2>
<pre><code>A=0
FOR I=1 TO 100 : A=A+I : NEXT
PRINT A</code></pre>

<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>

<h3>Two double quotes inside a comment</h3>
<pre><code>! This "comment" is broken
REM This "remark" is broken</code></pre>
17 changes: 17 additions & 0 deletions tests/languages/ichigojam/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'Foobar
' Foobar
REMFoobar
REM Foobar

----------------------------------------------------

[
["comment", "'Foobar"],
["comment", "' Foobar"],
["comment", "REMFoobar"],
["comment", "REM Foobar"]
]

----------------------------------------------------

Checks for comments.
59 changes: 59 additions & 0 deletions tests/languages/ichigojam/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ABS
ANA
ASC
BIN
BTN
DEC
FREE
HELP
HEX
I2CR
I2CW
IN
INKEY
LEN
LINE
PEEK
RND
SCR
SOUND
STR
TICK
USR
VER
VPEEK
ZER

----------------------------------------------------

[
["function", "ABS"],
["function", "ANA"],
["function", "ASC"],
["function", "BIN"],
["function", "BTN"],
["function", "DEC"],
["function", "FREE"],
["function", "HELP"],
["function", "HEX"],
["function", "I2CR"],
["function", "I2CW"],
["function", "IN"],
["function", "INKEY"],
["function", "LEN"],
["function", "LINE"],
["function", "PEEK"],
["function", "RND"],
["function", "SCR"],
["function", "SOUND"],
["function", "STR"],
["function", "TICK"],
["function", "USR"],
["function", "VER"],
["function", "VPEEK"],
["function", "ZER"]
]

----------------------------------------------------

Checks for functions.
119 changes: 119 additions & 0 deletions tests/languages/ichigojam/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
BEEP
BPS
CASE
CLEAR
CLK
CLO
CLP
CLS
CLT
CLV
CONT
COPY
ELSE
END
FILE
FILES
FOR
GOSUB
GSB
GOTO
IF
INPUT
KBD
LED
LET
LIST
LOAD
LOCATE
LRUN
NEW
NEXT
OUT
RIGHT
PLAY
POKE
PRINT
PWM
RENUM
RESET
RETURN
RTN
RUN
SAVE
SCROLL
SLEEP
SRND
STEP
STOP
SUB
TEMPO
THEN
TO
UART
VIDEO
WAIT

----------------------------------------------------

[
["keyword", "BEEP"],
["keyword", "BPS"],
["keyword", "CASE"],
["keyword", "CLEAR"],
["keyword", "CLK"],
["keyword", "CLO"],
["keyword", "CLP"],
["keyword", "CLS"],
["keyword", "CLT"],
["keyword", "CLV"],
["keyword", "CONT"],
["keyword", "COPY"],
["keyword", "ELSE"],
["keyword", "END"],
["keyword", "FILE"],
["keyword", "FILES"],
["keyword", "FOR"],
["keyword", "GOSUB"],
["keyword", "GSB"],
["keyword", "GOTO"],
["keyword", "IF"],
["keyword", "INPUT"],
["keyword", "KBD"],
["keyword", "LED"],
["keyword", "LET"],
["keyword", "LIST"],
["keyword", "LOAD"],
["keyword", "LOCATE"],
["keyword", "LRUN"],
["keyword", "NEW"],
["keyword", "NEXT"],
["keyword", "OUT"],
["keyword", "RIGHT"],
["keyword", "PLAY"],
["keyword", "POKE"],
["keyword", "PRINT"],
["keyword", "PWM"],
["keyword", "RENUM"],
["keyword", "RESET"],
["keyword", "RETURN"],
["keyword", "RTN"],
["keyword", "RUN"],
["keyword", "SAVE"],
["keyword", "SCROLL"],
["keyword", "SLEEP"],
["keyword", "SRND"],
["keyword", "STEP"],
["keyword", "STOP"],
["keyword", "SUB"],
["keyword", "TEMPO"],
["keyword", "THEN"],
["keyword", "TO"],
["keyword", "UART"],
["keyword", "VIDEO"],
["keyword", "WAIT"]
]

----------------------------------------------------

Checks for keywords.
13 changes: 13 additions & 0 deletions tests/languages/ichigojam/label_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@PAPERNEKO
@SUKI

----------------------------------------------------

[
["label", "@PAPERNEKO"],
["label", "@SUKI"]
]

----------------------------------------------------

Checks for labels.
23 changes: 23 additions & 0 deletions tests/languages/ichigojam/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
42
3.14159
2e8
3.4E-9
0.7E+12
#496F726953756B69
`11100010

----------------------------------------------------

[
["number", "42"],
["number", "3.14159"],
["number", "2e8"],
["number", "3.4E-9"],
["number", "0.7E+12"],
["number", "#496F726953756B69"],
["number", "`11100010"]
]

----------------------------------------------------

Checks for numbers.
36 changes: 36 additions & 0 deletions tests/languages/ichigojam/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<
<=
<>
>
>=
+
-
*
/
^
=
&
~
!
|
AND
NOT
OR
||
&&

----------------------------------------------------

[
["operator", "<"], ["operator", "<="], ["operator", "<>"],
["operator", ">"], ["operator", ">="],
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "/"],
["operator", "^"], ["operator", "="],
["operator", "&"], ["operator", "~"], ["operator", "!"], ["operator", "|"],
["operator", "AND"], ["operator", "NOT"], ["operator", "OR"],
["operator", "||"], ["operator", "&&"]
]

----------------------------------------------------

Checks for operators.
13 changes: 13 additions & 0 deletions tests/languages/ichigojam/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
""
"fo""obar"

----------------------------------------------------

[
["string", "\"\""],
["string", "\"fo\"\"obar\""]
]

----------------------------------------------------

Checks for strings.

0 comments on commit cf840be

Please sign in to comment.