Skip to content

Commit d3dd724

Browse files
BASIC MATCH support
1 parent 53c2a37 commit d3dd724

File tree

131 files changed

+1586
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1586
-775
lines changed

docpages/THIRDPARTY.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
This project includes third-party components. For each we list name, version, licence, and source.
44

5-
| Component | Version | Licence (SPDX) | Source / Upstream |
6-
| --------------- | -------------- | ------------------- | ------------------------------------------------------------------------------------------ |
7-
| Flanterm (fork) | 1.0.3 | MIT | [https://codeberg.org/Mintsuki/Flanterm](https://codeberg.org/Mintsuki/Flanterm) |
8-
| Limine | 9.6.7 | BSD-2-Clause | [https://github.com/limine-bootloader/limine](https://github.com/limine-bootloader/limine) |
9-
| mbedTLS | 2.28.10 | Apache-2.0 | [https://github.com/Mbed-TLS/mbedtls](https://github.com/Mbed-TLS/mbedtls) |
10-
| uACPI (fork) | 3.0.0 | MIT | [https://github.com/qword-os/uacpi](https://github.com/qword-os/uacpi) |
11-
| stb_image | 2.30 | MIT | [https://github.com/nothings/stb](https://github.com/nothings/stb) |
12-
| stb_vorbis | 1.22 | MIT | [https://github.com/nothings/stb](https://github.com/nothings/stb) |
13-
| minimp3 | afb604c | CC0-1.0 / Unlicense | [https://github.com/lieff/minimp3](https://github.com/lieff/minimp3) |
14-
| dr_flac | aac2c0e | Unlicense / MIT-0 | [https://github.com/mackron/dr_libs](https://github.com/mackron/dr_libs) |
15-
| zlib | 1.3.1.1-motley | Zlib | [https://github.com/madler/zlib](https://github.com/madler/zlib) |
16-
| tidwall-hashmap | ee05e0a | MIT | [https://github.com/tidwall/hashmap.c](https://github.com/tidwall/hashmap.c) |
5+
| Component | Version | Licence (SPDX) | Source / Upstream |
6+
| ------------------------ | -------------- | ----------------------------| ---------------------------------------------------------------------------------------------------------|
7+
| Flanterm (fork) | 1.0.3 | MIT | [https://codeberg.org/Mintsuki/Flanterm](https://codeberg.org/Mintsuki/Flanterm) |
8+
| Limine | 9.6.7 | BSD-2-Clause | [https://github.com/limine-bootloader/limine](https://github.com/limine-bootloader/limine) |
9+
| mbedTLS | 2.28.10 | Apache-2.0 | [https://github.com/Mbed-TLS/mbedtls](https://github.com/Mbed-TLS/mbedtls) |
10+
| uACPI (fork) | 3.0.0 | MIT | [https://github.com/qword-os/uacpi](https://github.com/qword-os/uacpi) |
11+
| stb_image | 2.30 | MIT | [https://github.com/nothings/stb](https://github.com/nothings/stb) |
12+
| stb_vorbis | 1.22 | MIT | [https://github.com/nothings/stb](https://github.com/nothings/stb) |
13+
| minimp3 | afb604c | CC0-1.0 / Unlicense | [https://github.com/lieff/minimp3](https://github.com/lieff/minimp3) |
14+
| dr_flac | aac2c0e | Unlicense / MIT-0 | [https://github.com/mackron/dr_libs](https://github.com/mackron/dr_libs) |
15+
| zlib | 1.3.1.1-motley | Zlib | [https://github.com/madler/zlib](https://github.com/madler/zlib) |
16+
| tidwall-hashmap | ee05e0a | MIT | [https://github.com/tidwall/hashmap.c](https://github.com/tidwall/hashmap.c) |
17+
| musl-regex (TRE subset) | 1.2.5 | BSD-2-Clause / BSD-3-Clause | [https://git.musl-libc.org/cgit/musl/tree/src/regex](https://git.musl-libc.org/cgit/musl/tree/src/regex) |
18+
| TRE Regular Expressions | 0.8.0 | BSD-2-Clause | [https://laurikari.net/tre/](https://laurikari.net/tre/) |

docpages/basic-language-reference/keywords/00_INDEX.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The following parameter types are used throughout this documentation:
9393
* \subpage LIBRARY
9494
* \subpage LINE
9595
* \subpage LOCAL
96+
* \subpage MATCH
9697
* \subpage MEMRELEASE
9798
* \subpage MKDIR
9899
* \subpage MOUNT
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
\page MATCH MATCH Keyword
2+
3+
```basic
4+
MATCH result, pattern$, haystack$
5+
```
6+
7+
Evaluates a **POSIX ERE** (extended regular expression) against a string and stores **1** for a match or **0** for no match into `result`.
8+
9+
* `result` must be an **integer** variable.
10+
* `pattern$` and `haystack$` are **strings**.
11+
* Matching is **ASCII-only** (no locale/Unicode).
12+
* No capture groups or sub-matches are returned; this is a **yes/no** test.
13+
14+
`MATCH` runs **cooperatively**: very large or pathological patterns are executed in slices.
15+
16+
\remark If the pattern is invalid, an error is raised with a descriptive message from the regex engine. Without an error handler, the program terminates. With an `ON ERROR` handler, control passes there.
17+
18+
---
19+
20+
### Supported syntax (POSIX ERE subset)
21+
22+
* Literals: `ABC`
23+
* Any char: `.`
24+
* Quantifiers: `* + ?` (greedy)
25+
* Character classes: `[abc]`, ranges `[a-z]`, negation `[^0-9]`
26+
* Alternation: `A|B`
27+
* Anchors: `^` (start of string), `$` (end of string)
28+
29+
### Not supported
30+
31+
* Backreferences `\1`, `\2`, …
32+
* Inline flags like `(?i)` (use explicit classes instead, or upper/lower where appropriate)
33+
* PCRE extensions (`\d`, `\w`, lookaround, etc.)
34+
* Multiline mode: `^` and `$` match **string** boundaries only.
35+
36+
---
37+
38+
### Examples
39+
40+
**Simple literal**
41+
42+
```basic
43+
MATCH R, "HELLO", "HELLO WORLD"
44+
IF R THEN PRINT "Found"
45+
```
46+
47+
**Anchors**
48+
49+
```basic
50+
MATCH R, "^START", "START HERE"
51+
PRINT R ' 1
52+
53+
MATCH R, "END$", "THE END"
54+
PRINT R ' 1
55+
56+
MATCH R, "^A", "BA"
57+
PRINT R ' 0
58+
```
59+
60+
**Alternation**
61+
62+
```basic
63+
MATCH R, "CAT|DOG", "HOTDOG"
64+
PRINT R ' 1
65+
66+
MATCH R, "RED|GREEN", "BLUE"
67+
PRINT R ' 0
68+
```
69+
70+
**Character classes and ranges**
71+
72+
```basic
73+
MATCH R, "[0-9]+", "foo123bar"
74+
PRINT R ' 1
75+
76+
MATCH R, "[A-Z][a-z]+", "Title"
77+
PRINT R ' 1
78+
79+
MATCH R, "[^x]*z$", "crab ballz"
80+
PRINT R ' 1
81+
```
82+
83+
**Wildcard and quantifiers**
84+
85+
```basic
86+
MATCH R, "A.*C", "AXYZC"
87+
PRINT R ' 1
88+
89+
MATCH R, "A.+C", "AC"
90+
PRINT R ' 0
91+
92+
MATCH R, "B*", "AAAA"
93+
PRINT R ' 1 ' empty match is allowed
94+
```
95+
96+
**Handling invalid patterns**
97+
98+
```basic
99+
ON ERROR GOTO BAD
100+
MATCH R, "(?i)HELLO", "hello" ' invalid: (?i) not supported
101+
PRINT "this line is not reached"
102+
103+
BAD:
104+
PRINT "Regex error!"
105+
RESUME NEXT
106+
```
107+
108+
---
109+
110+
### Notes
111+
112+
* Matching is **case-sensitive** by default. To approximate case-insensitive tests, normalise your data (e.g., convert both strings to upper case before matching) or use character classes (e.g., `[Hh][Ee][Ll][Ll][Oo]`).
113+
* Because `MATCH` is cooperative, very large inputs or patterns may take multiple idle ticks to complete. You do not need to poll—control returns to your program automatically once finished.
114+
* `^` and `$` are **string** anchors, not line anchors; there is no multiline mode.
115+
* The engine is compiled with `REG_NOSUB`; capture offsets are not available to BASIC code.

docs/MATCH.html

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5+
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
6+
<meta name="generator" content="Doxygen 1.14.0"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
8+
<title>Retro Rocket OS: MATCH Keyword</title>
9+
<link href="tabs.css" rel="stylesheet" type="text/css"/>
10+
<script type="text/javascript" src="jquery.js"></script>
11+
<script type="text/javascript" src="dynsections.js"></script>
12+
<script type="text/javascript" src="clipboard.js"></script>
13+
<link href="navtree.css" rel="stylesheet" type="text/css"/>
14+
<script type="text/javascript" src="navtreedata.js"></script>
15+
<script type="text/javascript" src="navtree.js"></script>
16+
<script type="text/javascript" src="cookie.js"></script>
17+
<link href="search/search.css" rel="stylesheet" type="text/css"/>
18+
<script type="text/javascript" src="search/searchdata.js"></script>
19+
<script type="text/javascript" src="search/search.js"></script>
20+
<link href="doxygen.css" rel="stylesheet" type="text/css" />
21+
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
22+
<link href="style.css" rel="stylesheet" type="text/css"/>
23+
</head>
24+
<body>
25+
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
26+
<div id="titlearea">
27+
<table cellspacing="0" cellpadding="0">
28+
<tbody>
29+
<tr id="projectrow">
30+
<td id="projectlogo"><img alt="Logo" src="rr.png"/></td>
31+
<td id="projectalign">
32+
<div id="projectname">Retro Rocket OS
33+
</div>
34+
<div id="projectbrief">BASIC-Powered Operating System</div>
35+
</td>
36+
</tr>
37+
</tbody>
38+
</table>
39+
</div>
40+
<!-- end header part -->
41+
<!-- Generated by Doxygen 1.14.0 -->
42+
<script type="text/javascript">
43+
var searchBox = new SearchBox("searchBox", "search/",'.html');
44+
</script>
45+
<script type="text/javascript">
46+
$(function() { codefold.init(); });
47+
</script>
48+
<script type="text/javascript" src="menudata.js"></script>
49+
<script type="text/javascript" src="menu.js"></script>
50+
<script type="text/javascript">
51+
$(function() {
52+
initMenu('',true,false,'search.php','Search',true);
53+
$(function() { init_search(); });
54+
});
55+
</script>
56+
<div id="main-nav"></div>
57+
</div><!-- top -->
58+
<div id="side-nav" class="ui-resizable side-nav-resizable">
59+
<div id="nav-tree">
60+
<div id="nav-tree-contents">
61+
<div id="nav-sync" class="sync"></div>
62+
</div>
63+
</div>
64+
<div id="splitbar" style="-moz-user-select:none;"
65+
class="ui-resizable-handle">
66+
</div>
67+
</div>
68+
<script type="text/javascript">
69+
$(function(){initNavTree('MATCH.html','',''); });
70+
</script>
71+
<div id="container">
72+
<div id="doc-content">
73+
<!-- window showing the filter options -->
74+
<div id="MSearchSelectWindow"
75+
onmouseover="return searchBox.OnSearchSelectShow()"
76+
onmouseout="return searchBox.OnSearchSelectHide()"
77+
onkeydown="return searchBox.OnSearchSelectKey(event)">
78+
</div>
79+
80+
<!-- iframe showing the search results (closed by default) -->
81+
<div id="MSearchResultsWindow">
82+
<div id="MSearchResults">
83+
<div class="SRPage">
84+
<div id="SRIndex">
85+
<div id="SRResults"></div>
86+
<div class="SRStatus" id="Loading">Loading...</div>
87+
<div class="SRStatus" id="Searching">Searching...</div>
88+
<div class="SRStatus" id="NoMatches">No Matches</div>
89+
</div>
90+
</div>
91+
</div>
92+
</div>
93+
94+
<div><div class="header">
95+
<div class="headertitle"><div class="title">MATCH Keyword </div></div>
96+
</div><!--header-->
97+
<div class="contents">
98+
<div class="textblock"><div class="fragment"><div class="line">MATCH result, pattern$, haystack$</div>
99+
</div><!-- fragment --><p>Evaluates a <b>POSIX ERE</b> (extended regular expression) against a string and stores <b>1</b> for a match or <b>0</b> for no match into <span class="tt">result</span>.</p>
100+
<ul>
101+
<li><span class="tt">result</span> must be an <b>integer</b> variable.</li>
102+
<li><span class="tt">pattern$</span> and <span class="tt">haystack$</span> are <b>strings</b>.</li>
103+
<li>Matching is <b>ASCII-only</b> (no locale/Unicode).</li>
104+
<li>No capture groups or sub-matches are returned; this is a <b>yes/no</b> test.</li>
105+
</ul>
106+
<p><span class="tt">MATCH</span> runs <b>cooperatively</b>: very large or pathological patterns are executed in slices.</p>
107+
<dl class="section remark"><dt>Remarks</dt><dd>If the pattern is invalid, an error is raised with a descriptive message from the regex engine. Without an error handler, the program terminates. With an <span class="tt">ON ERROR</span> handler, control passes there.</dd></dl>
108+
<hr />
109+
<h3 class="doxsection"><a class="anchor" id="supported-syntax-posix-ere-subset"></a>
110+
Supported syntax (POSIX ERE subset)</h3>
111+
<ul>
112+
<li>Literals: <span class="tt">ABC</span></li>
113+
<li>Any char: <span class="tt">.</span></li>
114+
<li>Quantifiers: <span class="tt">* + ?</span> (greedy)</li>
115+
<li>Character classes: <span class="tt">[abc]</span>, ranges <span class="tt">[a-z]</span>, negation <span class="tt">[^0-9]</span></li>
116+
<li>Alternation: <span class="tt">A|B</span></li>
117+
<li>Anchors: <span class="tt">^</span> (start of string), <span class="tt">$</span> (end of string)</li>
118+
</ul>
119+
<h3 class="doxsection"><a class="anchor" id="not-supported"></a>
120+
Not supported</h3>
121+
<ul>
122+
<li>Backreferences <span class="tt">\1</span>, <span class="tt">\2</span>, …</li>
123+
<li>Inline flags like <span class="tt">(?i)</span> (use explicit classes instead, or upper/lower where appropriate)</li>
124+
<li>PCRE extensions (<span class="tt">\d</span>, <span class="tt">\w</span>, lookaround, etc.)</li>
125+
<li>Multiline mode: <span class="tt">^</span> and <span class="tt">$</span> match <b>string</b> boundaries only.</li>
126+
</ul>
127+
<hr />
128+
<h3 class="doxsection"><a class="anchor" id="examples-140"></a>
129+
Examples</h3>
130+
<p><b>Simple literal</b></p>
131+
<div class="fragment"><div class="line">MATCH R, &quot;HELLO&quot;, &quot;HELLO WORLD&quot;</div>
132+
<div class="line">IF R THEN PRINT &quot;Found&quot;</div>
133+
</div><!-- fragment --><p><b>Anchors</b></p>
134+
<div class="fragment"><div class="line">MATCH R, &quot;^START&quot;, &quot;START HERE&quot;</div>
135+
<div class="line">PRINT R &#39; 1</div>
136+
<div class="line"> </div>
137+
<div class="line">MATCH R, &quot;END$&quot;, &quot;THE END&quot;</div>
138+
<div class="line">PRINT R &#39; 1</div>
139+
<div class="line"> </div>
140+
<div class="line">MATCH R, &quot;^A&quot;, &quot;BA&quot;</div>
141+
<div class="line">PRINT R &#39; 0</div>
142+
</div><!-- fragment --><p><b>Alternation</b></p>
143+
<div class="fragment"><div class="line">MATCH R, &quot;CAT|DOG&quot;, &quot;HOTDOG&quot;</div>
144+
<div class="line">PRINT R &#39; 1</div>
145+
<div class="line"> </div>
146+
<div class="line">MATCH R, &quot;RED|GREEN&quot;, &quot;BLUE&quot;</div>
147+
<div class="line">PRINT R &#39; 0</div>
148+
</div><!-- fragment --><p><b>Character classes and ranges</b></p>
149+
<div class="fragment"><div class="line">MATCH R, &quot;[0-9]+&quot;, &quot;foo123bar&quot;</div>
150+
<div class="line">PRINT R &#39; 1</div>
151+
<div class="line"> </div>
152+
<div class="line">MATCH R, &quot;[A-Z][a-z]+&quot;, &quot;Title&quot;</div>
153+
<div class="line">PRINT R &#39; 1</div>
154+
<div class="line"> </div>
155+
<div class="line">MATCH R, &quot;[^x]*z$&quot;, &quot;crab ballz&quot;</div>
156+
<div class="line">PRINT R &#39; 1</div>
157+
</div><!-- fragment --><p><b>Wildcard and quantifiers</b></p>
158+
<div class="fragment"><div class="line">MATCH R, &quot;A.*C&quot;, &quot;AXYZC&quot;</div>
159+
<div class="line">PRINT R &#39; 1</div>
160+
<div class="line"> </div>
161+
<div class="line">MATCH R, &quot;A.+C&quot;, &quot;AC&quot;</div>
162+
<div class="line">PRINT R &#39; 0</div>
163+
<div class="line"> </div>
164+
<div class="line">MATCH R, &quot;B*&quot;, &quot;AAAA&quot;</div>
165+
<div class="line">PRINT R &#39; 1 &#39; empty match is allowed</div>
166+
</div><!-- fragment --><p><b>Handling invalid patterns</b></p>
167+
<div class="fragment"><div class="line">ON ERROR GOTO BAD</div>
168+
<div class="line">MATCH R, &quot;(?i)HELLO&quot;, &quot;hello&quot; &#39; invalid: (?i) not supported</div>
169+
<div class="line">PRINT &quot;this line is not reached&quot;</div>
170+
<div class="line"> </div>
171+
<div class="line">BAD:</div>
172+
<div class="line">PRINT &quot;Regex error!&quot;</div>
173+
<div class="line">RESUME NEXT</div>
174+
</div><!-- fragment --><hr />
175+
<h3 class="doxsection"><a class="anchor" id="notes-151"></a>
176+
Notes</h3>
177+
<ul>
178+
<li>Matching is <b>case-sensitive</b> by default. To approximate case-insensitive tests, normalise your data (e.g., convert both strings to upper case before matching) or use character classes (e.g., <span class="tt">[Hh][Ee][Ll][Ll][Oo]</span>).</li>
179+
<li>Because <span class="tt">MATCH</span> is cooperative, very large inputs or patterns may take multiple idle ticks to complete. You do not need to poll—control returns to your program automatically once finished.</li>
180+
<li><span class="tt">^</span> and <span class="tt">$</span> are <b>string</b> anchors, not line anchors; there is no multiline mode.</li>
181+
<li>The engine is compiled with <span class="tt">REG_NOSUB</span>; capture offsets are not available to BASIC code. </li>
182+
</ul>
183+
</div></div><!-- contents -->
184+
</div><!-- PageDoc -->
185+
</div><!-- doc-content -->
186+
<div id="page-nav" class="page-nav-panel">
187+
<div id="page-nav-resize-handle"></div>
188+
<div id="page-nav-tree">
189+
<div id="page-nav-contents">
190+
</div><!-- page-nav-contents -->
191+
</div><!-- page-nav-tree -->
192+
</div><!-- page-nav -->
193+
</div><!-- container -->
194+
<!-- start footer part -->
195+
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
196+
<ul>
197+
<li class="navelem"><a href="index.html">Retro Rocket OS</a></li><li class="navelem"><a href="basic-ref.html">BASIC Language Reference</a></li><li class="navelem"><a href="keywords.html">Keywords</a></li>
198+
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
199+
</ul>
200+
</div>
201+
</body>
202+
</html>

docs/MEMRELEASE.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@
9898
<div class="textblock"><div class="fragment"><div class="line">MEMRELEASE(integer-expression)</div>
9999
</div><!-- fragment --><p>Releases (frees) a block of memory previously obtained via <a class="el" href="MEMALLOC.html">MEMALLOC</a>.</p>
100100
<hr />
101-
<h3 class="doxsection"><a class="anchor" id="examples-140"></a>
101+
<h3 class="doxsection"><a class="anchor" id="examples-141"></a>
102102
Examples</h3>
103103
<div class="fragment"><div class="line">buf = MEMALLOC(65536)</div>
104104
<div class="line">REM ... use buf ...</div>
105105
<div class="line">MEMRELEASE buf</div>
106106
</div><!-- fragment --><hr />
107-
<h3 class="doxsection"><a class="anchor" id="notes-151"></a>
107+
<h3 class="doxsection"><a class="anchor" id="notes-152"></a>
108108
Notes</h3>
109109
<ul>
110110
<li>Passing an invalid or already-freed handle raises an error.</li>

docs/MKDIR.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<dd>
108108
(catchable with <a href="https://github.com/brainboxdotcc/retro-rocket/wiki/ONERROR"><span class="tt">ON ERROR</span></a>).</dd></dl>
109109
<hr />
110-
<h3 class="doxsection"><a class="anchor" id="examples-141"></a>
110+
<h3 class="doxsection"><a class="anchor" id="examples-142"></a>
111111
Examples</h3>
112112
<p>Create a directory in the current folder </p><div class="fragment"><div class="line">MKDIR &quot;projects&quot;</div>
113113
</div><!-- fragment --><p>Create a directory by absolute path </p><div class="fragment"><div class="line">MKDIR &quot;/data/logs&quot;</div>

docs/MOUNT.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
(<span class="tt">OPENIN</span>, <span class="tt">OPENOUT</span>, <span class="tt">OPENUP</span>, <span class="tt">DELETE</span>, <span class="tt">MKDIR</span>, <span class="tt">RMDIR</span>, etc.). Use <span class="tt">CHDIR</span> to switch into the mounted path.</dd></dl>
121121
<p>If the mount fails (for example, unsupported <span class="tt">fstype</span> or unavailable device), a runtime error is raised (catchable with <a href="https://github.com/brainboxdotcc/retro-rocket/wiki/ONERROR"><span class="tt">ON ERROR</span></a>).</p>
122122
<hr />
123-
<h3 class="doxsection"><a class="anchor" id="examples-142"></a>
123+
<h3 class="doxsection"><a class="anchor" id="examples-143"></a>
124124
Examples</h3>
125125
<div class="fragment"><div class="line">MOUNT &quot;/devices&quot;, &quot;&quot;, &quot;devfs&quot;</div>
126126
<div class="line">MOUNT &quot;/harddisk&quot;, &quot;hd0&quot;, &quot;fat32&quot;</div>

0 commit comments

Comments
 (0)