Basic ragel test that can parse 1 ASNI sequence and do nothing with it.
This commit is contained in:
parent
4162287841
commit
753bc70b77
5 changed files with 227 additions and 1 deletions
3
Makefile
3
Makefile
|
@ -3,6 +3,9 @@ all: build test
|
||||||
reset:
|
reset:
|
||||||
powershell -executionpolicy bypass .\scripts\reset_build.ps1
|
powershell -executionpolicy bypass .\scripts\reset_build.ps1
|
||||||
|
|
||||||
|
ragel:
|
||||||
|
ragel -o .\scratchpad\testragel.cpp .\scratchpad\testragel.rl
|
||||||
|
|
||||||
build:
|
build:
|
||||||
meson compile -j 4 -C builddir
|
meson compile -j 4 -C builddir
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,9 @@ collider = executable('collider', [
|
||||||
],
|
],
|
||||||
dependencies: dependencies)
|
dependencies: dependencies)
|
||||||
|
|
||||||
|
testragel = executable('testragel', [
|
||||||
|
'./scratchpad/testragel.cpp'
|
||||||
|
],
|
||||||
|
dependencies: dependencies)
|
||||||
|
|
||||||
test('tests', runtests)
|
test('tests', runtests)
|
||||||
|
|
182
scratchpad/testragel.cpp
Normal file
182
scratchpad/testragel.cpp
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
|
||||||
|
#line 1 ".\\scratchpad\\testragel.rl"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
using namespace fmt;
|
||||||
|
|
||||||
|
|
||||||
|
#line 14 ".\\scratchpad\\testragel.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#line 8 ".\\scratchpad\\testragel.cpp"
|
||||||
|
static const char _foo_actions[] = {
|
||||||
|
0, 1, 0, 1, 1, 1, 2
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_key_offsets[] = {
|
||||||
|
0, 0, 1, 2, 4, 7, 9, 12,
|
||||||
|
13
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_trans_keys[] = {
|
||||||
|
27, 91, 48, 57, 59, 48, 57, 48,
|
||||||
|
57, 109, 48, 57, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_single_lengths[] = {
|
||||||
|
0, 1, 1, 0, 1, 0, 1, 1,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_range_lengths[] = {
|
||||||
|
0, 0, 0, 1, 1, 1, 1, 0,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_index_offsets[] = {
|
||||||
|
0, 0, 2, 4, 6, 9, 11, 14,
|
||||||
|
16
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_indicies[] = {
|
||||||
|
0, 1, 2, 1, 3, 1, 4, 3,
|
||||||
|
1, 5, 1, 6, 5, 1, 7, 1,
|
||||||
|
1, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_trans_targs[] = {
|
||||||
|
2, 0, 3, 4, 5, 6, 7, 8
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char _foo_trans_actions[] = {
|
||||||
|
0, 0, 0, 1, 0, 3, 0, 5
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int foo_start = 1;
|
||||||
|
static const int foo_first_final = 8;
|
||||||
|
static const int foo_error = 0;
|
||||||
|
|
||||||
|
static const int foo_en_main = 1;
|
||||||
|
|
||||||
|
|
||||||
|
#line 17 ".\\scratchpad\\testragel.rl"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int cs, res = 0;
|
||||||
|
char *test = "\x1B[36;46m";
|
||||||
|
|
||||||
|
char *p = test;
|
||||||
|
char *pe = p + strlen(p) + 1;
|
||||||
|
|
||||||
|
#line 64 ".\\scratchpad\\testragel.cpp"
|
||||||
|
{
|
||||||
|
cs = foo_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
#line 25 ".\\scratchpad\\testragel.rl"
|
||||||
|
|
||||||
|
#line 67 ".\\scratchpad\\testragel.cpp"
|
||||||
|
{
|
||||||
|
int _klen;
|
||||||
|
unsigned int _trans;
|
||||||
|
const char *_acts;
|
||||||
|
unsigned int _nacts;
|
||||||
|
const char *_keys;
|
||||||
|
|
||||||
|
if ( p == pe )
|
||||||
|
goto _test_eof;
|
||||||
|
if ( cs == 0 )
|
||||||
|
goto _out;
|
||||||
|
_resume:
|
||||||
|
_keys = _foo_trans_keys + _foo_key_offsets[cs];
|
||||||
|
_trans = _foo_index_offsets[cs];
|
||||||
|
|
||||||
|
_klen = _foo_single_lengths[cs];
|
||||||
|
if ( _klen > 0 ) {
|
||||||
|
const char *_lower = _keys;
|
||||||
|
const char *_mid;
|
||||||
|
const char *_upper = _keys + _klen - 1;
|
||||||
|
while (1) {
|
||||||
|
if ( _upper < _lower )
|
||||||
|
break;
|
||||||
|
|
||||||
|
_mid = _lower + ((_upper-_lower) >> 1);
|
||||||
|
if ( (*p) < *_mid )
|
||||||
|
_upper = _mid - 1;
|
||||||
|
else if ( (*p) > *_mid )
|
||||||
|
_lower = _mid + 1;
|
||||||
|
else {
|
||||||
|
_trans += (unsigned int)(_mid - _keys);
|
||||||
|
goto _match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_keys += _klen;
|
||||||
|
_trans += _klen;
|
||||||
|
}
|
||||||
|
|
||||||
|
_klen = _foo_range_lengths[cs];
|
||||||
|
if ( _klen > 0 ) {
|
||||||
|
const char *_lower = _keys;
|
||||||
|
const char *_mid;
|
||||||
|
const char *_upper = _keys + (_klen<<1) - 2;
|
||||||
|
while (1) {
|
||||||
|
if ( _upper < _lower )
|
||||||
|
break;
|
||||||
|
|
||||||
|
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
||||||
|
if ( (*p) < _mid[0] )
|
||||||
|
_upper = _mid - 2;
|
||||||
|
else if ( (*p) > _mid[1] )
|
||||||
|
_lower = _mid + 2;
|
||||||
|
else {
|
||||||
|
_trans += (unsigned int)((_mid - _keys)>>1);
|
||||||
|
goto _match;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_trans += _klen;
|
||||||
|
}
|
||||||
|
|
||||||
|
_match:
|
||||||
|
_trans = _foo_indicies[_trans];
|
||||||
|
cs = _foo_trans_targs[_trans];
|
||||||
|
|
||||||
|
if ( _foo_trans_actions[_trans] == 0 )
|
||||||
|
goto _again;
|
||||||
|
|
||||||
|
_acts = _foo_actions + _foo_trans_actions[_trans];
|
||||||
|
_nacts = (unsigned int) *_acts++;
|
||||||
|
while ( _nacts-- > 0 )
|
||||||
|
{
|
||||||
|
switch ( *_acts++ )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
#line 9 ".\\scratchpad\\testragel.rl"
|
||||||
|
{ println("NUM1"); }
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
#line 11 ".\\scratchpad\\testragel.rl"
|
||||||
|
{ println("NUM2"); }
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
#line 13 ".\\scratchpad\\testragel.rl"
|
||||||
|
{ res = 1; }
|
||||||
|
break;
|
||||||
|
#line 149 ".\\scratchpad\\testragel.cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_again:
|
||||||
|
if ( cs == 0 )
|
||||||
|
goto _out;
|
||||||
|
if ( ++p != pe )
|
||||||
|
goto _resume;
|
||||||
|
_test_eof: {}
|
||||||
|
_out: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#line 26 ".\\scratchpad\\testragel.rl"
|
||||||
|
|
||||||
|
fmt::println("result = {}", res);
|
||||||
|
return 0;
|
||||||
|
}
|
29
scratchpad/testragel.rl
Normal file
29
scratchpad/testragel.rl
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
|
using namespace fmt;
|
||||||
|
|
||||||
|
%%{
|
||||||
|
machine foo;
|
||||||
|
main :=
|
||||||
|
0x1B "["
|
||||||
|
[0-9]+ @{ println("NUM1"); }
|
||||||
|
";"
|
||||||
|
[0-9]+ @{ println("NUM2"); }
|
||||||
|
"m"
|
||||||
|
0 @{ res = 1; };
|
||||||
|
}%%
|
||||||
|
|
||||||
|
%% write data;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int cs, res = 0;
|
||||||
|
char *test = "\x1B[36;46m";
|
||||||
|
|
||||||
|
char *p = test;
|
||||||
|
char *pe = p + strlen(p) + 1;
|
||||||
|
%% write init;
|
||||||
|
%% write exec;
|
||||||
|
|
||||||
|
fmt::println("result = {}", res);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -1,3 +1,10 @@
|
||||||
|
NOTES:
|
||||||
|
|
||||||
|
* src/ftxui/screen/color_info.hpp has pallete.
|
||||||
|
* src/ftxui/screen/color.cpp
|
||||||
|
* Just search for ugrep x1B
|
||||||
|
* https://man7.org/linux/man-pages/man4/console_codes.4.html
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
* Write a test that generates a ton of maps then confirms there's a path from one room to every other room?
|
* Write a test that generates a ton of maps then confirms there's a path from one room to every other room?
|
||||||
|
@ -5,5 +12,5 @@ TODO:
|
||||||
|
|
||||||
* Combat system and simple loot system.
|
* Combat system and simple loot system.
|
||||||
* Actually render FTXUI ansi output instead of the gui.cpp hack.
|
* Actually render FTXUI ansi output instead of the gui.cpp hack.
|
||||||
* Remove entity from worl, _or_ mark them dead, switch their icon, and make them an entity the player walks over?
|
* Remove entity from world, _or_ mark them dead, switch their icon, and make them an entity the player walks over?
|
||||||
* Bring back sounds, check out SoLoud.
|
* Bring back sounds, check out SoLoud.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue