org.sweble.wikitext.lazy.parser.Whitespace.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.
*/
/*!
*
* Whitespace
* ----------
*
* AST node:
* Name : Whitespace
* Extends : ContentNode
* NodeType : org.sweble.wikitext.lazy.AstNodeTypes.NT_WHITESPACE
* Constructor : "content, hasNewline"
*
* Properties:
* hasNewline : boolean
*
*/
module org.sweble.wikitext.lazy.parser.Whitespace;
import org.sweble.wikitext.lazy.parser.ParserEntity;
modify org.sweble.wikitext.lazy.utils.Whitespace;
// -- Redefinition of EOL productions ------------------------------------------
inline String pSlEol = "\r\n" // tateess
/ "\r"
/ "\n"
/ "\u2028"
/ "\u2029"
/ "\u000B"
/ "\u000C"
/ "\u0085" ;
String pEol := &{ acceptEol() } pSlEol ;
inline void slEol = "\r\n" // tateess
/ '\r'
/ '\n'
/ '\u2028'
/ '\u2029'
/ '\u000B'
/ '\u000C'
/ '\u0085' ;
void Eol := &{ acceptEol() } slEol ;
transient void slEolOrEof = slEol
/ Eof ;
// -- Preserved Transparent Elements -------------------------------------------
AstNode pTpStar = ptTpStar ;
AstNode pTpPlus = ptTpPlus ;
private transient NodeList ptTpStar =
tp:pTransparent*
{
yyValue = new NodeList(tp);
}
;
private transient NodeList ptTpPlus =
tp:pTransparent+
{
yyValue = new NodeList(tp);
}
;
private inline AstNode pTransparent =
ParserEntityXmlCommentOrIgnore
;
// -- Preserved Extended Spaces ------------------------------------------------
AstNode pExtSpaceStar = ptExtSpaceStar ;
AstNode pExtSpacePlus = ptExtSpacePlus ;
private transient NodeList ptExtSpaceStar =
s:pExtSpaceAtom*
{
yyValue = new NodeList(s);
}
;
private transient NodeList ptExtSpacePlus =
s:pExtSpaceAtom+
{
yyValue = new NodeList(s);
}
;
private inline AstNode pExtSpaceAtom =
spaces:pSpacePlus
{
yyValue = new Text(spaces);
}
/ pTransparent
;
// -- Preserved Extended Whitespace --------------------------------------------
noinline transient AstNode pExtWsStar =
^{
StateAwareResult r = (StateAwareResult) ppExtWsStarMemoized(yyBase);
final LazyParserContext context = getContext();
Result yyResult = r.getResult(context);
if (yyResult == null)
yyResult = r.setResult(context, ppExtWsStarTransient(yyBase));
if (returnTrue(r))
return yyResult;
}
;
noinline memoized Whitespace pExtWsStarMemoized =
^{
Result yyResult = new StateAwareResult("pExtWsPlus", getContext(), ppExtWsStarTransient(yyBase));
if (returnTrue(yyResult))
return yyResult;
}
;
noinline transient Whitespace pExtWsStarTransient =
s:pExtSpaceStar ws:pExtWsAtom*
{
yyValue = new Whitespace(new NodeList(s, ws), !ws.isEmpty());
}
;
noinline transient AstNode pExtWsPlus =
^{
StateAwareResult r = (StateAwareResult) ppExtWsPlusMemoized(yyBase);
final LazyParserContext context = getContext();
Result yyResult = r.getResult(context);
if (yyResult == null)
yyResult = r.setResult(context, ppExtWsPlusTransient(yyBase));
if (returnTrue(r))
return yyResult;
}
;
noinline memoized Whitespace pExtWsPlusMemoized =
^{
Result yyResult = new StateAwareResult("pExtWsPlus", getContext(), ppExtWsPlusTransient(yyBase));
if (returnTrue(yyResult))
return yyResult;
}
;
noinline transient Whitespace pExtWsPlusTransient =
s:pExtSpacePlus ws:pExtWsAtom*
{
yyValue = new Whitespace(new NodeList(s, ws), !ws.isEmpty());
}
/ ws:pExtWsAtom+
{
yyValue = new Whitespace(new NodeList(ws), true);
}
;
private inline AstNode pExtWsAtom =
ws:pWsPlus
{
yyValue = new Text(ws);
}
/ pTransparent
;
// -- End of file --------------------------------------------------------------