12#ifndef MCRL2_LTS_PARSE_H
13#define MCRL2_LTS_PARSE_H
16#include "mcrl2/lts/detail/fsm_builder.h"
30 const std::
regex regex_parameter {
"\\s*([a-zA-Z_][a-zA-Z0-9_'@]*)\\((\\d+)\\)\\s*([a-zA-Z_][a-zA-Z0-9_'@#\\-> \t=,\\(\\):]*)?\\s*((\"[^\"]*\"\\s*)*)"};
50 builder.write_parameters();
55 default:
throw mcrl2::runtime_error(
"unexpected split line --- encountered while parsing FSM!");
61 std::vector<std::string> result;
63 std::regex_token_iterator cur{text.begin(), text.end(), regex_quoted_string};
64 std::regex_token_iterator<std::string::const_iterator> end;
65 for (; cur != end; ++cur)
67 std::string value = cur->str();
70 result.push_back(value.substr(1, value.size() - 2));
79 std::string text = utilities::trim_copy(line);
81 if (!std::regex_match(line, what, regex_parameter))
83 throw mcrl2::runtime_error(
"could not parse the following line as an FSM parameter: " + text);
85 std::string name = what[1];
86 std::string cardinality = what[2];
87 std::string sort = utilities::trim_copy(what[3]);
88 std::vector<std::string> domain_values = parse_domain_values(what[4]);
89 builder.add_parameter(name, cardinality, sort, domain_values);
96 std::vector<std::size_t> values = utilities::parse_natural_number_sequence(line);
97 builder.add_state(values);
99 catch (mcrl2::runtime_error&)
101 throw mcrl2::runtime_error(
"could not parse the following line as an FSM state: " + line);
107 std::string text = utilities::trim_copy(line);
109 if (!std::regex_match(line, what, regex_transition))
111 throw mcrl2::runtime_error(
"could not parse the following line as an FSM transition: " + text);
113 std::string source = what[1];
114 std::string target = what[3];
115 std::string label = what[5];
116 builder.add_transition(source, target, label);
122 if (!std::regex_match(line, what, regex_probabilistic_initial_distribution))
124 throw mcrl2::runtime_error(
"Could not parse the following line as an initial distribution: " + line +
".");
126 builder.add_initial_distribution(what[0]);
134 void run(std::istream& from)
140 while (std::getline(from, line))
142 utilities::trim(line);
147 state = next_state(state);
153 case PARAMETERS: { parse_parameter(line);
break; }
154 case STATES: { parse_state(line);
break; }
155 case TRANSITIONS: { parse_transition(line);
break; }
156 case INITIAL_DISTRIBUTION: { parse_initial_distribution(line);
break; }
171 fsm_parser.run(from);
177 std::istringstream is(text);
178 parse_fsm_specification(is, result);
function object to compare two constln_t pointers based on their contents
std::vector< std::string > parse_domain_values(const std::string &text)
void run(std::istream &from)
void parse_parameter(const std::string &line)
states next_state(states state)
const std::regex regex_quoted_string
void parse_state(const std::string &line)
const std::regex regex_parameter
simple_fsm_parser(probabilistic_lts_fsm_t &fsm)
const std::regex regex_transition
void parse_initial_distribution(const std::string &line)
detail::fsm_builder builder
void parse_transition(const std::string &line)
const std::regex regex_probabilistic_initial_distribution
A class to contain labelled transition systems in graphviz format.
void save(const std::string &filename) const
Save the labelled transition system to a file.
void save(std::ostream &os) const
Save the labelled transition system to a stream.
A class to contain labelled transition systems in graphviz format.
void save(std::ostream &os) const
Save the labelled transition system to a stream.
void save(const std::string &filename) const
Save the labelled transition system to a file.
The class lts_fsm_t contains labelled transition systems in .fsm format.
void parse_fsm_specification(std::istream &from, probabilistic_lts_fsm_t &result)
void parse_fsm_specification(const std::string &text, probabilistic_lts_fsm_t &result)