# HG changeset patch # User Teemu Piippo # Date 1569236796 -10800 # Node ID 68988ebc2a68e4e90372f02ef5a7145c000d0c77 # Parent 55a55a9ec2c24fd7b2b025e112a99f8defd2947b added regular expressions for the parser diff -r 55a55a9ec2c2 -r 68988ebc2a68 src/parser.cpp --- a/src/parser.cpp Sun Sep 22 11:51:41 2019 +0300 +++ b/src/parser.cpp Mon Sep 23 14:06:36 2019 +0300 @@ -262,6 +262,52 @@ } } +namespace +{ + namespace regexes + { + static const QRegExp comment {R"(^\s*0\s*\/\/\s*(.+)$)"}; + static const QRegExp metacommand {R"(^\s*0\s*(.+)$)"}; + static const QRegExp edgeline + { + R"(^\s*2)" // starting 2-token + R"(\s+(\d+))" // colour + R"(((?:\s+[^\s]+){3}))" // 1st vertex + R"(((?:\s+[^\s]+){3}))" // 2nd vertex + R"(\s*$)" // end + }; + static const QRegExp triangle + { + R"(^\s*3)" // starting 3-token + R"(\s+(\d+))" // colour + R"(((?:\s+[^\s]+){3}))" // 1st vertex + R"(((?:\s+[^\s]+){3}))" // 2nd vertex + R"(((?:\s+[^\s]+){3}))" // 3rd vertex + R"(\s*$)" // end + }; + static const QRegExp quadrilateral + { + R"(^\s*4)" // starting 4-token + R"(\s+(\d+))" // colour + R"(((?:\s+[^\s]+){3}))" // 1st vertex + R"(((?:\s+[^\s]+){3}))" // 2nd vertex + R"(((?:\s+[^\s]+){3}))" // 3rd vertex + R"(((?:\s+[^\s]+){3}))" // 4th vertex + R"(\s*$)" // end + }; + static const QRegExp conditionaledge + { + R"(^\s*5)" // starting 5-token + R"(\s+(\d+))" // colour + R"(((?:\s+[^\s]+){3}))" // 1st vertex + R"(((?:\s+[^\s]+){3}))" // 2nd vertex + R"(((?:\s+[^\s]+){3}))" // 1st control point + R"(((?:\s+[^\s]+){3}))" // 2nd control point + R"(\s*$)" // end + }; + } +} + modelobjects::BaseObject* Parser::parseFromString( Model::EditContext& editor, const QString& line)