OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
EditParser.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: EditParser.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: EditParser
10 // The parser class for the OPAL sequence editor.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:38 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Editor/EditParser.h"
22 #include "AbstractObjects/Object.h"
23 #include "Editor/EditCycle.h"
24 #include "Editor/EditEnd.h"
25 #include "Editor/EditFlatten.h"
26 #include "Editor/EditInstall.h"
27 #include "Editor/EditMove.h"
28 #include "Editor/EditReflect.h"
29 #include "Editor/EditRemove.h"
30 #include "Editor/EditReplace.h"
31 #include "Editor/EditSelect.h"
33 #include "Parser/Statement.h"
34 #include "Utilities/ParseError.h"
35 #include <ctime>
36 #include <iostream>
37 
38 
39 // Class EditParser
40 // ------------------------------------------------------------------------
41 
43  editDirectory.insert("CYCLE", new EditCycle());
44  editDirectory.insert("ENDEDIT", new EditEnd());
45  editDirectory.insert("FLATTEN", new EditFlatten());
46  editDirectory.insert("MOVE", new EditMove());
47  editDirectory.insert("REFLECT", new EditReflect());
48  editDirectory.insert("REMOVE", new EditRemove());
49  editDirectory.insert("REPLACE", new EditReplace());
50  editDirectory.insert("SELECT", new EditSelect());
51 }
52 
53 
55 {}
56 
57 
58 Object *EditParser::find(const std::string &name) const {
59  return editDirectory.find(name);
60 }
61 
62 
63 void EditParser::parse(Statement &stat) const {
64  std::string name =
65  Expressions::parseString(stat, "Identifier or keyword expected.");
66 
67  if(stat.delimiter('?')) {
68  // "<class>?": give help for class.
69  printHelp(name);
70  } else if(stat.delimiter(':')) {
71  // "<name>:...": INSTALL command.
72  parseInstall(stat);
73  } else if(stat.delimiter(',')) {
74  // "<name>,...": executable or INSTALL command.
75  if(find(name)) {
76  parseAction(stat);
77  } else {
78  parseInstall(stat);
79  }
80  } else if(stat.delimiter(';') || stat.atEnd()) {
81  // "<name>;": Executable command.
82  parseAction(stat);
83  } else {
84  throw ParseError("EditParser::parse()",
85  "Only sequence editor commands are accepted here.");
86  }
87 }
88 
89 
90 void EditParser::parseInstall(Statement &statement) const {
91  // This command must be an "INSTALL" sub-command.
92  statement.start();
93  Object *copy = 0;
94  try {
95  copy = new EditInstall();
96  copy->parse(statement);
97  parseEnd(statement);
98  execute(copy, "INSTALL");
99  } catch(...) {
100  delete copy;
101  throw;
102  }
103 }
The sequence editor REPLACE command.
Definition: EditReplace.h:28
virtual ~EditParser()
Definition: EditParser.cpp:54
Parse exception.
Definition: ParseError.h:32
The sequence editor FLATTEN command.
Definition: EditFlatten.h:28
void execute(Object *, const std::string &) const
Execute or check the current command.
Definition: OpalParser.cpp:125
bool atEnd() const
Test for end of command.
Definition: Statement.cpp:52
The sequence editor SELECT command.
Definition: EditSelect.h:28
The sequence editor REMOVE command.
Definition: EditRemove.h:28
The sequence editor ENDEDIT command.
Definition: EditEnd.h:28
Object * find(const std::string &name) const
Find entry.
Definition: Directory.cpp:66
Interface for statements.
Definition: Statement.h:38
void insert(const std::string &name, Object *newObject)
Define new object.
Definition: Directory.cpp:77
The sequence editor MOVE command.
Definition: EditMove.h:28
void start()
Return to start.
Definition: Statement.cpp:182
virtual Object * find(const std::string &) const
Find object by name in the sequence editor command directory.
Definition: EditParser.cpp:58
The sequence editor REFLECT command.
Definition: EditReflect.h:28
virtual void parse(Statement &) const
Parse and execute current statement.
Definition: EditParser.cpp:63
The sequence editor CYCLE command.
Definition: EditCycle.h:28
virtual void parseAction(Statement &) const
Parse executable command.
Definition: OpalParser.cpp:155
virtual void printHelp(const std::string &) const
Print help on named command.
Definition: OpalParser.cpp:444
The base class for all OPAL objects.
Definition: Object.h:48
virtual void parseEnd(Statement &) const
Check for end of statement.
Definition: OpalParser.cpp:372
const std::string name
virtual void parse(Statement &)
Parse the object.
Definition: Object.cpp:100
std::string parseString(Statement &, const char msg[])
Parse string value.
bool delimiter(char c)
Test for delimiter.
Definition: Statement.cpp:103
The sequence editor INSTALL command.
Definition: EditInstall.h:30
Directory editDirectory
Definition: EditParser.h:60
virtual void parseInstall(Statement &) const
Parse definition.
Definition: EditParser.cpp:90