
#line 1 "md_parser.rl"
#include <fmt/core.h>
#include <iostream>

enum {
  PLAIN=0,
  TITLE=1,
  ENUM=2
};


#line 66 "md_parser.rl"



#line 13 "md_parser.cpp"
static const char _Parser_actions[] = {
	0, 1, 0, 1, 1, 1, 2, 1, 
	3, 1, 4, 1, 5, 1, 6, 1, 
	7, 2, 1, 3, 2, 2, 3, 2, 
	3, 2, 2, 6, 0
};

static const char _Parser_key_offsets[] = {
	0, 0, 1, 1, 2, 3, 4, 5, 
	6, 7, 11, 13, 17, 22, 27, 34, 
	39, 44, 51, 56, 58, 60, 65, 67, 
	68, 73, 78
};

static const char _Parser_trans_keys[] = {
	123, 125, 10, 61, 61, 61, 10, 10, 
	35, 42, 45, 10, 45, 10, 35, 42, 
	45, 10, 32, 45, 9, 13, 10, 32, 
	45, 9, 13, 10, 32, 35, 42, 45, 
	9, 13, 10, 32, 45, 9, 13, 10, 
	32, 45, 9, 13, 10, 32, 35, 42, 
	45, 9, 13, 10, 32, 45, 9, 13, 
	10, 45, 10, 45, 10, 32, 45, 9, 
	13, 10, 45, 10, 10, 32, 45, 9, 
	13, 10, 32, 45, 9, 13, 10, 35, 
	42, 45, 0
};

static const char _Parser_single_lengths[] = {
	0, 1, 0, 1, 1, 1, 1, 1, 
	1, 4, 2, 4, 3, 3, 5, 3, 
	3, 5, 3, 2, 2, 3, 2, 1, 
	3, 3, 4
};

static const char _Parser_range_lengths[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 1, 1, 1, 1, 
	1, 1, 1, 0, 0, 1, 0, 0, 
	1, 1, 0
};

static const char _Parser_index_offsets[] = {
	0, 0, 2, 3, 5, 7, 9, 11, 
	13, 15, 20, 23, 28, 33, 38, 45, 
	50, 55, 62, 67, 70, 73, 78, 81, 
	83, 88, 93
};

static const char _Parser_indicies[] = {
	0, 1, 2, 3, 2, 4, 1, 5, 
	1, 6, 1, 7, 1, 8, 1, 10, 
	11, 12, 13, 9, 15, 16, 14, 18, 
	19, 20, 21, 17, 23, 22, 16, 22, 
	14, 25, 24, 26, 24, 17, 27, 24, 
	19, 28, 29, 24, 17, 31, 30, 16, 
	30, 14, 33, 32, 26, 32, 17, 34, 
	32, 19, 20, 21, 32, 17, 35, 30, 
	16, 30, 14, 15, 36, 14, 15, 1, 
	14, 35, 30, 37, 30, 14, 15, 38, 
	14, 39, 1, 35, 30, 36, 30, 14, 
	31, 30, 37, 30, 14, 10, 11, 12, 
	13, 9, 0
};

static const char _Parser_trans_targs[] = {
	2, 0, 3, 4, 5, 6, 7, 8, 
	9, 10, 11, 12, 18, 24, 10, 11, 
	19, 10, 11, 12, 18, 21, 13, 14, 
	13, 14, 19, 14, 15, 25, 16, 17, 
	16, 17, 17, 17, 20, 22, 23, 26
};

static const char _Parser_trans_actions[] = {
	1, 0, 0, 0, 9, 0, 0, 0, 
	11, 26, 13, 26, 26, 26, 0, 7, 
	0, 1, 0, 1, 1, 1, 3, 17, 
	1, 7, 1, 0, 1, 1, 5, 23, 
	1, 7, 0, 20, 0, 0, 0, 15
};

static const int Parser_start = 1;
static const int Parser_first_final = 26;
static const int Parser_error = 0;

static const int Parser_en_main = 1;


#line 69 "md_parser.rl"


bool Parser::parse(const std::string& input) {
  int cs = 0;
  const char *start = nullptr;
  const char *begin = input.data();
  const char *p = input.data();
  const char *pe = p + input.size();
  const char *eof = p + input.size(); (void)eof;
  std::string tk;

  
#line 111 "md_parser.cpp"
	{
	cs = Parser_start;
	}

#line 81 "md_parser.rl"
  
#line 114 "md_parser.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 = _Parser_trans_keys + _Parser_key_offsets[cs];
	_trans = _Parser_index_offsets[cs];

	_klen = _Parser_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 = _Parser_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 = _Parser_indicies[_trans];
	cs = _Parser_trans_targs[_trans];

	if ( _Parser_trans_actions[_trans] == 0 )
		goto _again;

	_acts = _Parser_actions + _Parser_trans_actions[_trans];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 )
	{
		switch ( *_acts++ )
		{
	case 0:
#line 14 "md_parser.rl"
	{ start = p; }
	break;
	case 1:
#line 15 "md_parser.rl"
	{ last = TITLE; }
	break;
	case 2:
#line 17 "md_parser.rl"
	{ last = ENUM; }
	break;
	case 3:
#line 19 "md_parser.rl"
	{
    if(last == TITLE) {
      title = input.substr(start - begin, p - start);
    } else if(last == ENUM) {
      content += "* " + input.substr(start - begin, p - start);
      content += "\n";
    } else {
      content += input.substr(start - begin, p - start);
      content += "\n";
    }

    last = PLAIN;
  }
	break;
	case 4:
#line 32 "md_parser.rl"
	{
    tk = input.substr(start - begin, p - start);
    deck->config = json::parse(tk);
    std::cout << "META:" << deck->config << '\n';
  }
	break;
	case 5:
#line 38 "md_parser.rl"
	{ fmt::println("----- START"); }
	break;
	case 6:
#line 40 "md_parser.rl"
	{
    title.clear();
    content.clear();
  }
	break;
	case 7:
#line 45 "md_parser.rl"
	{
    deck->slides.emplace_back(title, content, config);
  }
	break;
#line 232 "md_parser.cpp"
		}
	}

_again:
	if ( cs == 0 )
		goto _out;
	if ( ++p != pe )
		goto _resume;
	_test_eof: {}
	_out: {}
	}

#line 82 "md_parser.rl"

  bool good = pe - p == 0;

  if(good) {
    finalize();
  } else {
    error = true;
    std::cout << "!!!!!!!!!!!!!!!!!!!!!! error at:";
    std::cout << p;
  }
  return good;
}
