Example #1
0
	PureRegex::PureRegex(const String & regex)
	{
		RegexParser p;
		RefPtr<RegexNode> tree = p.Parse(regex);
		if (tree)
		{
			NFA_Graph nfa;
			nfa.GenerateFromRegexTree(tree.operator ->());
			DFA_Graph dfa;
			dfa.Generate(&nfa);
			dfaTable = new DFA_Table();
			dfa.ToDfaTable(dfaTable.operator->());
		}
		else
		{
			IllegalRegexException ex;
			if (p.Errors.Count())
				ex.Message = p.Errors[0].Text;
			throw ex;
		}
	}
Example #2
0
	void MetaLexer::ConstructDFA()
	{
		RegexParser parser;
		NFA_Graph nfa;
		NFA_Node * node = nfa.CreateNode();
		nfa.SetStartNode(node);
		for (int i=0; i<Regex.Count(); i++)
		{
			RefPtr<RegexNode> tree = parser.Parse(Regex[i]);
			if (tree)
			{
				NFA_Graph cNfa;
				cNfa.GenerateFromRegexTree(tree.operator->(), true);
				cNfa.SetTerminalIdentifier(i);
				nfa.CombineNFA(&cNfa);
				NFA_Translation * trans = nfa.CreateTranslation();
				trans->NodeDest = cNfa.GetStartNode();
				trans->NodeSrc = node;
				trans->NodeDest->PrevTranslations.Add(trans);
				trans->NodeSrc->Translations.Add(trans);
			}
			else
			{
				LexerError err;
				err.Position = 0;
				err.Text = L"Illegal regex for \"" + String(TokenNames[i]) + L"\"";
				Errors.Add(err);
				return;
			}
		}
		nfa.PostGenerationProcess();
		DFA_Graph dfaGraph;
		dfaGraph.Generate(&nfa);
		dfa = new DFA_Table();
		dfaGraph.ToDfaTable(dfa.operator ->());
	}
QVector<QString> Database::find(QString word) {
  RegexParser rgx;
  QStringList tablelist;
  QVector<QString> suggestions;
  char lmc = word.toStdString().at(0); // Left Most Character

  QRegularExpression regex(rgx.parse(word), QRegularExpression::OptimizeOnFirstUsageOption);

  switch (lmc) {
    case 'a':
      tablelist << "a" << "aa" << "e" << "oi" << "o" << "nya" << "y";
      break;
    case 'b':
      tablelist << "b" << "bh";
      break;
    case 'c':
      tablelist << "c" << "ch" << "k";
      break;
    case 'd':
      tablelist << "d" << "dh" << "dd" << "ddh";
      break;
    case 'e':
      tablelist << "i" << "ii" << "e" << "y";
      break;
    case 'f':
      tablelist << "ph";
      break;
    case 'g':
      tablelist << "g" << "gh" << "j";
      break;
    case 'h':
      tablelist << "h";
      break;
    case 'i':
      tablelist << "i" << "ii" << "y";
      break;
    case 'j':
      tablelist << "j" << "jh" << "z";
      break;
    case 'k':
      tablelist << "k" << "kh";
      break;
    case 'l':
      tablelist << "l";
      break;
    case 'm':
      tablelist << "h" << "m";
      break;
    case 'n':
      tablelist << "n" << "nya" << "nga" << "nn";
      break;
    case 'o':
      tablelist << "a" << "u" << "uu" << "oi" << "o" << "ou" << "y";
      break;
    case 'p':
      tablelist << "p" << "ph";
      break;
    case 'q':
      tablelist << "k";
      break;
    case 'r':
      tablelist << "rri" << "h" << "r" << "rr" << "rrh";
      break;
    case 's':
      tablelist << "s" << "sh" << "ss";
      break;
    case 't':
      tablelist << "t" << "th" << "tt" << "tth" << "khandatta";
      break;
    case 'u':
      tablelist << "u" << "uu" << "y";
      break;
    case 'v':
      tablelist << "bh";
      break;
    case 'w':
      tablelist << "o";
      break;
    case 'x':
      tablelist << "e" << "k";
      break;
    case 'y':
      tablelist << "i" << "y";
      break;
    case 'z':
      tablelist << "h" << "j" << "jh" << "z";
      break;
    default:
      break;
  }

  for(auto& table : tablelist) {
    QVector<QString> tableData = word_table[table];
    for(auto& tmpString : tableData) {
      if(tmpString.contains(regex)) {
        suggestions.push_back(tmpString);
      }
    }
  }
  return suggestions;
}