What's new?
|
Help
|
Directory
|
Sign in
heron-language
Heron is an object-oriented programming language for model driven architecture
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
Source Path:
svn
/
trunk
/
xml
/
heron_xml_parser.hpp
r47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using namespace xml_grammar;
/*
Notes:
- I will probably need to add an XMI parser file
- classses
Everything seems to have a name attribute and an xmi.id attribute.
Classifiers have attributes and operations
Attributes have multiplicity and type
Operation have Parameters
<XMI>
<XMI.content>
<UML:Model name = 'untitledModel'>
<UML:Namespace.ownedElement>
<UML:Class name = 'MyClass'>
<UML:Namespace.ownedElement>
<UML:Class name = 'int'>
<UML:Class name = 'void'>
</UML:Namespace.ownedElement>
<UML:Classifier.feature>
<UML:Attribute name = 'newAttr'>
<UML:StructuralFeature.multiplicity>
<UML:Multiplicity>
<UML:Multiplicity.range>
<UML:MultiplicityRange lower = '1' upper = '1'/>
</UML:Multiplicity.range>
</UML:Multiplicity>
</UML:StructuralFeature.multiplicity>
<UML:StructuralFeature.type>
<UML:Class xmi.idref = '-64--88-2-11--4523963b:117d8758866:-8000:0000000000000721'/>
</UML:StructuralFeature.type>
</UML:Attribute>
<UML:Operation name = 'newOperation'>
<UML:BehavioralFeature.parameter>
<UML:Parameter name = 'return'>
<UML:Parameter.type>
<UML:Class/>
</UML:Parameter.type>
</UML:Parameter>
</UML:BehavioralFeature.parameter>
</UML:Operation>
</UML:Classifier.feature>
</UML:Class>
<UML:ActivityGraph>
<UML:StateMachine.top>
<UML:CompositeState name = 'top'>
</UML:StateMachine.top>
</UML:ActivityGraph>
</UML:Namespace.ownedElement>
</UML:Model>
</XMI.content>
</XMI>
*/
void ProcessXmlNode(Node* node)
{
const type_info& ti = node->GetRuleTypeInfo();
if (ti == typeid(Element))
{
ProcessXmlNode(node->GetFirstChild());
}
else if (ti == typeid(TaggedContent))
{
Node* stag = node->GetFirstChild();
Node* content = stag->GetSibling();
Node* etag = content->GetSibling();
ProcessXmlNode(stag);
for (Node* child = content->GetFirstChild(); child != NULL; child = child->GetSibling())
ProcessXmlNode(child);
ProcessXmlNode(etag);
}
else if (ti == typeid(EmptyElemTag) || ti == typeid(STag))
{
Node* name = node->GetFirstChild();
Node* attributes = name->GetSibling();
Output("<");
Output(name);
Output(" ");
ProcessXmlNode(attributes);
if (ti == typeid(EmptyElemTag))
Output("/");
OutputLine(">");
}
else if (ti == typeid(ETag))
{
Node* name = node->GetFirstChild();
Output("<");
Output(name);
OutputLine(">");
}
else if (ti == typeid(Attributes))
{
for (Node* child = node->GetFirstChild(); child != NULL; child = child->GetSibling())
ProcessXmlNode(child);
}
else if (ti == typeid(Attribute))
{
Node* name = node->GetFirstChild();
Node* value = name->GetSibling();
Output(name);
Output(" = ");
Output(value);
}
}
bool ParseXmlString(const char* s)
{
size_t len = strlen(s);
Parser parser(s, s + len);
bool b = parser.Parse<xml_grammar::Document>();
if (!b)
return false;
ProcessXmlNode(parser.GetAstRoot());
return true;
}
Show details
Hide details
Change log
r9
by cdiggins on Feb 05, 2008
Diff
Go to:
/trunk/heron.vcproj
/trunk/heron_grammar.hpp
/trunk/heron_main.cpp
/trunk/jaction_grammar.hpp
/trunk/output/JAction.java
/trunk/xml/heron_xml_parser.hpp
/trunk/xml/yard_xml_parser_main.cpp
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3464 bytes, 128 lines
View raw file