1. seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by GreenEuphorian Oct 12, 2014
- 1459 views
I find that seq[a,b,c] is simpler and more readable than seq[a][b][c]. Does Euphoria support this (Pascal-like) syntax in addition to the standard form? If not, could you please implement it as a syntax variant?
Thanks
2. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by BRyan Oct 12, 2014
- 1418 views
I find that seq[a,b,c] is simpler and more readable than seq[a][b][c]. Does Euphoria support this (Pascal-like) syntax in addition to the standard form? If not, could you please implement it as a syntax variant?
Thanks
If you want to use syntax variants then why don't you
just use the preprocessor that is built-in into euphoria ?
3. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by ChrisB (moderator) Oct 13, 2014
- 1336 views
Hi Bernie
Thats great. How about an example of how to do it?
Chris
4. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by ghaberek (admin) Oct 13, 2014
- 1356 views
Thats great. How about an example of how to do it?
I was able to accomplish this with relatively little code by using Regular Expressions. You should be able to turn this into a pre-processor by following the example provided in The User Defined Pre-Processor. Basically, we're looking for anything that looks like a sequence index, splitting it on comma, and then reassembling it back into the normal bracket syntax. This code will process multiple instances of comma-based indexing on a single line (which my first attempt didn't do, and is what requires the start/stop integers). This code makes no attempt to ignore the contents of strings or comments. I'm sure it could be extended to do that if necessary.
include std/regex.e include std/sequence.e include std/text.e -- not sure what to call this, just use "syntax" for now constant re_syntax = regex:new( `(\[[\w,\s*]+\])` ) function process_syntax( sequence line ) sequence text = "" integer start = 1 integer stop = 0 -- look for matches on this line (and get -- the string offsets while we're at it) object matches = regex:matches( re_syntax, line, start, STRING_OFFSETS ) while sequence( matches ) do -- get the matching parts text = matches[2][1] -- e.g. "[1,2,3]" start = matches[2][2] -- e.g. 13 stop = matches[2][3] -- e.g. 19 -- trim the brackets and split the indices sequence parts = stdseq:split( text[2..$-1], ',' ) -- trim extra spaces off the parts for i = 1 to length( parts ) do parts[i] = text:trim( parts[i] ) end for -- assemble the new index and put back the outer brackets sequence temp = '[' & stdseq:join( parts, "][" ) & ']' -- put the proper index back into this line line = replace( line, temp, start, stop ) -- keep track of the last start index start += length(temp) + 1 stop = 0 -- look for more matches on this line matches = regex:matches( re_syntax, line, start, STRING_OFFSETS ) end while return line end function
Here is some example code that I used to test.
constant ONE = 1 constant TWO = 2 constant THREE = 3 sequence seq = { {"ABC","DEF","GHI"}, {"JKL","MNO","PQR"}, {"STU","VWZ","YZ "} } printf( 1, "seq[ 1, 2 ] = \"%s\"\n", {seq[1,2]} ) -- outputs "DEF" printf( 1, "seq[ 3, 1 ] = \"%s\"\n", {seq[3,1]} ) -- outputs "STU" printf( 1, "seq[3,2,1] = '%s'\n", {seq[3,2,1]} ) -- outputs 'V' printf( 1, "seq[ONE,TWO,THREE] = '%s'\n", {seq[ONE,TWO,THREE]} ) -- outputs 'F'
Hope this helps,
-Greg
5. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by bugmagnet Oct 13, 2014
- 1280 views
Wow, I'd forgotten all about this. Just a few preprocessor filters and we can have CeuBeuL, and FeuRTRAN, and maybe even HeuSKeuLL
Bugmagnet.
6. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by ChrisB (moderator) Oct 14, 2014
- 1220 views
Hi
So, here we have several great un trumpted features, a great really quick to implement pre processor, which seemingly can emulate other language syntaxes, and a fantastic user group who think faster than they type.
What more could a coder want!
Chris
7. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by GreenEuphorian Oct 14, 2014
- 1189 views
Hi
So, here we have several great un trumpted features, a great really quick to implement pre processor, which seemingly can emulate other language syntaxes, and a fantastic user group who think faster than they type.
What more could a coder want!
Chris
What's the best available introduction to using the preprocessor? Thanks
8. Re: seq[a,b,c] as a syntax variant for seq[a][b][c]
- Posted by bugmagnet Oct 15, 2014
- 1223 views
What's the best available introduction to using the preprocessor?
Probably the preproc doc.
Bugmagnet