All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sweble.wikitext.lazy.utils.XmlReference.rats Maven / Gradle / Ivy

There is a newer version: 3.1.9
Show newest version
/**
 * 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+    ';'
 *     - '&#x' 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("&#x", 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 --------------------------------------------------------------




© 2015 - 2024 Weber Informatics LLC | Privacy Policy