Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:52 28 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Regular Expressions

     Page 2 of 2    
Author Message
damos
Regular Member

Joined: 15/04/2016
Location: Australia
Posts: 63
Posted: 12:48am 28 Jun 2023
Copy link to clipboard 
Print this post

  disco4now said  @damos,

This regex functionality is integrated into the INSTR and LINSTR commands in V5.07.08 beta6.

It does return the position if the string is matched, otherwise 0.
LINSTR works on longstrings.

I have played with it, the main thing with the syntax is that various operators need to be escaped.

These expressions can be used to pull the version from your example.
"v[0-9]\+"              matches 1 or more (escape the +)
"v[0-9]\{1,3\}"         match 1 to 3      (escape { and }
"v[[:digit:]]\{1,\}     match 1 or more   [:class:]

PicoMite V5.07.08 betas

Gerry


Thanks for this Gerry. I will give it a go. When I have used regex on C# and Python I have not needed to use a \ before the quantifiers. This will be a genuinely good enhancement to Picomite if it is small enough for Peter to include it, or supply as a C function.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 06:25am 28 Jun 2023
Copy link to clipboard 
Print this post

I suspect that what you are looking for, damos, is not MMBasic. Perhaps Python on a bigger platform? As you say, MMBasic is very powerful *as a variation of BASIC*. Its true value, IMHO, is in its hardware control facilities, not data processing. I think that's true of all versions of BASIC to an extent, but particularly so for MMBasic as it was written and optimized for microcontrollers, not general purpose computers.

The RP2040 is an amazing chip, but it's still a microcontroller with restricted RAM. It's a pity that's not expandable or that there isn't (yet) a version with more, but we are stuck with what there is. That means no big buffers and data tables so it's possibilities for DP usage are seriously compromised. There's no OS to farm stuff off to either.

I'm very unhappy about attempting to bolt on facilities that it was never designed to handle. The underlying system isn't designed for it and you end up compromising what it's good at to end up with something that's, at best, a mediocre mongrel. I'm fine with the WebMite simply because it's a different platform, but it's highly unlikely that I'll ever have a use for one personally. If that was the only little 'mite version I'd probably move back to GCBASIC on the PIC chips. Or learn Circuit Python. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 07:44am 28 Jun 2023
Copy link to clipboard 
Print this post

  damos said  I would really love to have objects and proper collections
...
There is no database, SQL, LINQ or even collections apart from arrays. JSON is just at the early stages but not at the point of navigating complex trees
...

You'd need a big reorganisation of MMBasic to get objects & collections. It will grow in size and likely slow down.

Also, you'd probably need a big reorganisation of MMBasic to use FreeRTOS or other RTOS.

Huge amounts of work and yes some gains.

However, there's no more ROM or RAM on the RP2040 or many other available chips.

The RPi people have made it clear there's likely more to come beyond the RP2040 but not when (or exactly what) so if someone wants to do the above mammoth work it could be started now.

Or... and I recommend this... map (*) wanted features onto arrays and make do (probably for a few years).

(*) e.g. a pre-processor and/or CSUBs.

John
 
damos
Regular Member

Joined: 15/04/2016
Location: Australia
Posts: 63
Posted: 03:02am 29 Jun 2023
Copy link to clipboard 
Print this post

I tried the Regex function and it works well as Gerry stated.

I also tried the INSTR function and I would describe it more as wildcard search than regular expression search. This is still very useful as it is very easy to do. I like the way the INSTR function works as it can return both the position and length of the matched string. This would support pretty much achieves everything that I need if it supported the same search terms as the REGEX function.

It would be brilliant if the REGEX capability could be included into the INSTR and LINSTR functions rather than requiring a new function.

This could be done by using the / markers that usually surround regular expressions. So the search parameter would work like this:

"abc" returns position of "abc" in a string
"a.c" returns position of a substring "a" + anything + "c"
"/[0-9]\+/" returns position of any sequence of numeric digits
 
damos
Regular Member

Joined: 15/04/2016
Location: Australia
Posts: 63
Posted: 03:24am 29 Jun 2023
Copy link to clipboard 
Print this post

I have been thinking about objects in MMBASIC and I think that since the JSON function has been added the capability is already built in to the language.

If you want to return a complex value from a function in C# (or Javascript) you can use dynamic objects:

return new { Name: "dan", Employee: true };

In MMBASIC you could do:

functionname$ = "{\"Name\": \"dan\", \"Employee\": 1 }"

The caller can then use JSON$(val$,"Name") to get the name.

From the example I see on page 30 on the manual (I haven't tried it yet), it looks like the JSON function actually navigates the tree as well, which is much better than the Python implementation.

Setting the value of the property can be done using the improved MID$ capabilities or by reconstructing the JSON object.

This capability does a long way toward basic database support as well. JSON is brilliant for storing configuration data and many small projects use JSON files as databases. In the .Net world, Entity Framework can work with JSON files directly and provide the same capabilities through LINQ that you get when using SQL Server or Oracle.
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 897
Posted: 06:32am 29 Jun 2023
Copy link to clipboard 
Print this post

  damos said  I tried the Regex function and it works well as Gerry stated.

It would be brilliant if the REGEX capability could be included into the INSTR and LINSTR functions rather than requiring a new function.



The info I gave above was actually tested/derived from using the INSTR function
as included in the Beta6 as found in the thread below. It shows the new optional versions of INSTR and LINSTR which do what you are suggesting.

PicoMite V5.07.08 betas


I think what Peter gave you as the test REGEX function above is now replaced by the new optional forms of INSTR and LINSTR

Gerry
Latest F4 Latest H7
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024