Package org.lifstools.jgoslin.parser
Class Parser<T>
java.lang.Object
org.lifstools.jgoslin.parser.Parser<T>
- Type Parameters:
T- the type of a successful parse result.
- Direct Known Subclasses:
FattyAcidParser,GoslinParser,HmdbParser,LipidMapsParser,ShorthandParser,SumFormulaParser,SwissLipidsParser
Abstract base class for parsers producing a parse result of type T. Uses a
re-implementation of Cocke-Younger-Kasami (CYK) algorithm for context free
grammars.
- Author:
- Dominik Kopczynski, Nils Hoffmann
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected final classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected static final charprotected static final longprotected static final Stringprotected static final charprotected Stringprotected static final longprotected longprotected charprotected final ArrayList<org.lifstools.jgoslin.parser.Bitfield>protected static final charprotected static final charprotected static final charprotected static final intprotected static final longprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected longadd_terminal(String text) collect_backwards(long child_rule_index, long parent_rule_index, HashSet<Long> visited, ArrayList<Long> path, ArrayList<ArrayList<Long>> collection) collect_backwards(Long child_rule_index, Long parent_rule_index) collect_one_backwards(Long rule_index) protected longcompute_rule_key(long rule_index_1, long rule_index_2) protected Stringextract_text_based_rules(String grammar, char _quote) protected voidprotected longprotected booleanis_terminal(String product_token, char _quote) abstract BaseParserEventHandler<T>parse(String textToParse, BaseParserEventHandler<T> parserEventHandler) Parse the given text, constructing the output object of type T using the provided parser event handler.parse(String textToParse, BaseParserEventHandler<T> parserEventHandler, boolean throwError) Parse the given text, constructing the output object of type T using the provided parser event handler.Allows the user to specify, if exceptions should be thrown on errors.protected Optional<Parser<T>.ParsingErrors>parse_regular(String text_to_parse, BaseParserEventHandler<T> parserEventHandler) protected voidraise_events(TreeNode node, BaseParserEventHandler parserEventHandler) protected final voidreadGrammar(String grammar) top_nodes(long rule_index)
-
Field Details
-
SHIFT
protected static final int SHIFT- See Also:
-
MASK
protected static final long MASK- See Also:
-
RULE_ASSIGNMENT
protected static final char RULE_ASSIGNMENT- See Also:
-
RULE_SEPARATOR
protected static final char RULE_SEPARATOR- See Also:
-
RULE_TERMINAL
protected static final char RULE_TERMINAL- See Also:
-
EOF_SIGN
protected static final char EOF_SIGN- See Also:
-
EOF_RULE
protected static final long EOF_RULE- See Also:
-
START_RULE
protected static final long START_RULE- See Also:
-
EOF_RULE_NAME
- See Also:
-
nextFreeRuleIndex
protected long nextFreeRuleIndex -
TtoNT
-
originalTtoNT
-
ruleToNT
-
NTtoNT
-
NTtoRule
-
substitution
-
rightPair
-
avgPair
protected int avgPair -
quote
protected char quote -
grammarName
-
usedEof
protected boolean usedEof -
DEFAULT_QUOTE
protected static final char DEFAULT_QUOTE- See Also:
-
-
Constructor Details
-
Parser
-
Parser
-
-
Method Details
-
newEventHandler
-
get_next_free_rule_index
protected long get_next_free_rule_index() -
readGrammar
-
extract_text_based_rules
-
compute_rule_key
protected long compute_rule_key(long rule_index_1, long rule_index_2) -
is_terminal
-
de_escape
-
add_terminal
-
top_nodes
-
collect_one_backwards
-
collect_backwards
-
collect_backwards
-
raise_events
-
fill_tree
-
parse
Parse the given text, constructing the output object of type T using the provided parser event handler.- Parameters:
textToParse- the text to parse.parserEventHandler- the parser event handler to process events created by the parser.- Returns:
- the parsed object of type T if successful, otherwise an exception will be thrown.
- Throws:
LipidParsingException
-
parse
public T parse(String textToParse, BaseParserEventHandler<T> parserEventHandler, boolean throwError) Parse the given text, constructing the output object of type T using the provided parser event handler.Allows the user to specify, if exceptions should be thrown on errors.- Parameters:
textToParse- the text to parse.parserEventHandler- the parser event handler to process events created by the parser.throwError- if true, throws exception if parsing was not successful.- Returns:
- the parsed object of type T if successful, otherwise
null, if throwError isfalse.
-
parse_regular
protected Optional<Parser<T>.ParsingErrors> parse_regular(String text_to_parse, BaseParserEventHandler<T> parserEventHandler)
-