|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "messagedefparser\messageprocessor.h" |
|
17 #include "messagedefparser\initialstate.h" |
|
18 #include "messagedefparser\definitiontokenizer.h" |
|
19 #include "messagedefparser\signatureidentifier.h" |
|
20 #include "util.h" |
|
21 |
|
22 namespace Parser |
|
23 { |
|
24 |
|
25 void CMessageProcessor::ProcessState() |
|
26 { |
|
27 Tokens::TTokenType tokenType = CurrentTokenType(); |
|
28 Parser::TResult result = Parser::EUnexpectedToken; |
|
29 const CIdentifierBase* ident = NULL; |
|
30 |
|
31 switch (iInternalState) |
|
32 { |
|
33 case EStateExpectMessageIdentifier: |
|
34 if (tokenType == Tokens::EIdentifier) |
|
35 { |
|
36 if (!ParserSM().FindIdentifier(CurrentToken())) |
|
37 { |
|
38 iIdentifier = new CMessageIdentifier(CurrentToken()); |
|
39 iInternalState = EStateExpectSignature; |
|
40 result = Parser::ENoError; |
|
41 } |
|
42 else |
|
43 { |
|
44 result = Parser::EDuplicateIdentifier; |
|
45 } |
|
46 } |
|
47 break; |
|
48 |
|
49 case EStateExpectSignature: |
|
50 if (tokenType == Tokens::ESignature) |
|
51 { |
|
52 result = Parser::ENoError; |
|
53 iInternalState = EStateExpectSignatureEquals; |
|
54 } |
|
55 break; |
|
56 |
|
57 case EStateExpectSignatureEquals: |
|
58 if (tokenType == Tokens::EEquals) |
|
59 { |
|
60 result = Parser::ENoError; |
|
61 iInternalState = EStateExpectSignatureIdentifier; |
|
62 } |
|
63 break; |
|
64 |
|
65 case EStateExpectSignatureIdentifier: |
|
66 iInternalState = EStateExpectMessageId; |
|
67 if (tokenType == Tokens::EIdentifier) |
|
68 { |
|
69 ident = ParserSM().FindIdentifier(CurrentToken()); |
|
70 if (!ident) |
|
71 { |
|
72 result = Parser::EUnknownIdentifier; |
|
73 } |
|
74 else if (ident->Type() == Parser::ESignatureIdentifier) |
|
75 { |
|
76 iIdentifier->iSignature = static_cast<const CSignatureIdentifier*>(ident); |
|
77 result = Parser::ENoError; |
|
78 } |
|
79 else |
|
80 { |
|
81 result = Parser::EInvalidType; |
|
82 } |
|
83 } |
|
84 break; |
|
85 |
|
86 case EStateExpectMessageId: |
|
87 if (tokenType == Tokens::EMessageId) |
|
88 { |
|
89 result = Parser::ENoError; |
|
90 iInternalState = EStateExpectMessageIdEquals; |
|
91 } |
|
92 break; |
|
93 |
|
94 case EStateExpectMessageIdEquals: |
|
95 if (tokenType == Tokens::EEquals) |
|
96 { |
|
97 result = Parser::ENoError; |
|
98 iInternalState = EStateExpectMessageRealmValue; |
|
99 } |
|
100 break; |
|
101 |
|
102 case EStateExpectMessageRealmValue: |
|
103 result = ResolveNumericToken(tokenType, CurrentToken(), 32, iIdentifier->iMessageId.iRealmId); |
|
104 if (result == Parser::ENoError) |
|
105 { |
|
106 iInternalState = EStateExpectMessageColon; |
|
107 } |
|
108 break; |
|
109 |
|
110 case EStateExpectMessageColon: |
|
111 if (tokenType == Tokens::EColon) |
|
112 { |
|
113 result = Parser::ENoError; |
|
114 iInternalState = EStateExpectMessageIdValue; |
|
115 } |
|
116 break; |
|
117 |
|
118 case EStateExpectMessageIdValue: |
|
119 result = ResolveNumericToken(tokenType, CurrentToken(), 16, iIdentifier->iMessageId.iMessageId); |
|
120 if (result == Parser::ENoError) |
|
121 { |
|
122 iInternalState = EStateExpectEnd; |
|
123 } |
|
124 break; |
|
125 |
|
126 case EStateExpectEnd: |
|
127 if (tokenType == Tokens::EEnd) |
|
128 { |
|
129 result = Parser::ENoError; |
|
130 iInternalState = EStateExpectEndMessage; |
|
131 } |
|
132 break; |
|
133 |
|
134 case EStateExpectEndMessage: |
|
135 if (tokenType == Tokens::EMessage) |
|
136 { |
|
137 result = Parser::ENoError; |
|
138 ParserSM().AddIdentifier(iIdentifier); |
|
139 iIdentifier = NULL; |
|
140 } |
|
141 ParserSM().SetState(new CInitialState(ParserSM())); |
|
142 break; |
|
143 } |
|
144 |
|
145 if (result != Parser::ENoError) |
|
146 { |
|
147 ParserSM().SetError(result); |
|
148 } |
|
149 } |
|
150 |
|
151 } // namespace Parser |
|
152 |