Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Checking if a ID matches some string
Checking if a ID matches some string [message #1701262] Fri, 10 July 2015 10:54 Go to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
I have the standard ID terminal from common terminals. I now have a long list of Colors:

MediumTurquoise
MediumVioletRed
MidnightBlue
MintCream
MistyRose
Moccasin
NavajoWhite
Navy
OldLace
Olive
OliveDrab
Orange
OrangeRed
Orchid
PaleGoldenRod
PaleGreen
PaleTurquoise
PaleVioletRed
PapayaWhip
PeachPuff
Peru
Pink


etc. Is there any way of checking if the ID exists in this list, instead of creating a separate rule for colors that I have to match against?

Some other way than this:
 Actor:
'actor' name=ID  ('#' Color)?


Color:
	('AliceBlue'|'AntiqueWhite'|'Aqua'|'Aquamarine'|'Azure'|'Beige'|'Bisque'|'Black'|'BlanchedAlmond'
	|'Blue'|'BlueViolet'|'Brown'|'BurlyWood'|'CadetBlue'|'Chartreuse'|'Chocolate'|'Coral'
	|'CornflowerBlue'|'Cornsilk'|'Crimson'|'Cyan'|'DarkBlue'|'DarkCyan'|'DarkGoldenRod'|'DarkGray'
	|'DarkGreen'|'DarkGrey'|'DarkKhaki'|'DarkMagenta'|'DarkOliveGreen'|'DarkOrchid'|'DarkRed'
	|'DarkSalmo'|'DarkSeaGreen'|'DarkSlateBlue'|'DarkSlateGray'|'DarkSlateGrey'|'DarkTurquoise'
	|'DarkViolet'|'Darkorange'|'DeepPink'|'DeepSkyBlue'|'DimGray'|'DimGrey'|'DodgerBlue'
	|'FireBrick'|'FloralWhite'|'ForestGreen'|'Fuchsia'|'Gainsboro'|'GhostWhite'|'Gold'
	|'GoldenRod'|'Gray'|'Green'|'GreenYellow'|'Grey'|'HoneyDew'|'HotPink'|'IndianRed'
	|'Indigo'|'Ivory'|'Khaki'|'Lavender'|'LavenderBlush'|'LawnGreen'|'LemonChiffon'
	|'LightBlue'|'LightCoral'|'LightCyan'|'LightGoldenRodYellow'|'LightGray'|'LightGreen'
	|'LightGrey'|'LightPink'|'LightSalmon'|'LightSeaGreen'|'LightSkyBlue'|'LightSlateGray'
	|'LightSlateGrey'|'LightSteelBlue'|'LightYellow'|'Lime'|'LimeGreen'|'Linen'|'Magenta'
	|'Maroon'|'MediumAquaMarine'|'MediumBlue'|'MediumOrchid'|'MediumPurple'|'MediumSeaGreen'
	|'MediumSlateBlue'|'MediumSpringGreen'|'MediumTurquoise'|'MediumVioletRed'
	|'MidnightBlue'|'MintCream'|'MistyRose'|'Moccasin'|'NavajoWhite'|'Navy'|'OldLace'
	|'Olive'|'OliveDrab'|'OrangeRed'|'Orchid'|'PaleGoldenRod'|'PaleGreen'
	|'PaleTurquoise'|'PaleVioletRed'|'PapayaWhip'|'PeachPuff'|'Peru'|'Pink'|'Plum'
	|'PowderBlue'|'Purple'|'Red'|'RosyBrown'|'RoyalBlue'|'SaddleBrown'
	|'Salmon'|'SandyBrown'|'SeaGreen'|'Sienna'|'Silver'|'SkyBlue'|'SlateBlue'
	|'SlateGray'|'SlateGrey'|'Snow'|'SpringGreen'|'SteelBlue'|'Tan'|'Teal'|'Thistle'
	|'Tomato'|'Turquoise'|'Violet'|'Wheat'|'White'|'WhiteSmoke'|'Yellow'|'YellowGreen')
;

[Updated on: Fri, 10 July 2015 10:57]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701263 is a reply to message #1701262] Fri, 10 July 2015 10:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
what about using a datatype rule

Color: ID

and then a valueconverter that does the check?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701266 is a reply to message #1701263] Fri, 10 July 2015 11:23 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
So the value converter should check for the Color rule, and if the ID in it it is not in my list, just throw an error?
Re: Checking if a ID matches some string [message #1701268 is a reply to message #1701266] Fri, 10 July 2015 11:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701276 is a reply to message #1701268] Fri, 10 July 2015 12:24 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Never created a value converter before, so please bear with me. I did something like this: http://pastebin.com/7VF2r56T but I am probably doing something very wrong. Am I on the right track?

Thanks,

[Updated on: Mon, 13 July 2015 06:07]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701280 is a reply to message #1701276] Fri, 10 July 2015 12:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the link is not working

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701281 is a reply to message #1701280] Fri, 10 July 2015 12:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
ah the comma is too much. looks fine. simply bind it

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701370 is a reply to message #1701281] Mon, 13 July 2015 06:07 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Is this the correct binding?

Inside PlantumlRuntimeModule:

@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
        return PlantumlValueConverter.class;
    }


Because nothing really happens when I run the DSL, except it now thinks that Color can be any ID. The check never seems to be made.

[Updated on: Mon, 13 July 2015 06:08]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701375 is a reply to message #1701370] Mon, 13 July 2015 07:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Sure you did the grammar right? and your implementation of the valueconverter looks strange since it disallows colors. and you should not compare using ==

             @Override
                        public String toValue(String string, INode node) throws ValueConverterException{
                        		if (!org.eclipse.xtext.util.Arrays.contains(colorArray, string)) {
                        			 throw new ValueConverterException("Not a Color", node, null);
                        		}
                                return string;
                        }


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701378 is a reply to message #1701375] Mon, 13 July 2015 07:25 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
The grammar is now basically ( the important parts ):

Actor: 'actor' ID (Color)?
Color: '#' ID;
terminal ID = ('a'..'z'|'A'..'Z'|'0'..'9' | 'å' | 'ä' | 'ö')+;


That change to the Valueconverter that you suggested unfortunately made no difference.

[Updated on: Mon, 13 July 2015 07:52]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701385 is a reply to message #1701378] Mon, 13 July 2015 07:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

in my case i get an error.

buz my rule is named COLOR and the converter uses COLOR in the anno. and method name


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701386 is a reply to message #1701385] Mon, 13 July 2015 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
make use you converter is called using debugging

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701391 is a reply to message #1701386] Mon, 13 July 2015 08:14 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Sorry, but I am not exactly sure what you mean.

Here is full grammar: http://pastebin.com/zHeJ1FNf
With the converter: http://pastebin.com/R30JxKvK
And the runtimemodule: http://pastebin.com/FEXstzmX
Re: Checking if a ID matches some string [message #1701392 is a reply to message #1701391] Mon, 13 July 2015 08:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
The following works for me

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=COLOR '!';
	
	
COLOR: ID;
public class PlantumlValueConverter extends DefaultTerminalConverters {
        boolean Exists = false;
        String[] colorArray = {
                        "AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black"
                        ,"BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse"
                        ,"Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan"
                        ,"DarkGoldenRod","DarkGray","DarkGreen","DarkGrey","DarkKhaki","DarkMagenta","DarkOliveGreen"
                        ,"DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray"
                        ,"DarkSlateGrey","DarkTurquoise","DarkViolet","Darkorange","DeepPink","DeepSkyBlue"
                        ,"DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia"
                        ,"Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Green","GreenYellow","Grey"
                        ,"HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush"
                        ,"LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow"
                        ,"LightGray","LightGreen","LightGrey","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue"
                        ,"LightSlateGray","LightSlateGrey","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen"
                        ,"Magenta","Maroon","MediumAquaMarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen"
                        ,"MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue"
                        ,"MintCream","MistyRose","Moccasin","NavajoWhite","Navy","OldLace","Olive","OliveDrab"
                        ,"Orange","OrangeRed","Orchid","PaleGoldenRod","PaleGreen","PaleTurquoise","PaleVioletRed"
                        ,"PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Psurple","Red","RosyBrown"
                        ,"RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell"
                        ,"Sienna","Silver","SkyBlue","SlateBlue","SlateGray","SlateGrey","Snow","SpringGreen"
                        ,"SteelBlue","Tan","Teal","Thistle","Tomato","Turquoise","Violet","Wheat","White"
                        ,"WhiteSmoke","Yellow","YellowGreen"
        };     
        @ValueConverter(rule = "COLOR")
        public IValueConverter<String> COLOR(){
                return new IValueConverter<String>(){
 
                        @Override
                        public String toValue(String string, INode node) throws ValueConverterException{
                        		if (!org.eclipse.xtext.util.Arrays.contains(colorArray, string)) {
                        			 throw new ValueConverterException("Not a Color", node, null);
                        		}
                                return string;
                        }
 
                        @Override
                        public String toString(String value)
                                        throws ValueConverterException {
                                // TODO Auto-generated method stub
                                return value;
                        }              
                };     
        }
}
	@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
        return PlantumlValueConverter.class;
    }


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701395 is a reply to message #1701392] Mon, 13 July 2015 08:22 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Still nothing happens for me Sad

For instance, I can write

Hello ASDASD
without any complaints.

[Updated on: Mon, 13 July 2015 08:23]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701403 is a reply to message #1701395] Mon, 13 July 2015 08:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
which xtext Version? i use 283 ant it works nice.
i have no idea what you are doing. did you debug if the code is called?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701408 is a reply to message #1701403] Mon, 13 July 2015 09:31 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
I have the same version. When trying to just print something in the toValue function it does not look like it enters it at all.
Re: Checking if a ID matches some string [message #1701418 is a reply to message #1701408] Mon, 13 July 2015 11:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
And how do you test this

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701420 is a reply to message #1701418] Mon, 13 July 2015 11:11 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Just by inserting some sysout in the method call to see if it was printed. Also tried to insert a breakpoint, but it seems it was never reached.
Re: Checking if a ID matches some string [message #1701424 is a reply to message #1701420] Mon, 13 July 2015 11:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Strange. Please try with a fresh ws and hello world dsl

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701433 is a reply to message #1701424] Mon, 13 July 2015 12:40 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Same thing there. Just tried extending the Hello World DSL with my runtime module and my valueconverter, but on the Greeting-rule instead of the Color rule, and I get absolutley nothing again.

Just tried:

Hello test ! 


With the same binding as before and
@Override
                    public String toValue(String string, INode node) throws ValueConverterException{
                    		System.out.println("Test print !! ");
                    		if (!org.eclipse.xtext.util.Arrays.contains(colorArray, string)) {
                    			 throw new ValueConverterException("Not a Color", node, null);
                    		}
                            return string;
                    }


as the valueconverter. Still get nothing. Sad Perhaps something very fundamental that I am doing wrong? Do I have to assign the ID in Color to a name? Because I already have a name assigned in my original rule

Actor : 'actor' name = ID Color?

[Updated on: Mon, 13 July 2015 12:44]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701434 is a reply to message #1701433] Mon, 13 July 2015 12:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
please copy & paste may code 1:1
maybe it is Problem of Color vs COLOR


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701435 is a reply to message #1701434] Mon, 13 July 2015 12:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and

Actor : 'actor' name = ID Color?

makes no sense to me

in you example

Hello test NoColor !


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701453 is a reply to message #1701435] Mon, 13 July 2015 14:02 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
I try it simple, with this grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID Color '!';

Color: ID;


This valueconverter:
package org.xtext.example.mydsl;

import org.eclipse.xtext.common.services.DefaultTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Strings;

public class PlantumlValueConverter extends DefaultTerminalConverters {
    boolean Exists = false;
    String[] colorArray = {
                    "AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black"
                    ,"BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse"
                    ,"Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan"
                    ,"DarkGoldenRod","DarkGray","DarkGreen","DarkGrey","DarkKhaki","DarkMagenta","DarkOliveGreen"
                    ,"DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray"
                    ,"DarkSlateGrey","DarkTurquoise","DarkViolet","Darkorange","DeepPink","DeepSkyBlue"
                    ,"DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia"
                    ,"Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Green","GreenYellow","Grey"
                    ,"HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush"
                    ,"LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow"
                    ,"LightGray","LightGreen","LightGrey","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue"
                    ,"LightSlateGray","LightSlateGrey","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen"
                    ,"Magenta","Maroon","MediumAquaMarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen"
                    ,"MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue"
                    ,"MintCream","MistyRose","Moccasin","NavajoWhite","Navy","OldLace","Olive","OliveDrab"
                    ,"Orange","OrangeRed","Orchid","PaleGoldenRod","PaleGreen","PaleTurquoise","PaleVioletRed"
                    ,"PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Psurple","Red","RosyBrown"
                    ,"RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell"
                    ,"Sienna","Silver","SkyBlue","SlateBlue","SlateGray","SlateGrey","Snow","SpringGreen"
                    ,"SteelBlue","Tan","Teal","Thistle","Tomato","Turquoise","Violet","Wheat","White"
                    ,"WhiteSmoke","Yellow","YellowGreen"
    };     
    
    @ValueConverter(rule = "Color")
    public IValueConverter<String> Color(){
            return new IValueConverter<String>(){

                    @Override
                    public String toValue(String string, INode node) throws ValueConverterException{
                    		System.out.println("Test print !! ");
                    		if (!org.eclipse.xtext.util.Arrays.contains(colorArray, string)) {
                    			 throw new ValueConverterException("Not a Color", node, null);
                    		}
                            return string;
                    }

                    @Override
                    public String toString(String value)
                                    throws ValueConverterException {
                            // TODO Auto-generated method stub
                            return value;
                    }              
            };     
    }
}



And this runtimemodule:
/*
 * generated by Xtext
 */
package org.xtext.example.mydsl;

import org.eclipse.xtext.conversion.IValueConverterService;


/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
        return PlantumlValueConverter.class;
    }
}


And no errors are thrown, and no sysout is written, when I for example test the DSL with

Hello bob asdasdasd !

[Updated on: Mon, 13 July 2015 14:03]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701466 is a reply to message #1701453] Mon, 13 July 2015 14:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Rename Color to COLOR and file a bug

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701467 is a reply to message #1701466] Mon, 13 July 2015 14:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Nope it works camel case as well.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701471 is a reply to message #1701392] Mon, 13 July 2015 14:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and please try this test

import javax.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.junit.Test
import org.junit.runner.RunWith
import org.xtext.example.mydsl2.MyDslInjectorProvider
import org.xtext.example.mydsl2.myDsl.Model
import org.eclipse.xtext.junit4.validation.ValidationTestHelper

@InjectWith(MyDslInjectorProvider)
@RunWith(XtextRunner)
class MyDslParserTest {
	
	@Inject extension ParseHelper<Model> 
	@Inject extension ValidationTestHelper
	
	@Test
	def void testIt() {
		'''Hello NoColor!'''.parse.assertNoErrors
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701556 is a reply to message #1701471] Tue, 14 July 2015 07:03 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
package org.xtext.example.mydsl.tests

import javax.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.junit.Test
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.validation.ValidationTestHelper
import org.xtext.example.mydsl.MyDslInjectorProvider
import org.xtext.example.mydsl.myDsl.Model

@InjectWith(MyDslInjectorProvider)
@RunWith(XtextRunner)
class MyDslParserTest {
	@Inject extension ParseHelper<Model> 
	@Inject extension ValidationTestHelper

	@Test
	def void testIt() {
		'''Hello NoColor !'''.parse.assertNoErrors
	}
}


Tests without any errors with the grammar

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' Color '!';

Color: 
	ID
;


All i get in the console is this, but it guess most of it is unrelated:
!SESSION 2015-07-14 08:59:56.082 -----------------------------------------------
eclipse.buildId=4.4.2.M20150204-1700
java.version=1.8.0_45
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -version 3 -port 64020 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames org.xtext.example.mydsl.tests.MyDslParserTest -application org.eclipse.pde.junit.runtime.uitestapplication -product org.eclipse.platform.ide -testpluginname org.xtext.example.mydsl.tests
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -consoleLog -version 3 -port 64020 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames org.xtext.example.mydsl.tests.MyDslParserTest -application org.eclipse.pde.junit.runtime.uitestapplication -product org.eclipse.platform.ide -data C:\Users\eaonban\Downloads\eclipse-clean\workspace-clean/../junit-workspace -dev file:C:/Users/eaonban/Downloads/eclipse-clean/workspace-clean/.metadata/.plugins/org.eclipse.pde.core/pde-junit/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog -testpluginname org.xtext.example.mydsl.tests

!ENTRY org.eclipse.egit.ui 2 0 2015-07-14 09:00:27.445
!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level
Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory.
The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in
this system level configuration. The Git installation location can be configured on the
Team > Git > Configuration preference page's 'System Settings' tab.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

!ENTRY org.eclipse.egit.ui 2 0 2015-07-14 09:00:27.449
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'H:\'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

!ENTRY org.eclipse.core.net 4 0 2015-07-14 09:00:30.300
!MESSAGE WinHttp.DetectAutoProxyConfigUrl for wpad failed with error 'The Proxy Auto-configuration URL was not found.
' #12180.

[Updated on: Tue, 14 July 2015 07:04]

Report message to a moderator

Re: Checking if a ID matches some string [message #1701566 is a reply to message #1701556] Tue, 14 July 2015 08:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

then i have no idea what is wrong with your Environment.
can you share your complete example Project as exported zip


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701574 is a reply to message #1701566] Tue, 14 July 2015 08:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

why do you not assign things?

Greeting:
'Hello' Color '!';

Greeting:
'Hello' Color=Color '!';


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Checking if a ID matches some string [message #1701577 is a reply to message #1701574] Tue, 14 July 2015 09:00 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Just bad habit I guess. As I said, I just started out with Xtext. Gonna keep that in mind from now on, because now it works! Thanks a lot!
Re: Checking if a ID matches some string [message #1701591 is a reply to message #1701577] Tue, 14 July 2015 10:46 Go to previous messageGo to next message
Anton Bergman is currently offline Anton BergmanFriend
Messages: 34
Registered: June 2015
Member
Is there a way to get the valueconverter to produce just a warning instead of an error when running the DSL?
Re: Checking if a ID matches some string [message #1701600 is a reply to message #1701591] Tue, 14 July 2015 11:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Nope

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Class not found when using JvmModelInferrer
Next Topic:Hidden file in the project
Goto Forum:
  


Current Time: Tue Mar 19 06:07:15 GMT 2024

Powered by FUDForum. Page generated in 0.08169 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top