diff --git a/Import/GacUI.cpp b/Import/GacUI.cpp index 90703e11..f8910905 100644 --- a/Import/GacUI.cpp +++ b/Import/GacUI.cpp @@ -128,24 +128,6 @@ External Functions (Basic) return GetCurrentController()->ResourceService()->GetSystemCursor(type); } - Ptr DocumentModel_Constructor(const WString& path) - { - FileStream fileStream(path, FileStream::ReadOnly); - if (!fileStream.IsAvailable()) return 0; - - BomDecoder decoder; - DecoderStream decoderStream(fileStream, decoder); - StreamReader reader(decoderStream); - WString xmlText = reader.ReadToEnd(); - - Ptr table = XmlLoadTable(); - Ptr xml = XmlParseDocument(xmlText, table); - if (!xml) return 0; - - List errors; - return DocumentModel::LoadFromXml(xml, GetFolderPath(path), errors); - } - /*********************************************************************** External Functions (Elements) ***********************************************************************/ @@ -32174,6 +32156,7 @@ namespace vl using namespace collections; using namespace compositions; using namespace regex; + using namespace parsing; /*********************************************************************** GuiToolstripCommand @@ -32220,7 +32203,7 @@ GuiToolstripCommand void GuiToolstripCommand::BuildShortcut(const WString& builderText) { - List errors; + List> errors; if (auto parser = GetParserManager()->GetParser(L"SHORTCUT")) if (Ptr builder = parser->TypedParse(builderText, errors)) { @@ -32368,12 +32351,12 @@ GuiToolstripCommand::ShortcutBuilder Parser { } - Ptr TypedParse(const WString& text, collections::List& errors)override + Ptr TypedParse(const WString& text, collections::List>& errors)override { Ptr match=regexShortcut.MatchHead(text); if (match && match->Result().Length() != text.Length()) { - errors.Add(L"Failed to parse a shortcut \"" + text + L"\"."); + errors.Add(new ParsingError(L"Failed to parse a shortcut \"" + text + L"\".")); return 0; } @@ -43073,14 +43056,16 @@ document_operation_visitors::DeserializeNodeVisitor Ptr model; Ptr container; vint paragraphIndex; + Ptr resource; Ptr resolver; Regex regexAttributeApply; - List& errors; + GuiResourceError::List& errors; - DeserializeNodeVisitor(Ptr _model, Ptr _paragraph, vint _paragraphIndex, Ptr _resolver, List& _errors) + DeserializeNodeVisitor(Ptr _model, Ptr _paragraph, vint _paragraphIndex, Ptr _resource, Ptr _resolver, GuiResourceError::List& _errors) :model(_model) , container(_paragraph) , paragraphIndex(_paragraphIndex) + , resource(_resource) , resolver(_resolver) , regexAttributeApply(L"/{@([^{}]+)/}") , errors(_errors) @@ -43089,8 +43074,8 @@ document_operation_visitors::DeserializeNodeVisitor void PrintText(const WString& text) { - Ptr run=new DocumentTextRun; - run->text=text; + Ptr run = new DocumentTextRun; + run->text = text; container->runs.Add(run); } @@ -43115,215 +43100,219 @@ document_operation_visitors::DeserializeNodeVisitor void Visit(XmlElement* node)override { Ptr createdContainer; - bool useTemplateInfo=false; - XmlElement* subNodeContainer=node; + bool useTemplateInfo = false; + XmlElement* subNodeContainer = node; - if(node->name.value==L"br") + if (node->name.value == L"br") { PrintText(L"\r\n"); } - else if(node->name.value==L"sp") + else if (node->name.value == L"sp") { PrintText(L" "); } - else if(node->name.value==L"tab") + else if (node->name.value == L"tab") { PrintText(L"\t"); } - else if(node->name.value==L"img") + else if (node->name.value == L"img") { - Ptr run=new DocumentImageRun; + Ptr run = new DocumentImageRun; run->baseline = -1; - if(Ptr source=XmlGetAttribute(node, L"source")) + if (Ptr source = XmlGetAttribute(node, L"source")) { - run->source=source->value.value; + run->source = source->value.value; WString protocol, path; - if(IsResourceUrl(run->source, protocol, path)) + if (IsResourceUrl(run->source, protocol, path)) { - Ptr imageData=resolver->ResolveResource(protocol, path).Cast(); - if(imageData) + Ptr imageData = resolver->ResolveResource(protocol, path).Cast(); + if (imageData) { - run->image=imageData->GetImage(); + run->image = imageData->GetImage(); } - if(run->image && run->image->GetFrameCount()>0) + if (run->image && run->image->GetFrameCount() > 0) { - run->size=run->image->GetFrame(0)->GetSize(); - run->frameIndex=0; + run->size = run->image->GetFrame(0)->GetSize(); + run->frameIndex = 0; } } FOREACH(Ptr, att, node->attributes) { - if(att->name.value==L"width") + if (att->name.value == L"width") { - run->size.x=wtoi(att->value.value); + run->size.x = wtoi(att->value.value); } - else if(att->name.value==L"height") + else if (att->name.value == L"height") { - run->size.y=wtoi(att->value.value); + run->size.y = wtoi(att->value.value); } - else if(att->name.value==L"baseline") + else if (att->name.value == L"baseline") { - run->baseline=wtoi(att->value.value); + run->baseline = wtoi(att->value.value); } - else if(att->name.value==L"frameIndex") + else if (att->name.value == L"frameIndex") { - run->frameIndex=wtoi(att->value.value); + run->frameIndex = wtoi(att->value.value); } else if (att->name.value != L"source") { - errors.Add(L"Unknown attribute in \"" + att->name.value + L"\"."); + errors.Add(GuiResourceError({ {resource},att->name.codeRange.start }, L"Unknown attribute in : \"" + att->name.value + L"\".")); } } container->runs.Add(run); } + else + { + errors.Add(GuiResourceError({ {resource},node->codeRange.start }, L"Attribute \"source\" is missing in .")); + } } - else if(node->name.value==L"object") + else if (node->name.value == L"object") { - Ptr run=new DocumentEmbeddedObjectRun; + Ptr run = new DocumentEmbeddedObjectRun; run->baseline = -1; - if(Ptr name=XmlGetAttribute(node, L"name")) + if (auto name = XmlGetAttribute(node, L"name")) { run->name = name->value.value; container->runs.Add(run); } else { - errors.Add(L"The \"name\" attribute in is missing."); + errors.Add(GuiResourceError({ {resource},node->codeRange.start }, L"The \"name\" attribute in is missing.")); } } - else if(node->name.value==L"font") + else if (node->name.value == L"font") { - Ptr run=new DocumentStylePropertiesRun(); - Ptr sp=new DocumentStyleProperties; - run->style=sp; + Ptr run = new DocumentStylePropertiesRun(); + Ptr sp = new DocumentStyleProperties; + run->style = sp; FOREACH(Ptr, att, node->attributes) { - if(att->name.value==L"face") + if (att->name.value == L"face") { - sp->face=att->value.value; + sp->face = att->value.value; } - else if(att->name.value==L"size") + else if (att->name.value == L"size") { - sp->size=DocumentFontSize::Parse(att->value.value); + sp->size = DocumentFontSize::Parse(att->value.value); } - else if(att->name.value==L"color") + else if (att->name.value == L"color") { - sp->color=Color::Parse(att->value.value); + sp->color = Color::Parse(att->value.value); } - else if(att->name.value==L"bkcolor") + else if (att->name.value == L"bkcolor") { - sp->backgroundColor=Color::Parse(att->value.value); + sp->backgroundColor = Color::Parse(att->value.value); } else { - errors.Add(L"Unknown attribute in \"" + att->name.value + L"\"."); + errors.Add(GuiResourceError({ {resource},att->name.codeRange.start }, L"Unknown attribute in : \"" + att->name.value + L"\".")); } } container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"b" || node->name.value==L"b-") + else if (node->name.value == L"b" || node->name.value == L"b-") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->bold=node->name.value==L"b"; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->bold = node->name.value == L"b"; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"i" || node->name.value==L"i-") + else if (node->name.value == L"i" || node->name.value == L"i-") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->italic=node->name.value==L"i"; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->italic = node->name.value == L"i"; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"u" || node->name.value==L"u-") + else if (node->name.value == L"u" || node->name.value == L"u-") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->underline=node->name.value==L"u"; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->underline = node->name.value == L"u"; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"s" || node->name.value==L"s-") + else if (node->name.value == L"s" || node->name.value == L"s-") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->strikeline=node->name.value==L"s"; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->strikeline = node->name.value == L"s"; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"ha") + else if (node->name.value == L"ha") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->antialias=true; - run->style->verticalAntialias=false; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->antialias = true; + run->style->verticalAntialias = false; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"va") + else if (node->name.value == L"va") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->antialias=true; - run->style->verticalAntialias=true; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->antialias = true; + run->style->verticalAntialias = true; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"na") + else if (node->name.value == L"na") { - Ptr run=new DocumentStylePropertiesRun(); - run->style=new DocumentStyleProperties; - run->style->antialias=false; - run->style->verticalAntialias=false; + Ptr run = new DocumentStylePropertiesRun(); + run->style = new DocumentStyleProperties; + run->style->antialias = false; + run->style->verticalAntialias = false; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"div") + else if (node->name.value == L"div") { - if(Ptr att=XmlGetAttribute(node, L"style")) + if (Ptr att = XmlGetAttribute(node, L"style")) { - WString styleName=att->value.value; - - Ptr run=new DocumentStyleApplicationRun; - run->styleName=styleName; + WString styleName = att->value.value; + + Ptr run = new DocumentStyleApplicationRun; + run->styleName = styleName; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } else { - createdContainer=container; + createdContainer = container; } } - else if(node->name.value==L"a") + else if (node->name.value == L"a") { - Ptr run=new DocumentHyperlinkRun; - run->normalStyleName=L"#NormalLink"; - run->activeStyleName=L"#ActiveLink"; - if(Ptr att=XmlGetAttribute(node, L"normal")) + Ptr run = new DocumentHyperlinkRun; + run->normalStyleName = L"#NormalLink"; + run->activeStyleName = L"#ActiveLink"; + if (Ptr att = XmlGetAttribute(node, L"normal")) { - run->normalStyleName=att->value.value; + run->normalStyleName = att->value.value; } - if(Ptr att=XmlGetAttribute(node, L"active")) + if (Ptr att = XmlGetAttribute(node, L"active")) { - run->activeStyleName=att->value.value; + run->activeStyleName = att->value.value; } - if(Ptr att=XmlGetAttribute(node, L"href")) + if (Ptr att = XmlGetAttribute(node, L"href")) { - run->reference=att->value.value; + run->reference = att->value.value; } - run->styleName=run->normalStyleName; + run->styleName = run->normalStyleName; container->runs.Add(run); - createdContainer=run; + createdContainer = run; } - else if(node->name.value==L"p") + else if (node->name.value == L"p") { FOREACH(Ptr, sub, node->subNodes) { @@ -43334,7 +43323,7 @@ document_operation_visitors::DeserializeNodeVisitor { if (node->name.value != L"nop") { - errors.Add(L"Unknown tag in document resource \"" + node->name.value + L"\"."); + errors.Add(GuiResourceError({ {resource},node->codeRange.start }, L"Unknown element in

: \"" + node->name.value + L"\".")); } FOREACH(Ptr, sub, node->subNodes) { @@ -43342,15 +43331,15 @@ document_operation_visitors::DeserializeNodeVisitor } } - if(createdContainer) + if (createdContainer) { - Ptr oldContainer=container; - container=createdContainer; + Ptr oldContainer = container; + container = createdContainer; FOREACH(Ptr, subNode, subNodeContainer->subNodes) { subNode->Accept(this); } - container=oldContainer; + container = oldContainer; } } @@ -43363,7 +43352,7 @@ document_operation_visitors::DeserializeNodeVisitor } }; - Ptr ParseDocumentStyle(Ptr styleElement) + Ptr ParseDocumentStyle(Ptr resource, Ptr styleElement, GuiResourceError::List& errors) { Ptr style=new DocumentStyle; @@ -43428,6 +43417,10 @@ document_operation_visitors::DeserializeNodeVisitor sp->verticalAntialias=true; } } + else + { + errors.Add(GuiResourceError({ {resource},att->codeRange.start }, L"Unknown element in