Skip to content

Commit

Permalink
WI #2582 Support CONTENT syntax type in XML GENERATE statement (#2583)
Browse files Browse the repository at this point in the history
  • Loading branch information
fm-117 committed Oct 3, 2023
1 parent 358d72a commit 3a4be4c
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 98 deletions.
@@ -1,8 +1,8 @@
--- Diagnostics ---
Line 1[37,41] <27, Error, Syntax> - Syntax error : mismatched input 'QUOTE' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,41:QUOTE]<QUOTE>
Line 2[37,42] <27, Error, Syntax> - Syntax error : mismatched input 'QUOTES' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,42:QUOTES]<QUOTES>
Line 3[37,40] <27, Error, Syntax> - Syntax error : mismatched input 'NULL' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,40:NULL]<NULL>
Line 4[37,41] <27, Error, Syntax> - Syntax error : mismatched input 'NULLS' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,41:NULLS]<NULLS>
Line 1[37,41] <27, Error, Syntax> - Syntax error : mismatched input 'QUOTE' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>genericSuppressionPhrase>whenPhrase>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,41:QUOTE]<QUOTE>
Line 2[37,42] <27, Error, Syntax> - Syntax error : mismatched input 'QUOTES' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>genericSuppressionPhrase>whenPhrase>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,42:QUOTES]<QUOTES>
Line 3[37,40] <27, Error, Syntax> - Syntax error : mismatched input 'NULL' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>genericSuppressionPhrase>whenPhrase>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,40:NULL]<NULL>
Line 4[37,41] <27, Error, Syntax> - Syntax error : mismatched input 'NULLS' expecting {HIGH-VALUE, HIGH-VALUES, LOW-VALUE, LOW-VALUES, SPACE, SPACES, ZERO, ZEROES, ZEROS} RuleStack=codeElement>xmlGenerateStatement>xmlSuppressDirective>genericSuppressionPhrase>whenPhrase>repeatedCharacterValue3>figurativeConstantForXMLGenerate, OffendingSymbol=[37,41:NULLS]<NULLS>
--- Code Elements ---
[[XmlGenerateStatement]] [1,3:XML]<XML> --> [37,41:QUOTE]<QUOTE>

Expand Down
Expand Up @@ -17,3 +17,29 @@

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [37,47:HIGH-VALUES]<HIGH_VALUES>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [32,32:a]<UserDefinedWord>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [39,42:ZERO]<ZERO>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [69,78:HIGH-VALUE]<HIGH_VALUE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [69,78:HIGH-VALUE]<HIGH_VALUE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [69,78:HIGH-VALUE]<HIGH_VALUE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [69,78:HIGH-VALUE]<HIGH_VALUE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [73,78:SPACES]<SPACES>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [73,78:SPACES]<SPACES>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [73,78:SPACES]<SPACES>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [73,78:SPACES]<SPACES>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [74,78:SPACE]<SPACE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [74,78:SPACE]<SPACE>

[[XmlGenerateStatement]] [1,3:XML]<XML> --> [74,78:SPACE]<SPACE>

15 changes: 14 additions & 1 deletion TypeCobol.Test/Parser/CodeElements/XML/SUPPRESS_ok.cbl
Expand Up @@ -6,4 +6,17 @@ XML GENERATE x FROM y SUPPRESS WHEN SPACES
XML GENERATE x FROM y SUPPRESS WHEN LOW-VALUE
XML GENERATE x FROM y SUPPRESS WHEN LOW-VALUES
XML GENERATE x FROM y SUPPRESS WHEN HIGH-VALUE
XML GENERATE x FROM y SUPPRESS WHEN HIGH-VALUES
XML GENERATE x FROM y SUPPRESS WHEN HIGH-VALUES
XML GENERATE x FROM y SUPPRESS a
XML GENERATE x FROM y SUPPRESS a WHEN ZERO
XML GENERATE x FROM y SUPPRESS EVERY NUMERIC ATTRIBUTE WHEN ZERO OR HIGH-VALUE
XML GENERATE x FROM y SUPPRESS EVERY NUMERIC CONTENT WHEN ZERO OR HIGH-VALUE
XML GENERATE x FROM y SUPPRESS EVERY NUMERIC ELEMENT WHEN ZERO OR HIGH-VALUE
XML GENERATE x FROM y SUPPRESS EVERY NUMERIC WHEN ZERO OR HIGH-VALUE
XML GENERATE x FROM y SUPPRESS EVERY NONNUMERIC ATTRIBUTE WHEN SPACE OR SPACES
XML GENERATE x FROM y SUPPRESS EVERY NONNUMERIC CONTENT WHEN SPACE OR SPACES
XML GENERATE x FROM y SUPPRESS EVERY NONNUMERIC ELEMENT WHEN SPACE OR SPACES
XML GENERATE x FROM y SUPPRESS EVERY NONNUMERIC WHEN SPACE OR SPACES
XML GENERATE x FROM y SUPPRESS EVERY ATTRIBUTE WHEN ZERO OR SPACE
XML GENERATE x FROM y SUPPRESS EVERY CONTENT WHEN ZERO OR SPACE
XML GENERATE x FROM y SUPPRESS EVERY ELEMENT WHEN ZERO OR SPACE
11 changes: 9 additions & 2 deletions TypeCobol/AntlrGrammar/CobolCodeElements.g4
Expand Up @@ -7733,10 +7733,17 @@ xmlTypeMapping:
subordinateDataItem=variable1 IS? (attribute | element | CONTENT);

xmlSuppressDirective:
( subordinateDataItem=variable1 |
(EVERY (attribute | element | ((NUMERIC | nonnumeric) (attribute | element)?)))?)
(subordinateDataItem=variable1 whenPhrase?) | genericSuppressionPhrase;

whenPhrase:
// Only figurative constants are allowed: ZERO | ZEROES | ZEROS | SPACE | SPACES | LOW_VALUE | LOW_VALUES | HIGH_VALUE | HIGH_VALUES
WHEN repeatedCharacterValue3 (OR? repeatedCharacterValue3)*;

genericSuppressionPhrase:
(EVERY ((NUMERIC attributeOrContentOrElement?) | (nonnumeric attributeOrContentOrElement?) | attributeOrContentOrElement))? whenPhrase;

attributeOrContentOrElement:
attribute | CONTENT | element;

xmlStatementEnd: END_XML;

Expand Down
133 changes: 70 additions & 63 deletions TypeCobol/Compiler/CodeElements/Statement/XmlGenerateStatement.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;

namespace TypeCobol.Compiler.CodeElements
namespace TypeCobol.Compiler.CodeElements
{
/// <summary>
/// p457:
Expand Down Expand Up @@ -305,6 +302,42 @@ public class XmlNameMapping : IVisitable
}
}

/// <summary>
/// Identifies an XML syntax type for either an <code>XmlTypeMapping</code> or an <code>XmlSuppressDirective</code>
/// </summary>
public enum XmlSyntaxType
{
/// <summary>
/// p463:
/// When ATTRIBUTE is specified, identifier-7 must be eligible to be an XML
/// attribute. identifier-7 is expressed in the generated XML as an attribute of
/// the XML element immediately superordinate to identifier-7 rather than as
/// a child element.
/// </summary>
ATTRIBUTE,
/// <summary>
/// p463:
/// When ELEMENT is specified, identifier-7 is expressed in the generated
/// XML as an element. The XML element name is derived from identifier-7
/// and the element character content is derived from the converted content
/// of identifier-7 as described in “Operation of XML GENERATE” on page 465.
/// </summary>
ELEMENT,
/// <summary>
/// p463:
/// When CONTENT is specified, identifier-7 is expressed in the generated
/// XML as element character content of the XML element that corresponds
/// to the data item immediately superordinate to identifier-7. The value of
/// the element character content is derived from the converted content of
/// identifier-7 as described in “Operation of XML GENERATE” on page 465.
///
/// When CONTENT is specified for multiple identifiers all corresponding
/// to the same superordinate identifier, the multiple contributions to the
/// element character content are concatenated.
/// </summary>
CONTENT
}

/// <summary>
/// p462:
/// TYPE phrase
Expand All @@ -328,45 +361,27 @@ public class XmlTypeMapping : IVisitable

public SyntaxProperty<XmlSyntaxType> XmlSyntaxTypeToGenerate { get; set; }

public enum XmlSyntaxType
{
UNKNOWN,
/// <summary>
/// p463:
/// When ATTRIBUTE is specified, identifier-7 must be eligible to be an XML
/// attribute. identifier-7 is expressed in the generated XML as an attribute of
/// the XML element immediately superordinate to identifier-7 rather than as
/// a child element.
/// </summary>
ATTRIBUTE,
/// <summary>
/// p463:
/// When ELEMENT is specified, identifier-7 is expressed in the generated
/// XML as an element. The XML element name is derived from identifier-7
/// and the element character content is derived from the converted content
/// of identifier-7 as described in “Operation of XML GENERATE” on page 465.
/// </summary>
ELEMENT,
/// <summary>
/// p463:
/// When CONTENT is specified, identifier-7 is expressed in the generated
/// XML as element character content of the XML element that corresponds
/// to the data item immediately superordinate to identifier-7. The value of
/// the element character content is derived from the converted content of
/// identifier-7 as described in “Operation of XML GENERATE” on page 465.
///
/// When CONTENT is specified for multiple identifiers all corresponding
/// to the same superordinate identifier, the multiple contributions to the
/// element character content are concatenated.
/// </summary>
CONTENT
}

public bool AcceptASTVisitor(IASTVisitor astVisitor) {
return this.ContinueVisitToChildren(astVisitor, DataItemName, XmlSyntaxTypeToGenerate);
}
}

/// <summary>
/// For SUPPRESS clauses using data item type matching
/// </summary>
public enum XmlItemType
{
/// <summary>
/// Suppress only NUMERIC items
/// </summary>
NUMERIC,

/// <summary>
/// Suppress only NON-NUMERIC items
/// </summary>
NONNUMERIC
}

/// <summary>
/// p463:
/// SUPPRESS phrase
Expand All @@ -379,20 +394,23 @@ public enum XmlSyntaxType
public class XmlSuppressDirective : IVisitable
{
/// <summary>
/// p463:
/// With the generic-suppression-phrase, elementary items subordinate to
/// identifier-2 that are not otherwise ignored by XML GENERATE operations
/// are identified generically for potential suppression. Either items of class
/// numeric, if the NUMERIC keyword is specified, or items that are not of
/// class numeric, if the NONNUMERIC keyword is specified, or both, may be
/// suppressed. If the ATTRIBUTE keyword is specified, only items that would
/// be expressed in the generated XML document as an XML attribute are
/// identified for potential suppression. If the ELEMENT keyword is specified,
/// only items that would be expressed in the generated XML document as an
/// XML element are identified.
///
/// With the generic-suppression-phrase, elementary items subordinate to identifier-2 that are not
/// otherwise ignored by XML GENERATE operations are identified generically for potential suppression.
/// Either items of class numeric, if the NUMERIC keyword is specified, or items that are not of class
/// numeric, if the NONNUMERIC keyword is specified, or both, might be suppressed.
/// </summary>
public SyntaxProperty<XmlItemType> XmlItemTypeToSuppress { get; set; }

/// <summary>
/// If the ATTRIBUTE keyword is specified, only items that would be expressed in the generated XML document as an
/// XML attribute are identified for potential suppression. If the ELEMENT keyword is specified, only
/// items that would be expressed in the generated XML document as an XML element are identified for
/// potential suppression. If the CONTENT keyword is specified, only items that would be expressed in
/// the generated XML document as element character content of the XML element corresponding to the
/// data item superordinate to the CONTENT data item are identified for potential suppression.
///
/// If multiple generic-suppression-phrase are specified, the effect is cumulative.
/// </summary>
/// </summary>
public SyntaxProperty<XmlSyntaxType> XmlSyntaxTypeToSuppress { get; set; }

/// <summary>
Expand Down Expand Up @@ -437,19 +455,8 @@ public class XmlSuppressDirective : IVisitable
/// </summary>
public RepeatedCharacterValue[] ItemValuesToSuppress;

public enum XmlSyntaxType
{
UNKNOWN,
NUMERIC_ATTRIBUTE,
NUMERIC_ELEMENT,
NONNUMERIC_ATTRIBUTE,
NONNUMERIC_ELEMENT,
ATTRIBUTE,
ELEMENT,
}

public bool AcceptASTVisitor(IASTVisitor astVisitor) {
return this.ContinueVisitToChildren(astVisitor, XmlSyntaxTypeToSuppress, DataItemName)
return this.ContinueVisitToChildren(astVisitor, XmlItemTypeToSuppress, XmlSyntaxTypeToSuppress, DataItemName)
&& this.ContinueVisitToChildren(astVisitor, (IEnumerable<IVisitable>) ItemValuesToSuppress);
}
}
Expand Down
@@ -1,7 +1,4 @@
using Antlr4.Runtime.Tree;
using System;
using System.Collections.Generic;
using System.Linq;
using TypeCobol.Compiler.AntlrUtils;
using TypeCobol.Compiler.CodeElements;
using TypeCobol.Compiler.Diagnostics;
Expand Down Expand Up @@ -1615,17 +1612,17 @@ private XmlNameMapping CreateXmlNameMapping(CodeElementsParser.XmlNameMappingCon
typeMapping.DataItemName = CobolExpressionsBuilder.CreateVariable(context.subordinateDataItem);
if (context.attribute() != null)
{
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlTypeMapping.XmlSyntaxType.ATTRIBUTE,
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlSyntaxType.ATTRIBUTE,
context.attribute().UserDefinedWord());
}
if (context.element() != null)
{
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlTypeMapping.XmlSyntaxType.ELEMENT,
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlSyntaxType.ELEMENT,
context.element().UserDefinedWord());
}
if (context.CONTENT() != null)
{
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlTypeMapping.XmlSyntaxType.CONTENT,
typeMapping.XmlSyntaxTypeToGenerate = CreateSyntaxProperty(XmlSyntaxType.CONTENT,
context.CONTENT());
}
return typeMapping;
Expand All @@ -1636,35 +1633,54 @@ private XmlNameMapping CreateXmlNameMapping(CodeElementsParser.XmlNameMappingCon
if (context.subordinateDataItem != null)
{
suppressDirective.DataItemName = CobolExpressionsBuilder.CreateVariable(context.subordinateDataItem);
if (context.whenPhrase() != null)
{
suppressDirective.ItemValuesToSuppress = BuildObjectArrayFromParserRules(context.whenPhrase().repeatedCharacterValue3(), ctx => CobolWordsBuilder.CreateRepeatedCharacterValue(ctx));
}
}
else
{
if (context.attribute() != null)
{
if (context.NUMERIC() != null)
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.NUMERIC_ATTRIBUTE,
context.NUMERIC());
else if (context.nonnumeric() != null)
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.NONNUMERIC_ATTRIBUTE,
context.nonnumeric().UserDefinedWord());
else
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.ATTRIBUTE,
context.attribute().UserDefinedWord());
}
else if (context.element() != null)
System.Diagnostics.Debug.Assert(context.genericSuppressionPhrase() != null);
var suppression = context.genericSuppressionPhrase();

if (suppression.EVERY() != null)
{
if (context.NUMERIC() != null)
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.NUMERIC_ELEMENT,
context.NUMERIC());
else if (context.nonnumeric() != null)
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.NONNUMERIC_ELEMENT,
context.nonnumeric().UserDefinedWord());
if (suppression.NUMERIC() != null)
{
suppressDirective.XmlItemTypeToSuppress = CreateSyntaxProperty(XmlItemType.NUMERIC, suppression.NUMERIC());
}
else if (suppression.nonnumeric() != null)
{
suppressDirective.XmlItemTypeToSuppress = CreateSyntaxProperty(XmlItemType.NONNUMERIC, suppression.nonnumeric().UserDefinedWord());
}
else
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSuppressDirective.XmlSyntaxType.ELEMENT,
context.element().UserDefinedWord());
{
System.Diagnostics.Debug.Assert(suppression.attributeOrContentOrElement() != null);
}

if (suppression.attributeOrContentOrElement() != null)
{
var attributeOrContentOrElement = suppression.attributeOrContentOrElement();
if (attributeOrContentOrElement.attribute() != null)
{
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSyntaxType.ATTRIBUTE, attributeOrContentOrElement.attribute().UserDefinedWord());
}
else if (attributeOrContentOrElement.CONTENT() != null)
{
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSyntaxType.CONTENT, attributeOrContentOrElement.CONTENT());
}
else
{
System.Diagnostics.Debug.Assert(attributeOrContentOrElement.element() != null);
suppressDirective.XmlSyntaxTypeToSuppress = CreateSyntaxProperty(XmlSyntaxType.ELEMENT, attributeOrContentOrElement.element().UserDefinedWord());
}
}
}

System.Diagnostics.Debug.Assert(suppression.whenPhrase() != null);
suppressDirective.ItemValuesToSuppress = BuildObjectArrayFromParserRules(suppression.whenPhrase().repeatedCharacterValue3(), ctx => CobolWordsBuilder.CreateRepeatedCharacterValue(ctx));
}
suppressDirective.ItemValuesToSuppress = BuildObjectArrayFromParserRules(context.repeatedCharacterValue3(), ctx => CobolWordsBuilder.CreateRepeatedCharacterValue(ctx));

return suppressDirective;
}

Expand Down

0 comments on commit 3a4be4c

Please sign in to comment.