All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.jproperties.parser.JavaPropertiesGrammar Maven / Gradle / Ivy

There is a newer version: 2.6
Show newest version
/*
 * SonarQube Java Properties Plugin
 * Copyright (C) 2015-2016 David RACODON
 * [email protected]
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.jproperties.parser;

import com.sonar.sslr.api.typed.GrammarBuilder;
import org.sonar.jproperties.tree.impl.InternalSyntaxToken;
import org.sonar.plugins.jproperties.api.tree.*;

public class JavaPropertiesGrammar {

  private final GrammarBuilder b;
  private final TreeFactory f;

  public JavaPropertiesGrammar(GrammarBuilder b, TreeFactory f) {
    this.b = b;
    this.f = f;
  }

  public PropertiesTree PROPERTIES() {
    return b.nonterminal(JavaPropertiesLexicalGrammar.PROPERTIES).is(
      f.properties(
        b.optional(b.token(JavaPropertiesLexicalGrammar.BOM)),
        b.zeroOrMore(PROPERTY()),
        b.token(JavaPropertiesLexicalGrammar.EOF)));
  }

  public PropertyTree PROPERTY() {
    return b.nonterminal(JavaPropertiesLexicalGrammar.PROPERTY).is(
      f.property(
        KEY(),
        SEPARATOR(),
        b.optional(VALUE())));
  }

  public KeyTree KEY() {
    return b.nonterminal(JavaPropertiesLexicalGrammar.KEY).is(
      f.key(b.token(JavaPropertiesLexicalGrammar.KEY_LITERAL)));
  }

  public SeparatorTree SEPARATOR() {
    return b.nonterminal(JavaPropertiesLexicalGrammar.SEPARATOR).is(
      f.separator(
        b.firstOf(
          b.token(JavaPropertiesLexicalGrammar.EQUALS_SEPARATOR),
          b.token(JavaPropertiesLexicalGrammar.COLON_SEPARATOR))));
  }

  public ValueTree VALUE() {
    return b.nonterminal(JavaPropertiesLexicalGrammar.VALUE).is(
      f.value(b.token(JavaPropertiesLexicalGrammar.VALUE_LITERAL)));
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy