Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* commons - Various Java Utils
* Copyright (C) 2009 Adrian Cristian Ionescu - https://github.com/acionescu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.segoia.util.parser;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.segoia.util.parser.utils.JavaCollectionMapParser;
import net.segoia.util.parser.workers.AbstractParseWorkerFactory;
import net.segoia.util.parser.workers.ParseWorker;
import net.segoia.util.strings.StringUtil;
/**
* Defines a simple entity to be searched in a string
*
* @author adi
*
*/
public class Symbol extends ParseContextConfig {
/**
* Sequence of characters that define this symbol
*/
private String sequence;
/**
* the name for this symbol
*/
private String name;
// /**
// * Defines a special kind of action associeated with this symbol
// */
// private String action;
private int priority = -1;
/**
* The type of this symbol
*/
private SymbolType type;
/**
* The pair symbols list for a group delimiter symbol
*/
private List pairSymbols = new ArrayList();
private List workers = new ArrayList();
private static Parser symbolDefinitionParser;
private static JavaCollectionMapParser collectionsParser = new JavaCollectionMapParser();
static {
symbolDefinitionParser = new Parser();
symbolDefinitionParser.setUseEscapeCharacterOn(true);
symbolDefinitionParser.addSymbol(",", SymbolType.SEPARATE, 0);
Symbol apos = new Symbol("\'", SymbolType.GROUP_START, 0);
apos.addNestedSymbol(new Symbol("\'", SymbolType.GROUP_END));
apos.addFlag(SymbolFlag.SIMPLE);
Symbol startGroup = new Symbol("[", SymbolType.GROUP_START, 1);
startGroup.addNestedSymbol(new Symbol("]", SymbolType.GROUP_END, 1));
startGroup.addNestedSymbol(new Symbol(",", SymbolType.SEPARATE, 0));
startGroup.addNestedSymbol(startGroup);
startGroup.addNestedSymbol(apos);
symbolDefinitionParser.addSymbol(startGroup);
}
public Symbol() {
}
public Symbol(String sequence, SymbolType type) {
this.sequence = sequence;
this.type = type;
}
public Symbol(String sequence, SymbolType type, int priority) {
this.sequence = sequence;
this.type = type;
this.priority = priority;
}
/**
* @return the sequence
*/
public String getSequence() {
return sequence;
}
// /**
// * @return the action
// */
// public String getAction() {
// return action;
// }
/**
* @return the type
*/
public SymbolType getType() {
return type;
}
/**
* @param sequence
* the sequence to set
*/
public void setSequence(String sequence) {
this.sequence = unescapeSequence(sequence);
}
// /**
// * @param action
// * the action to set
// */
// public void setAction(String action) {
// this.action = action;
// }
/**
* @param type
* the type to set
*/
public void setType(SymbolType type) {
this.type = type;
}
/**
* @return the pairSymbols
*/
public List getPairSymbols() {
return pairSymbols;
}
/**
* @param pairSymbols
* the pairSymbols to set
*/
public void setPairSymbols(List pairSymbols) {
this.pairSymbols = pairSymbols;
}
public void addPairSymbol(Symbol s) {
pairSymbols.add(s);
}
public void addWorker(ParseWorker worker) {
workers.add(worker);
}
public Object applyWorkers(Collection