mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
Merge pull request #1011 from cdietrich/bf492456
[492456] Added support for ignorecase-keywords to the new serializer
This commit is contained in:
commit
324180d6c8
2 changed files with 37 additions and 0 deletions
|
@ -51,6 +51,7 @@ import org.eclipse.xtext.xtext.generator.util.SyntheticTerminalDetector
|
|||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
|
||||
import org.eclipse.xtext.serializer.tokens.IKeywordSerializer
|
||||
|
||||
class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
|
||||
|
||||
|
@ -458,6 +459,7 @@ class XtextAntlrGeneratorFragment2 extends AbstractAntlrGeneratorFragment2 {
|
|||
if (getOptions().isIgnoreCase()) {
|
||||
rtBindings
|
||||
.addTypeToType(ITokenSerializer.IKeywordSerializer.typeRef, IgnoreCaseKeywordSerializer.typeRef)
|
||||
.addTypeToType(IKeywordSerializer.typeRef, org.eclipse.xtext.serializer.tokens.IgnoreCaseKeywordSerializer.typeRef)
|
||||
.addTypeToType(AbstractIDValueConverter.typeRef, IgnoreCaseIDValueConverter.typeRef)
|
||||
}
|
||||
rtBindings.contributeTo(language.runtimeGenModule)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.serializer.tokens;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.Keyword;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
|
||||
|
||||
/**
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
public class IgnoreCaseKeywordSerializer implements IKeywordSerializer {
|
||||
|
||||
@Override
|
||||
public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) {
|
||||
if (value instanceof String) {
|
||||
return keyword.getValue().equalsIgnoreCase((String) value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, Acceptor errorAcceptor) {
|
||||
if (node != null && node.getGrammarElement() == keyword)
|
||||
return node.getText();
|
||||
return keyword.getValue();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue