Package eu.bandm.tools.d2d2.parser2
Class Parser
java.lang.Object
eu.bandm.tools.d2d2.parser2.Parser
Hand-written Ramus-based lexer and parser for d2d definition files.
COPIED AND ADOPTED from eu.bandm.tools.lljava.parser.LLJavaGrammar3 and LLJavaParser3.
Realizing the grammar as defined in the XAntlr-source ../parser/d2d.g and the
Reducer from ../base/Reducer
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Distributes documentation text to definitions in the current module, descending into local definitions when required.static class
static enum
Enumeration of token types. -
Field Summary
Modifier and TypeFieldDescriptionAccepts and decodes char set constants given as contents between single quotes.Accepts and decodes char set constants given as decimal number.Accepts and decodes char set constants given as hex number.(package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Object> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Void> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Unit> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Unit> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Boolean> Accepts and decodes top level grammar expressions.(package private) final Object
Key for storing/retrieving the lexical context of a new definition.(package private) final Object
Key for storing/retrieving the currently growing "XRegExp" object.(package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> Accepts and decodes identifiers, which includes keywords and lexer identifiers.(package private) static final Parser.TokenType[]
(package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, ImportItem> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Object> Is requird because local nodes can get a mangled xml tag not before the field "name" of the containing node is set, which is not the case when "declModifiers" is parsed and reduced.(package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Unit> (package private) final Object
Key for storing/retrieving the currently growing "module" object.static final MessageReceiver<SimpleMessage<XMLDocumentIdentifier>>
(package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Unit> NamespaceDecls are stored in the "Module" model element.Accepts and decodes references, which are identifiers separated by dots.Accepts and decodes string constants, which is the contents between double quotes.Accepts and decodes string constants not containing newline and tab characters.(package private) static Function3<Location<XMLDocumentIdentifier>,
Parser.TokenType, String, TLex.Token<XMLDocumentIdentifier, Parser.TokenType>> (package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> (package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> Accepts simple hash-mark keywords and "#d2d..#/d2d" escape sequences.(package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> (package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> (package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> (package private) final Expression<XMLDocumentIdentifier,
Parser.TokenType, Unit> Parse, accept and set the corresponding fields of a model elementDefinition
according to '[with ..] xmlrep (trimmed|untrimmed)? (data)? (el|att)? (= "nspref:tag" "value"?)? ' -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToContext
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, SourceItem currentScope, Definition newdef, String kind) AddDefinition
(Enum or Tags or Chars Parser) to currentscope (either to Module or (as a local definition) to a definition).static void
addToModule
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Module host, SourceItem item, String kind) Store a definition to the given module.atom_000
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes lowest level grammar expressions.atom_002
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Parse greedy and insert prefix sequence as in "@ @ > > (a, b)"atom_004
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set cut expression "e1 A e2"atom_006
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set join expression "e1 U e2"atom_008
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set minus expression "e1 - e2"protected static boolean
protected static <A> Expression<XMLDocumentIdentifier,
Parser.TokenType, A> constant
(Parser.TokenType type, A value) Delivers an Expression, which accepts the given token type, and reduces to the given value (the location is preserved).declModifiers
(Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) decor_002
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes tight sequence "e1 ~ e2"decor_004
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes permutation "e1 & e2
"decor_006
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes non-tight sequecne "e1 , e2"decor_008
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes alternative "e1 | e2"decorated
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes decorated expression "e1? / + / * / +~ / *~"definitionBody
(Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) DOCME +++ Does not return anything but enters it into the current growing lexical context.protected static void
error
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, @Opt Location<XMLDocumentIdentifier> loc, String s) grammarExpr
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> p_grammarExpr) Accepts and decodes top level grammar expressions.localnodes
(Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) static void
Adopted from lljava/parser/LLJavaParser3.module
(Expression<XMLDocumentIdentifier, Parser.TokenType, Module> p_module) Accepts and decodes a "module" declaration.namespaceMapping
(Module module) protected static TLex<XMLDocumentIdentifier,
Parser.TokenType> newLexer
(XMLDocumentIdentifier docId, Reader reader) protected static @Opt Parser.TokenType
protected void
postProcess
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Module module) range
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes next-to-lowest level grammar expressions.splitdoctext
(String text, Location<XMLDocumentIdentifier> startloc) substituted
(Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes substituted expression "e1 ^(e2/i2) ^(e3/i3).."protected static Parser<XMLDocumentIdentifier,
Parser.TokenType> static <DD,
TT, R> R testParse
(MessageReceiver<SimpleMessage<DD>> msg, TLex<DD, TT> lexer, TT[] ignore, Expression<DD, TT, R> nonterm, String data, boolean projectResult) <R> R
testParseD2d
(Expression<XMLDocumentIdentifier, Parser.TokenType, R> nonterm, String data, boolean projectResult) (package private) static TLex.Item<XMLDocumentIdentifier,
Parser.TokenType> token_stringconst
(char delim, Parser.TokenType tt) protected static Expression<XMLDocumentIdentifier,
Parser.TokenType, Parser.TokenType> tokenType
(Parser.TokenType... types) DOCMEprotected static Parser<XMLDocumentIdentifier,
Parser.TokenType> protected static Expression<XMLDocumentIdentifier,
Parser.TokenType, Content<XMLDocumentIdentifier, Parser.TokenType>> unparsedLiteral
(Parser.TokenType... types) Auxiliary function, gives necessary constraints to type inference.protected static Expression<XMLDocumentIdentifier,
Parser.TokenType, String> unparsedLiteralText
(Parser.TokenType... types) protected static void
warning
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, @Opt Location<XMLDocumentIdentifier> loc, String s)
-
Field Details
-
tfact
-
token_comment
-
hexLit
-
token_numeric_0
-
token_numeric_1_9
-
token_hashkeyword_X
Accepts simple hash-mark keywords and "#d2d..#/d2d" escape sequences. -
token_ident
-
d2dLexer
-
identifier
Accepts and decodes identifiers, which includes keywords and lexer identifiers. -
reference
Accepts and decodes references, which are identifiers separated by dots. -
stringconst
Accepts and decodes string constants, which is the contents between double quotes. -
stringconstChecked
Accepts and decodes string constants not containing newline and tab characters. Is used for character parser defintions, xml names and name mangling infixes. -
charset
Accepts and decodes char set constants given as contents between single quotes. -
charset_dez
Accepts and decodes char set constants given as decimal number. -
charset_hex
Accepts and decodes char set constants given as hex number. -
grammarExpr
Accepts and decodes top level grammar expressions. This is the version where the recursive call "grammarExpr" is resolved. This version must be used by all higher level expressions. -
moduleContextKey
Key for storing/retrieving the currently growing "module" object. -
growingLexContextKey
Key for storing/retrieving the lexical context of a new definition. -
growingXregexpKey
Key for storing/retrieving the currently growing "XRegExp" object. -
namespaceDecls
-
xmlspec
Parse, accept and set the corresponding fields of a model elementDefinition
according to '[with ..] xmlrep (trimmed|untrimmed)? (data)? (el|att)? (= "nspref:tag" "value"?)? ' -
editspec
-
inputspec
-
postprocessor
-
manglingRules
Is requird because local nodes can get a mangled xml tag not before the field "name" of the containing node is set, which is not the case when "declModifiers" is parsed and reduced. -
definitionBody
-
namespacedecl
NamespaceDecls are stored in the "Module" model element. (Are not set in a "defaultgroup" d2d.g rule!) -
importcmd
-
enumDecl
-
documentation
-
modline
-
globaltrimming
-
manglingRule
-
defaultDef
-
defaultGroup
-
module
-
top
-
ignores
-
msg
-
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
token_stringconst
static TLex.Item<XMLDocumentIdentifier,Parser.TokenType> token_stringconst(char delim, Parser.TokenType tt) -
newLexer
protected static TLex<XMLDocumentIdentifier,Parser.TokenType> newLexer(XMLDocumentIdentifier docId, Reader reader) -
TRACE
-
unparsedLiteral
protected static Expression<XMLDocumentIdentifier,Parser.TokenType, unparsedLiteralContent<XMLDocumentIdentifier, Parser.TokenType>> (Parser.TokenType... types) Auxiliary function, gives necessary constraints to type inference.- Parameters:
types
- realizes an ALTERNATIVE of accepted token types- Returns:
- an Expression which will deliver one
Content
as its reduction result.
-
tokenType
protected static Expression<XMLDocumentIdentifier,Parser.TokenType, tokenTypeParser.TokenType> (Parser.TokenType... types) DOCME -
constant
protected static <A> Expression<XMLDocumentIdentifier,Parser.TokenType, constantA> (Parser.TokenType type, A value) Delivers an Expression, which accepts the given token type, and reduces to the given value (the location is preserved). -
unparsedLiteralText
protected static Expression<XMLDocumentIdentifier,Parser.TokenType, unparsedLiteralTextString> (Parser.TokenType... types) - Parameters:
types
- realizes an ALTERNATIVE of accepted token types- Returns:
- an Expression which will deliver the text (of type String) of one Token as its parsing result.
-
error
protected static void error(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, @Opt @Opt Location<XMLDocumentIdentifier> loc, String s) -
warning
protected static void warning(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, @Opt @Opt Location<XMLDocumentIdentifier> loc, String s) -
optTokenType
-
terminal
-
atom_000
public final Expression<XMLDocumentIdentifier,Parser.TokenType, atom_000Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes lowest level grammar expressions. It must be method(=function) and not constant definition, because it is the end point of a cyclic reference.- Parameters:
grammarExpr
- the highest level grammar expression. Is inserted here (wrapped into "("..")") for recursion.
-
range
public final Expression<XMLDocumentIdentifier,Parser.TokenType, rangeExpression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes next-to-lowest level grammar expressions. It must be method(=function) because it must pass down the parameter for recursion from its definition point to its lowest point of usage. -
atom_002
public final Expression<XMLDocumentIdentifier,Parser.TokenType, atom_002Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Parse greedy and insert prefix sequence as in "@ @ > > (a, b)" -
atom_004
public final Expression<XMLDocumentIdentifier,Parser.TokenType, atom_004Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set cut expression "e1 A e2" -
atom_006
public final Expression<XMLDocumentIdentifier,Parser.TokenType, atom_006Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set join expression "e1 U e2" -
atom_008
public final Expression<XMLDocumentIdentifier,Parser.TokenType, atom_008Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes char set minus expression "e1 - e2" -
substituted
public final Expression<XMLDocumentIdentifier,Parser.TokenType, substitutedExpression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes substituted expression "e1 ^(e2/i2) ^(e3/i3).." -
decorated
public final Expression<XMLDocumentIdentifier,Parser.TokenType, decoratedExpression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes decorated expression "e1? / + / * / +~ / *~" -
decor_002
public final Expression<XMLDocumentIdentifier,Parser.TokenType, decor_002Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes tight sequence "e1 ~ e2" -
decor_004
public final Expression<XMLDocumentIdentifier,Parser.TokenType, decor_004Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes permutation "e1 & e2
" -
decor_006
public final Expression<XMLDocumentIdentifier,Parser.TokenType, decor_006Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes non-tight sequecne "e1 , e2" -
decor_008
public final Expression<XMLDocumentIdentifier,Parser.TokenType, decor_008Expression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> grammarExpr) Accepts and decodes alternative "e1 | e2" -
grammarExpr
public final Expression<XMLDocumentIdentifier,Parser.TokenType, grammarExprExpression> (Expression<XMLDocumentIdentifier, Parser.TokenType, Expression> p_grammarExpr) Accepts and decodes top level grammar expressions.- Parameters:
p_grammarExpr
- its own result, for defining the grammar rule recursion many levels lower. Is handled by the call toExpression.fix(java.util.function.Function<eu.bandm.tools.ramus.runtime2.Expression<D, T, A>, eu.bandm.tools.ramus.runtime2.Expression<D, T, A>>)
, as performed ingrammarExpr
.
-
addToModule
public static void addToModule(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Module host, SourceItem item, String kind) Store a definition to the given module. ImportItems, (Sub-)Modules and Definitions (=Enums, Chars and Tags Parser) can be added. They are stored to different maps, but must have unique names over all.
(Made public and with explicit message channel for later re-construction of synthetic definitions, e.g. from Parser sub-particles.) -
addToContext
protected void addToContext(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, SourceItem currentScope, Definition newdef, String kind) AddDefinition
(Enum or Tags or Chars Parser) to currentscope (either to Module or (as a local definition) to a definition).- Parameters:
kind
- for error messaging only.
-
namespaceMapping
-
localnodes
public final Expression<XMLDocumentIdentifier,Parser.TokenType, localnodesUnit> (Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) -
declModifiers
public final Expression<XMLDocumentIdentifier,Parser.TokenType, declModifiersUnit> (Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) -
definitionBody
public final Expression<XMLDocumentIdentifier,Parser.TokenType, definitionBodyUnit> (Expression<XMLDocumentIdentifier, Parser.TokenType, Unit> p_definitionBody) DOCME +++ Does not return anything but enters it into the current growing lexical context. -
checkEnumItemValid
-
splitdoctext
-
module
public final Expression<XMLDocumentIdentifier,Parser.TokenType, moduleModule> (Expression<XMLDocumentIdentifier, Parser.TokenType, Module> p_module) Accepts and decodes a "module" declaration. All definitions contained therein must be stored to the maps in this module. Therefore the module is stored in a context register, -
postProcess
protected void postProcess(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msg, Module module) -
testParse
public static <DD,TT, R testParseR> (MessageReceiver<SimpleMessage<DD>> msg, TLex<DD, TT> lexer, TT[] ignore, Expression<DD, TT, R> nonterm, String data, boolean projectResult) -
testParseD2d
public <R> R testParseD2d(Expression<XMLDocumentIdentifier, Parser.TokenType, R> nonterm, String data, boolean projectResult) -
main
Adopted from lljava/parser/LLJavaParser3.- Parameters:
args
- [0] filename- Throws:
FileNotFoundException
-