org.sweble.wikitext.lazy.parser.TableHeader.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.
*/
/*!
*
* TableHeader
* -----------
*
* Grammar:
*
* AST node:
* Name : TableHeader
* Extends : InnerNode.InnerNode2
* Constructor : "xmlAttributes, body"
* NodeType : org.sweble.wikitext.lazy.AstNodeTypes.NT_TABLE_HEADER
*
* Children:
* xmlAttributes : NodeList
* body : NodeList
*
*/
module org.sweble.wikitext.lazy.parser.TableHeader;
import org.sweble.wikitext.lazy.utils.Assert;
import org.sweble.wikitext.lazy.parser.Content;
import org.sweble.wikitext.lazy.parser.TableAttributeInline;
import org.sweble.wikitext.lazy.parser.Whitespace;
// -- Table Header --[ State Aware Memoization ]--------------------------------
noinline transient AstNode TableHeader =
^{
StateAwareResult r = (StateAwareResult) pTableHeaderMemoized(yyBase);
final LazyParserContext context = getContext();
Result yyResult = r.getResult(context);
if (yyResult == null)
yyResult = r.setResult(context, pTableHeaderTransient(yyBase));
if (returnTrue(r))
return yyResult;
}
;
noinline memoized AstNode TableHeaderMemoized =
^{
Result yyResult = new StateAwareResult("TableHeader", getContext(), pTableHeaderTransient(yyBase));
if (returnTrue(yyResult))
return yyResult;
}
;
// -- Table Header -------------------------------------------------------------
noinline transient AstNode TableHeaderTransient =
&( pExtSpaceStar '!' ) inline:TableInlineHeaderPlus last:TableBlockHeader?
{
yyValue = new NodeList(inline, last);
}
/ &( pExtSpaceStar '!' ) header:TableBlockHeader
{
yyValue = header;
}
;
inline void InlineContentStopperTableHeader =
&{ inScope(ParserScopes.TABLE_INLINE_HEADER) } ( "!!" / "||" )
;
// -- Table Inline Header ------------------------------------------------------
private transient NodeList TableInlineHeaderPlus =
headers:( TableInlineHeader &( "||" / "!!" ) )+
{
yyValue = new NodeList(headers);
}
;
private inline TableHeader TableInlineHeader =
rt0:pExtSpaceStar prefix:( "!!" / "||" / "!" ) attributes:Attributes body:InlineContentStar
{
yyValue = new TableHeader(attributes._1, body);
if (isGatherRtData())
addRtData(yyValue,
joinRt(rt0, prefix),
(Object[]) attributes._2,
null);
}
;
// -- Table Block Header -------------------------------------------------------
private inline TableHeader TableBlockHeader =
rt0:pExtSpaceStar prefix:( "!!" / "||" / "!" ) attributes:Attributes body:BlockContentStar &FollowUpSanityCheck
{
yyValue = new TableHeader(attributes._1, body);
if (isGatherRtData())
addRtData(yyValue,
joinRt(rt0, prefix),
(Object[]) attributes._2,
null);
}
;
private inline void FollowUpSanityCheck =
ExpectedFollowUp / ShouldNotBeHere
;
private inline void ExpectedFollowUp =
pExtSpaceStar ( "!" / "|+" / "|-" / "|}" / "|" / Eof )
;
// -- Table Header Attributes --------------------------------------------------
private Tuple2 Attributes =
&AttrPossible attrs:TableAttributeInlineStar ws:pExtSpaceStar '|' !'|'
{
yyValue = Tuple.from(attrs, (Object) joinRt(ws, '|'));
}
/ {
yyValue = Tuple.from(new NodeList(), null);
}
;
private transient void AttrPossible =
( ![<|] !"[[" !"!!" !slEol _ )* ( ( '|' !'|' ) / ( '!' !'!' ) )
;
// -- Table Header Inline Content ----------------------------------------------
private inline stateful NodeList InlineContentStar =
{
enter(ParserScopes.TABLE_INLINE_HEADER);
}
InlineContentPlus
;
private inline stateful NodeList BlockContentStar =
{
enter(ParserScopes.TABLE_CELL);
}
BlockContent
;
// -- End of file --------------------------------------------------------------