BrightSide Workbench Full Report + Source Code
ParserMacro.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.parser;
20 
21 import java.util.TreeSet;
22 import org.turro.util.CompareUtil;
23 
28 public class ParserMacro implements Comparable<ParserMacro> {
29 
30  private final String macroName;
31  private final int order;
32  private final TreeSet<ParserParameter> parameters = new TreeSet<>();
33 
34  public ParserMacro(String macroName, int order) {
35  this.macroName = macroName;
36  this.order = order;
37  }
38 
39  public String getMacroName() {
40  return macroName;
41  }
42 
43  public int getOrder() {
44  return order;
45  }
46 
47  public TreeSet<ParserParameter> getParameters() {
48  return parameters;
49  }
50 
51  public ParserMacro addParameter(String name, boolean optional) {
52  return addParameter(name, optional, null, false);
53  }
54 
55  public ParserMacro addParameter(String name, boolean optional, String defaultValue) {
56  return addParameter(name, optional, defaultValue, false);
57  }
58 
59  public ParserMacro addParameter(String name, boolean optional, String defaultValue, boolean commaSeparated) {
60  parameters.add(new ParserParameter(name, optional, defaultValue, parameters.size() + 1, commaSeparated));
61  return this;
62  }
63 
64  public ParserMacro addPossibleValue(String value) {
65  if(!parameters.isEmpty()) {
66  parameters.last().addPossibleValue(value);
67  }
68  return this;
69  }
70 
71  public void copyParametersFrom(String macroName, ParserMacroSet macros) {
72  for(ParserMacro macro : macros) {
73  if(macro.getMacroName().equals(macroName)) {
74  macros.copyParametersTo(macro, this);
75  break;
76  }
77  }
78  }
79 
80  @Override
81  public int compareTo(ParserMacro o) {
82  int result = CompareUtil.compare(order, o.order);
83  if(result == 0) CompareUtil.compare(macroName, o.macroName);
84  return result;
85  }
86 
87 }
void copyParametersTo(ParserMacro origin, ParserMacro destiny)
ParserMacro addPossibleValue(String value)
void copyParametersFrom(String macroName, ParserMacroSet macros)
TreeSet< ParserParameter > getParameters()
ParserMacro(String macroName, int order)
int compareTo(ParserMacro o)
ParserMacro addParameter(String name, boolean optional, String defaultValue, boolean commaSeparated)
ParserMacro addParameter(String name, boolean optional)
ParserMacro addParameter(String name, boolean optional, String defaultValue)