1 | #include "stdafx.h" |
---|
2 | |
---|
3 | using namespace ActiveBasic::IDE::WindowComponents::CodeEditor; |
---|
4 | |
---|
5 | void Language::Load( const TiXmlDocument &doc ) |
---|
6 | { |
---|
7 | const TiXmlElement* root = doc.FirstChild( "language" )->ToElement(); |
---|
8 | |
---|
9 | // 言語名を取得 |
---|
10 | this->name = root->FirstChild( "name" )->FirstChild()->Value(); |
---|
11 | |
---|
12 | // Syntaxタグを解析 |
---|
13 | const TiXmlElement* syntaxElement = root->FirstChild( "syntax" )->ToElement(); |
---|
14 | this->syntax.commentSingle = syntaxElement->FirstChild( "commentSingle" )->FirstChild()->Value(); |
---|
15 | this->syntax.commentMultiBegin = syntaxElement->FirstChild( "commentMulti" )->FirstChild( "begin" )->FirstChild()->Value(); |
---|
16 | this->syntax.commentMultiEnd = syntaxElement->FirstChild( "commentMulti" )->FirstChild( "end" )->FirstChild()->Value(); |
---|
17 | { |
---|
18 | const TiXmlElement* element = syntaxElement->FirstChild( "quoteMarks" )->FirstChild( "item" )->ToElement(); |
---|
19 | while( element ) |
---|
20 | { |
---|
21 | this->syntax.quoteMarks.push_back( element->FirstChild()->Value() ); |
---|
22 | element = element->NextSibling() ? element->NextSibling()->ToElement() : NULL; |
---|
23 | } |
---|
24 | } |
---|
25 | { |
---|
26 | const TiXmlElement* element = syntaxElement->FirstChild( "reservedSimpleKeywords" )->FirstChild( "item" )->ToElement(); |
---|
27 | while( element ) |
---|
28 | { |
---|
29 | this->syntax.reservedSimpleKeywords.push_back( element->FirstChild()->Value() ); |
---|
30 | element = element->NextSibling() ? element->NextSibling()->ToElement() : NULL; |
---|
31 | } |
---|
32 | } |
---|
33 | { |
---|
34 | const TiXmlElement* element = syntaxElement->FirstChild( "reservedKeywordsWithQuickHelp" )->FirstChild( "item" )->ToElement(); |
---|
35 | while( element ) |
---|
36 | { |
---|
37 | ReservedKeywordWithQuickHelp temp; |
---|
38 | temp.keyword = element->FirstChild( "keyword" )->FirstChild()->Value(); |
---|
39 | temp.quickHelp = element->FirstChild( "quickHelp" )->FirstChild()->Value(); |
---|
40 | this->syntax.reservedKeywordsWithQuickHelp.push_back( temp ); |
---|
41 | element = element->NextSibling() ? element->NextSibling()->ToElement() : NULL; |
---|
42 | } |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | bool Language::IsExistKeyword( const std::string &keyword ) const |
---|
47 | { |
---|
48 | if( Jenga::Common::IsExistString( this->syntax.reservedSimpleKeywords, keyword ) |
---|
49 | || this->IsExistReservedKeywordWithQuickHelp( keyword ) ) |
---|
50 | { |
---|
51 | return true; |
---|
52 | } |
---|
53 | |
---|
54 | return false; |
---|
55 | } |
---|
56 | |
---|
57 | bool Language::IsExistReservedKeywordWithQuickHelp( const std::string &keyword ) const |
---|
58 | { |
---|
59 | BOOST_FOREACH( const ReservedKeywordWithQuickHelp &item, syntax.reservedKeywordsWithQuickHelp ) |
---|
60 | { |
---|
61 | if( item.keyword == keyword ) |
---|
62 | { |
---|
63 | return true; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | return false; |
---|
68 | } |
---|
69 | |
---|
70 | const std::string &Language::GetReservedKeywordWithQuickHelp( const std::string &keyword ) const |
---|
71 | { |
---|
72 | BOOST_FOREACH( const ReservedKeywordWithQuickHelp &item, syntax.reservedKeywordsWithQuickHelp ) |
---|
73 | { |
---|
74 | if( item.keyword == keyword ) |
---|
75 | { |
---|
76 | return item.quickHelp; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | throw; |
---|
81 | } |
---|
82 | |
---|
83 | bool Language::IsQuoteMark( char c ) const |
---|
84 | { |
---|
85 | BOOST_FOREACH( const std::string "eMark, syntax.quoteMarks ) |
---|
86 | { |
---|
87 | if( quoteMark.size() == 1 && c == quoteMark[0] ) |
---|
88 | { |
---|
89 | return true; |
---|
90 | } |
---|
91 | } |
---|
92 | return false; |
---|
93 | } |
---|
94 | |
---|
95 | void Languages::Add( const std::string &xmlPath ) |
---|
96 | { |
---|
97 | Language language; |
---|
98 | try |
---|
99 | { |
---|
100 | TiXmlDocument doc( xmlPath ); |
---|
101 | doc.LoadFile(); |
---|
102 | |
---|
103 | language.Load( doc ); |
---|
104 | |
---|
105 | (*this)[language.GetName()] = language; |
---|
106 | } |
---|
107 | catch( ... ) |
---|
108 | { |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void Languages::LoadFiles( const std::string &dirPath ) |
---|
113 | { |
---|
114 | Jenga::Common::Strings results; |
---|
115 | Jenga::Common::Directory dir( dirPath ); |
---|
116 | dir.SearchFiles( results, "*.xml" ); |
---|
117 | BOOST_FOREACH( const std::string &xmlPath, results ) |
---|
118 | { |
---|
119 | this->Add( xmlPath ); |
---|
120 | } |
---|
121 | } |
---|