org.sweble.wikitext.lazy.parser.TableCaption.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.
*/
/*!
*
* TableCaption
* ------------
*
* Grammar:
* - S* '|+' TableAttributeInline* S* '|' TableCaptionContent* Garbage* Eol
*
* AST node:
* Name : TableCaption
* Extends : InnerNode.InnerNode2
* Constructor : "xmlAttributes, body"
* NodeType : org.sweble.wikitext.lazy.AstNodeTypes.NT_TABLE_CAPTION
*
* Children:
* xmlAttributes : NodeList
* body : NodeList
*
*/
module org.sweble.wikitext.lazy.parser.TableCaption;
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 Caption --[ State Aware Memoization ]-------------------------------
noinline transient AstNode TableCaption =
^{
StateAwareResult r = (StateAwareResult) pTableCaptionMemoized(yyBase);
final LazyParserContext context = getContext();
Result yyResult = r.getResult(context);
if (yyResult == null)
yyResult = r.setResult(context, pTableCaptionTransient(yyBase));
if (returnTrue(r))
return yyResult;
}
;
noinline memoized AstNode TableCaptionMemoized =
^{
Result yyResult = new StateAwareResult("TableCaption", getContext(), pTableCaptionTransient(yyBase));
if (returnTrue(yyResult))
return yyResult;
}
;
// -- Table Caption ------------------------------------------------------------
noinline transient AstNode TableCaptionTransient =
rt0:pExtSpaceStar "|+" attributes:Attributes body:InlineContentStar garbage:Garbage &FollowUpSanityCheck
{
yyValue = new TableCaption(attributes._1, body);
// TODO: Issue warning if garbage is more than just whitespace
if (isGatherRtData())
addRtData(yyValue,
joinRt(rt0, "|+"),
(Object[]) attributes._2,
joinRt(garbage));
}
/ rt0:pExtSpaceStar "|+" attributes:Attributes body:BlockContentStar &FollowUpSanityCheck
{
yyValue = new TableCaption(attributes._1, body);
if (isGatherRtData())
addRtData(yyValue,
joinRt(rt0, "|+"),
(Object[]) attributes._2,
null);
}
;
private inline String Garbage =
&"||" garbage:GarbageStar end:( pEol / pEof )
{
yyValue = garbage + end;
}
;
private transient String GarbageStar =
( !( slEol pExtSpaceStar [|!] ) _ )*
;
private inline void FollowUpSanityCheck =
ExpectedFollowUp / ShouldNotBeHere
;
private inline void ExpectedFollowUp =
pExtSpaceStar ( "!" / "|+" / "|-" / "|}" / "|" / Eof )
;
// -- Table Caption 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 Caption Content ----------------------------------------------------
private inline stateful NodeList InlineContentStar =
{
enter(ParserScopes.TABLE_INLINE_CELL);
}
InlineContentPlus
;
private inline stateful NodeList BlockContentStar =
{
enter(ParserScopes.TABLE_CELL);
}
BlockContent
;
// -- End of file --------------------------------------------------------------