mirror of
https://github.com/Minres/RDL-Editor.git
synced 2025-06-12 21:32:22 +02:00
Iniital checkin
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,22 @@
|
||||
package com.minres.rdl.converter;
|
||||
|
||||
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class IDValueConverter extends AbstractLexerBasedConverter<String> {
|
||||
@Override
|
||||
protected String toEscapedString(final String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toValue(final String string, final INode node) {
|
||||
boolean _startsWith = string.startsWith("\\");
|
||||
if (_startsWith) {
|
||||
return string.substring(1);
|
||||
} else {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.minres.rdl.converter;
|
||||
|
||||
import com.minres.rdl.IntegerWithRadix;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.conversion.ValueConverterException;
|
||||
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.util.Strings;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
class NUMValueConverter extends AbstractLexerBasedConverter<IntegerWithRadix> {
|
||||
@Override
|
||||
protected String toEscapedString(final IntegerWithRadix value) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertValidValue(final IntegerWithRadix value) {
|
||||
super.assertValidValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntegerWithRadix toValue(final String string, final INode node) throws ValueConverterException {
|
||||
boolean _isEmpty = Strings.isEmpty(string);
|
||||
if (_isEmpty) {
|
||||
throw new ValueConverterException(
|
||||
"Couldn\'t convert empty string to an integer value.", node, null);
|
||||
}
|
||||
try {
|
||||
return new IntegerWithRadix(string);
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof NumberFormatException) {
|
||||
final NumberFormatException e = (NumberFormatException)_t;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Couldn\'t convert \'");
|
||||
_builder.append(string);
|
||||
_builder.append("\' to an integer value.");
|
||||
throw new ValueConverterException(_builder.toString(), node, e);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.minres.rdl.converter;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.minres.rdl.IntegerWithRadix;
|
||||
import com.minres.rdl.converter.IDValueConverter;
|
||||
import com.minres.rdl.converter.NUMValueConverter;
|
||||
import com.minres.rdl.converter.STRValueConverter;
|
||||
import org.eclipse.xtext.common.services.DefaultTerminalConverters;
|
||||
import org.eclipse.xtext.conversion.IValueConverter;
|
||||
import org.eclipse.xtext.conversion.ValueConverter;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class RdlTerminalConverters extends DefaultTerminalConverters {
|
||||
@Inject
|
||||
private NUMValueConverter numValueConverter;
|
||||
|
||||
@Inject
|
||||
private STRValueConverter stringConverter;
|
||||
|
||||
@Inject
|
||||
private IDValueConverter idConverter;
|
||||
|
||||
@ValueConverter(rule = "NUM")
|
||||
public IValueConverter<IntegerWithRadix> getNumValueConverter() {
|
||||
return this.numValueConverter;
|
||||
}
|
||||
|
||||
@ValueConverter(rule = "STR")
|
||||
public IValueConverter<String> getStrValueConverter() {
|
||||
return this.stringConverter;
|
||||
}
|
||||
|
||||
@ValueConverter(rule = "ID")
|
||||
public IValueConverter<String> getIdValueConverter() {
|
||||
return this.idConverter;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.minres.rdl.converter;
|
||||
|
||||
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class STRValueConverter extends AbstractLexerBasedConverter<String> {
|
||||
@Override
|
||||
protected String toEscapedString(final String value) {
|
||||
return (("\"" + value) + "\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toValue(final String string, final INode node) {
|
||||
int _length = string.length();
|
||||
int _minus = (_length - 1);
|
||||
return string.substring(1, _minus);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user