org.sweble.wikitext.lazy.utils.XmlReference.rats Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swc-parser-lazy Show documentation
Show all versions of swc-parser-lazy Show documentation
A parser for MediaWiki's Wikitext.
/**
* Copyright 2011 The Open Source Research Group,
* University of Erlangen-Nürnberg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*!
*
* Xml Character Reference
* -----------------------
*
* Grammar:
* - '' Digit+ ';'
* - '' HexDigit+ ';'
*
* AST node:
* Name : XmlCharRef
* Extends : LeafNode
* Constructor : codePoint
* NodeType : org.sweble.wikitext.lazy.AstNodeTypes.NT_XML_CHAR_REF
*
* Properties:
* codePoint : int
*
* Xml Entity Reference
* --------------------
*
* Grammar:
* - '&' XmlName ';'
*
* AST node:
* Name : XmlEntityRef
* Extends : LeafNode
* Constructor : name
* NodeType : org.sweble.wikitext.lazy.AstNodeTypes.NT_XML_ENTITY_REF
*
* Properties:
* name : String
*
*/
module org.sweble.wikitext.lazy.utils.XmlReference;
import org.sweble.wikitext.lazy.utils.Numbers;
import org.sweble.wikitext.lazy.utils.Warnings;
import org.sweble.wikitext.lazy.utils.XmlName;
// -- Header -------------------------------------------------------------------
header
{
import org.sweble.wikitext.lazy.utils.XmlCharRef;
import org.sweble.wikitext.lazy.utils.XmlEntityRef;
}
// -- References ---------------------------------------------------------------
AstNode XmlReference =
'&' yyValue:XmlReferenceChoice
/ '&'
{
yyValue = new Text("&");
}
;
private inline AstNode XmlReferenceChoice =
"#" yyValue:XmlCharRefChoice
/ yyValue:XmlEntityRefChoice
/ &{ isWarningsEnabled() }
yyValue:XmlReferenceAutoCorrect
;
private inline AstNode XmlReferenceAutoCorrect =
&{ isWarningLevelEnabled(WS_INFO) }
{
yyValue = new Text("&");
fileLooksLikeWarning(
yyValue,
makeSpan(yyStart - 1, yyStart),
WS_INFO,
"XML Reference",
"the entity name or character code is missing");
}
;
private inline AstNode XmlCharRefChoice =
'x' ch:HexDigitPlus ';'
{
// TODO: check if valid char ref
// TODO: add warnings for incomplete syntax
// TODO: make sure only valid characters are "generated" (encval)
yyValue = new XmlCharRef(Integer.parseInt(ch, 16));
if (isGatherRtData())
addRtData(yyValue, joinRt("", ch, ';'));
}
/ ch:DigitPlus ';'
{
// TODO: check if valid char ref
// TODO: add warnings for incomplete syntax
// TODO: make sure only valid characters are "generated" (encval)
yyValue = new XmlCharRef(Integer.parseInt(ch));
if (isGatherRtData())
addRtData(yyValue, joinRt("", ch, ';'));
}
/// &{ isWarningsEnabled() } XmlCharRefAutoCorrect
;
private inline AstNode XmlEntityRefChoice =
name:XmlName ';'
{
// TODO: check if valid entity name
// TODO: add warnings for incomplete syntax
// TODO: make sure only valid characters are "generated" (encval)
yyValue = new XmlEntityRef(name);
if (isGatherRtData())
addRtData(yyValue, joinRt('&', name, ';'));
}
/// &{ isWarningsEnabled() } XmlEntityRefAutoCorrect
;
// -- End of file --------------------------------------------------------------