|
XmlAnnotation.grm
|
// FILE. . . . . /home/hak/hlt/src/hlt/language/syntax/xml/XmlAnnotation.grm // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . 4j4zn71 // STARTED ON. . Fri Mar 16 18:13:06 2007 // Last modified on Tue Jun 19 18:00:21 2012 by hak
| [Description generated from file XmlAnnotationSpecification.grm] |
//////////////////////////////////////////////////////////////////////// %package hlt.language.syntax.xml; %import java.util.Iterator; %import hlt.language.tools.Misc; %import hlt.language.util.ArrayList; %import hlt.language.util.IntArrayList; %import hlt.language.syntax.XmlWrapper;
| Including file XmlAnnotationNodeClasses.grm defining some fields and methods for some non-terminal nodes used in the grammar's semantic actions. |
%include "XmlAnnotationNodeClasses.grm"
| Including file XmlAnnotationSpecification.grm containg the documentation describing the logical design for Jacc's XML serialization annotation notation. |
%include "XmlAnnotationSpecification.grm" %access public %start XmlAnnotation %token DOT STAR SLASH %token POSITION SYMBOL TEXT VALUE NSPREFIX LOCALNAME ATTRIBUTES CHILDREN LISTSEP KEYVALSEP
| [See also XmlAnnotationParserCode.grm] |
%include "XmlAnnotationParserCode.grm" %% XmlAnnotation : AnnotationPairs ; AnnotationPairs : /* empty */ | AnnotationPairs AnnotationPair ; AnnotationPair : NSPrefixPair | LocalNamePair | AttributesPair | ChildrenPair ; NSPrefixPair : NSPrefixKey NSPrefixValue ; NSPrefixKey : NSPREFIX KeyValSep_opt ; NSPrefixValue : SYMBOL { nsPrefix = $1.svalue(); } ; LocalNamePair : LocalNameKey LocalNameValue ; LocalNameKey : LOCALNAME KeyValSep_opt ; LocalNameValue : SYMBOL { localName = $1.svalue(); } ; AttributesPair : AttributesKey AttributesValue ; AttributesKey : ATTRIBUTES KeyValSep_opt ; AttributesValue : '{' Attributes '}' ; Attributes : Attribute | Attributes ListSep_opt Attribute ; Attribute : SYMBOL KeyValSep_opt AttributeValue { XmlAttributeInfo info = null; String key = $1.svalue(); if ($3.hasLiteralValueContent) info = XmlAttributeInfo.literalXmlAttributeInfo(key,$3.value); else if ($3.hasTerminalValueContent) info = new XmlAttributeInfo(key); else if ($3.textInfo != null) info = new XmlAttributeInfo(key, new XmlSpecialForm($3.textInfo)); else info = new XmlAttributeInfo(key, $3.cstChildPosition, $3.xmlPath, $3.attributeName); attributes.add(info); } ;
An $AttributeValue$ may be one of:
|
AttributeValue
:
| An attribute value may the special form '$VALUE' or '$TEXT' |
SpecialForm
{
$$.hasTerminalValueContent = $1.hasTerminalValueContent;
$$.textInfo = $1.textInfo;
}
|
| An attribute value may be a literal (unquoted, single-quoted, or double-quoted) string. |
SYMBOL
{
$$.value = $1.svalue();
$$.hasLiteralValueContent = true;
}
|
| An attribute value may be a deep reference into the XML tree of the CST child at $POSITION$, optionally followed by an $XmlPath$. Then comes an optional $AttributeName$ consisting of a slash '/' followed by an unquoted, single-quoted, or double-quoted string denoting an attribute name in the referenced XML subtree. |
POSITION XmlPath_opt AttributeName_opt
{
$$.cstChildPosition = (int)$1.nvalue();
$$.xmlPath = $2.xmlPath;
$$.attributeName = $3.attributeName;
}
;
A $SpecialForm$ is introduced with a dollar sign
('$') followed by specially interpreted contents; at
present the available special forms are:
|
SpecialForm : VALUE { $$.hasTerminalValueContent = true; } | TEXT '(' TextArguments ')' { $$.textInfo = $3.textInfo; } ; TextArguments : TextArgument { ($$.textInfo = new ArrayList()).add($1.info); } | TextArguments ListSep_opt TextArgument { ($$.textInfo = $1.textInfo).add($3.info); } ; TextArgument : SYMBOL { ($$.info = new XmlTextInfoArg()).setText($1.svalue()); } | TextRef { $$.info = $1.info; } ;
| A TextRef denotes a reference to some text located in the XML tree that has been built for a child CST. |
TextRef : ChildXmlTree AttributeName_opt { $$.info = new XmlTextInfoArg($1.cstChildPosition, $1.xmlPath, $2.attributeName); } ; AttributeName : SLASH SYMBOL { $$.attributeName = $2.svalue(); } ;
| An XmlChildSpec specifies the structure of an XML tree for a child CST. When $WrapperPath_opt$ is not empty, it is a sequence of $SYMBOL$'s each followed by either a dot or an asterisk. This specifies a path of XML tags: one for each XML layer to wrap around the resulting XML contents. A dot triggers a single element wrap, while an asterisk triggers the wrap to distribute on the next nesting level's elements, if any. |
XmlChildSpec : WrapperPath_opt ChildXmlTree { $$.wrapperPath = $1.wrapperPath; $$.cstChildPosition = $2.cstChildPosition; $$.xmlPath = $2.xmlPath; $$.hasTerminalValueContent = $2.hasTerminalValueContent; $$.textInfo = $2.textInfo; } ;
| A child XML tree denotes the contents on the XML tree being built for a child CST node. |
ChildXmlTree
:
| A child XML tree may be a special form starting with a '$'. |
SpecialForm
{
$$.hasTerminalValueContent = $1.hasTerminalValueContent;
$$.textInfo = $1.textInfo;
}
|
|
$POSITION$ is an int (say, n)
and refers to the nth child CST node.
When $XmlPath_opt$ is empty, an ChildXmlTree refers to the XML element of the nth child CST node. When $XmlPath_opt$ is not empty, it is a bracketed, dot-separated sequence of $POSITION$'s (see $XmlPath$). This sequence denotes a tree-address path in the tree of XML elements, starting from the XML element associated with the CST node at position n. |
POSITION XmlPath_opt
{
$$.cstChildPosition = (int)$1.nvalue();
$$.xmlPath = $2.xmlPath;
}
;
WrapperPath_opt
: /* empty */
| WrapperPath
{
$$.wrapperPath = $1.wrapperPath;
}
;
| A $WrapperPath$ is a sequence of pairs each made of $SYMBOL$'s followed by either a dot or an asterisk. This specifies a path of XML tags: one for each XML layer to wrap around the resulting XML contents. A dot triggers a single element wrap, while an asterisk triggers the wrap to distribute on the next nesting level's elements. |
WrapperPath : SYMBOL DotOrStar { $$.add($1.svalue(),$2.isStarred); } | WrapperPath SYMBOL DotOrStar { $$.addTo($1.wrapperPath,$2.svalue(),$3.isStarred); } ; DotOrStar : DOT | STAR { $$.isStarred = true; } ;
| A $XmlPath_opt$ is a possibly empty bracketed $XmlPath$. |
XmlPath_opt : /* empty */ | '[' XmlPath ']' { $$.xmlPath = $2.xmlPath; } ;
| An XmlPath is either a single positive integer, or a dot-separated sequence thereof. |
XmlPath : POSITION { $$.add((int)$1.nvalue()); } | XmlPath DOT POSITION { $$.addTo($1.xmlPath,(int)$3.nvalue()); } ; ChildrenPair : ChildrenKey ChildrenValue ; ChildrenKey : CHILDREN KeyValSep_opt ;
| A ChildrenValue is a parenthesized $XmlTreeRefs$. |
ChildrenValue : '(' XmlTreeRefs ')' ;
| An XmlTreeRefs is either a single $XmlTreeRef$, or a sequence thereof. |
XmlTreeRefs : XmlTreeRef { children.add($1.cstChildPosition); xmlPaths.add($1.xmlPath); wrapperPaths.add($1.wrapperPath); attributeNames.add($1.attributeName); terminalValueFlag = $1.hasTerminalValueContent; textInfos.add($1.textInfo); } | XmlTreeRefs ListSep_opt XmlTreeRef { children.add($3.cstChildPosition); xmlPaths.add($3.xmlPath); wrapperPaths.add($3.wrapperPath); attributeNames.add($3.attributeName); terminalValueFlag = $3.hasTerminalValueContent; textInfos.add($3.textInfo); } ; XmlTreeRef : XmlChildSpec AttributeName_opt { $$.cstChildPosition = $1.cstChildPosition; $$.xmlPath = $1.xmlPath; $$.wrapperPath = $1.wrapperPath; $$.attributeName = $2.attributeName; $$.hasTerminalValueContent = $1.hasTerminalValueContent; $$.textInfo = $1.textInfo; } ; AttributeName_opt : /* empty */ | AttributeName { $$.attributeName = $1.attributeName; } ; KeyValSep_opt : /* empty */ | KEYVALSEP ; ListSep_opt : /* empty */ | LISTSEP ; %%
This file was generated on Tue Apr 30 07:44:49 CEST 2019 from file XmlAnnotation.grm
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci