001/*
002 * Copyright 2021 Dominik Kopczynski, Nils Hoffmann.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.lifstools.jgoslin.parser;
017
018import org.lifstools.jgoslin.domain.KnownFunctionalGroups;
019import org.lifstools.jgoslin.domain.LipidAdduct;
020import org.lifstools.jgoslin.domain.StringFunctions;
021
022/**
023 * Parser implementation for the updated 2020 Liebisch lipid shorthand
024 * nomenclature.
025 *
026 * @author Dominik Kopczynski
027 * @author Nils Hoffmann
028 */
029public class SwissLipidsParser extends Parser<LipidAdduct> {
030
031    private static final String DEFAULT_GRAMMAR = "SwissLipids.g4";
032
033    private final KnownFunctionalGroups knownFunctionalGroups;
034
035    /**
036     * Create a new instance of a {@link SwissLipidsParser}.
037     *
038     * @param knownFunctionalGroups the known functional groups
039     * @param grammarContent the grammar text content
040     * @param quote the quotation character used in the grammar
041     */
042    public SwissLipidsParser(KnownFunctionalGroups knownFunctionalGroups, String grammarContent, char quote) {
043        super(grammarContent, quote);
044        this.knownFunctionalGroups = knownFunctionalGroups;
045    }
046
047    /**
048     * Create a new instance of a {@link SwissLipidsParser} with default grammar
049     * {@link SwissLipidsParser#DEFAULT_GRAMMAR} and default quote
050     * {@link StringFunctions#DEFAULT_QUOTE}.
051     *
052     * @param knownFunctionalGroups the known functional groups
053     */
054    public SwissLipidsParser(KnownFunctionalGroups knownFunctionalGroups) {
055        this(knownFunctionalGroups, StringFunctions.getResourceAsString(DEFAULT_GRAMMAR), StringFunctions.DEFAULT_QUOTE);
056    }
057
058    /**
059     * Create a new instance of a {@link SwissLipidsParser} with default grammar
060     * {@link SwissLipidsParser#DEFAULT_GRAMMAR} and default quote
061     * {@link StringFunctions#DEFAULT_QUOTE} and default
062     * {@link KnownFunctionalGroups}.
063     */
064    public SwissLipidsParser() {
065        this(new KnownFunctionalGroups(), StringFunctions.getResourceAsString(DEFAULT_GRAMMAR), StringFunctions.DEFAULT_QUOTE);
066    }
067
068    @Override
069    public SwissLipidsParserEventHandler newEventHandler() {
070        return new SwissLipidsParserEventHandler(knownFunctionalGroups);
071    }
072
073}