Discussion:
[Cucumber:3470] [cuke4nuke] Adding support for non-english step definitions
(too old to reply)
Aslak Johannessen
2010-02-10 07:54:12 UTC
Permalink
Hi

I have been using cucumber for some rails projects over the last year or so.
Now i'm starting up a C# .NET project and want to take the tool with me. But
as far as I can see from the current source it does not support for
ex. Norwegian step definitions.

What i want to do is:

[Code in Norwegian]
In the feature.

# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil

Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"



In the steps.cs file
[Gitt(@"^at jeg trykker ""(.+)"" pluss ""(.+)""$")]
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}


The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.


I have in my fork of cuke4nuke <http://github.com/aslakjo/Cuke4Nuke>
added support for the Norwegian attributes. Since i am kinda new to
the cuke4nuke project i would really like some help to see that the
implementation is done correctly and makes sens to some other then my
self.


All help and comments are welcome!


Regards Aslak Johannessen

-------------
Some links into the source:
language examples in Norwegian :
http://github.com/aslakjo/Cuke4Nuke/tree/master/examples/language/no/
the Norwegian attributes (is it really this simple) :
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/languages/no/Norwegian.cs

step attribute tests:
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Specifications/language/no/Norwegian_StepDefinition_Specification.cs
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-10 11:59:37 UTC
Permalink
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke <http://github.com/aslakjo/Cuke4Nuke> added support for the Norwegian attributes. Since i am kinda new to the cuke4nuke project i would really like some help to see that the implementation is done correctly and makes sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for all
of the i18n keywords. (
http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to go
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.

Here is an example of how the Gherkin gem is used for code generation (this
is for the pygments lexer):
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).

The result is here:
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py

A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.

If you write a script for cuke4nuke that does this I'll happily borrow it
for cuke4duke :-)

Aslak
Post by Aslak Johannessen
All help and comments are welcome!
Regards Aslak Johannessen
-------------
http://github.com/aslakjo/Cuke4Nuke/tree/master/examples/language/no/
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/languages/no/Norwegian.cs
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Specifications/language/no/Norwegian_StepDefinition_Specification.cs
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-10 12:44:07 UTC
Permalink
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke <http://github.com/aslakjo/Cuke4Nuke> added support for the Norwegian attributes. Since i am kinda new to the cuke4nuke project i would really like some help to see that the implementation is done correctly and makes sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for all
of the i18n keywords. (
http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to go
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation (this
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.

I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.

--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Richard Lawrence
2010-02-10 13:53:56 UTC
Permalink
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.

Thanks,

Richard
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
  Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
     Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
    kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would really
like some help to see that the implementation is done correctly and makes
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for all
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to go
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-16 20:44:53 UTC
Permalink
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber

It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke

To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable as
possible. With that in mind I would appreciate feedback.

To support other languages one should only need to write a new
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.

Hope this solves more than my problem.

--aslakjo



On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence <
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy <
Post by aslak hellesoy
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year
or
Post by aslak hellesoy
Post by Aslak Johannessen
so. Now i'm starting up a C# .NET project and want to take the tool
with me.
Post by aslak hellesoy
Post by Aslak Johannessen
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would
really
Post by aslak hellesoy
Post by Aslak Johannessen
like some help to see that the implementation is done correctly and
makes
Post by aslak hellesoy
Post by Aslak Johannessen
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for
all
Post by aslak hellesoy
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to
go
Post by aslak hellesoy
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile(It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
Post by aslak hellesoy
A similar script could generate a .cs source file for every step
keyword.
Post by aslak hellesoy
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow
it
Post by aslak hellesoy
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week,
so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Richard Lawrence
2010-02-17 08:33:30 UTC
Permalink
Would you also want to do language-specific versions of Before, After,
and Pending? If so, be aware that Before and After are about to get
tag support (via a constructor overload); the generator should be
easily extended for this.

Have you written tests to confirm that Cuke4Nuke handles the attribute
subclasses correctly?

Thanks,

Richard
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
  - illegal characters
  - duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable as
possible. With that in mind I would appreciate feedback.
To support other languages one should only need to write a new
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.
Hope this solves more than my problem.
--aslakjo
On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
Post by Aslak Johannessen
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap:  Kalkulator
  Som en bruker
  Ønsker jeg å få hjelp til å regne
  Slik at jeg ikke får regne feil
  Scenario: Legge sammen
     Gitt at jeg trykker "4" pluss "4"
     Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
    kalkulator = new Kalkulator.Kalkulator();
    kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would really
like some help to see that the implementation is done correctly and makes
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for all
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to go
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-17 09:06:36 UTC
Permalink
On Wed, Feb 17, 2010 at 9:33 AM, Richard Lawrence <
Post by Richard Lawrence
Would you also want to do language-specific versions of Before, After,
and Pending? If so, be aware that Before and After are about to get
tag support (via a constructor overload); the generator should be
easily extended for this.
Hm...

Then next thing on my agenda is "And", which haven't made attributes for.
Before After and Pending should not be to hard as well.
Will the before and after attribute be deprecated or will tags and
attributes both be available? If they both will be available I look into
anding attributes for them first.

Do you have any example of other tag support?
Post by Richard Lawrence
Have you written tests to confirm that Cuke4Nuke handles the attribute
subclasses correctly?
I have written tests in cuke4nuke here
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Specifications/language/no/Norwegian_StepDefinition_Specification.cs

I dont know if that covers attribute subclasses good enough? If not, give me
a hint, and I will see what i can do.

--aslakjo
Post by Richard Lawrence
Thanks,
Richard
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages
supported
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable
as
Post by Aslak Johannessen
possible. With that in mind I would appreciate feedback.
To support other languages one should only need to write a new
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.
Hope this solves more than my problem.
--aslakjo
On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
Post by Aslak Johannessen
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy
On Wed, Feb 10, 2010 at 3:54 AM, Aslak Johannessen <
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last
year
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
Post by Aslak Johannessen
or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would really
like some help to see that the implementation is done correctly and makes
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class
for
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
all
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way
to
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
go
about this is code generation.
The gherkin gem has a simple API that can be used to access the
various
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily
borrow
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication
when
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
writing the norwegian steps since they only contained boilerplate
code.
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google
Groups
Post by Aslak Johannessen
Post by Richard Lawrence
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
Post by Richard Lawrence
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Richard Lawrence
2010-02-17 09:21:54 UTC
Permalink
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 9:33 AM, Richard Lawrence
Post by Richard Lawrence
Would you also want to do language-specific versions of Before, After,
and Pending? If so, be aware that Before and After are about to get
tag support (via a constructor overload); the generator should be
easily extended for this.
Hm...
Then next thing on my agenda is "And", which haven't made attributes for.
There are no And or But attributes. And and But are conveniences for
Gherkin, but don't need to be reflected in the step definitions.
Post by Aslak Johannessen
Before After and Pending should not be to hard as well.
Will the before and after attribute be deprecated or will tags and
attributes both be available? If they both will be available I look into
anding attributes for them first.
Do you have any example of other tag support?
Haven't done it yet, but it will be like Cuke4Duke:
http://wiki.github.com/aslakhellesoy/cuke4duke/hooks. To support this,
BeforeAttribute and AfterAttribute will each get an additional
constructor to take tag strings.
Post by Aslak Johannessen
Post by Richard Lawrence
Have you written tests to confirm that Cuke4Nuke handles the attribute
subclasses correctly?
I have written tests in cuke4nuke here
http://github.com/aslakjo/Cuke4Nuke/blob/master/Cuke4Nuke/Specifications/language/no/Norwegian_StepDefinition_Specification.cs
I dont know if that covers attribute subclasses good enough? If not, give me
a hint, and I will see what i can do.
That ought to be sufficient, but an end-to-end Cucumber feature
covering i18n would be nice to make sure there are no surprises.
Post by Aslak Johannessen
--aslakjo
Post by Richard Lawrence
Thanks,
Richard
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
  - illegal characters
  - duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable as
possible. With that in mind I would appreciate feedback.
To support other languages one should only need to write a new
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.
Hope this solves more than my problem.
--aslakjo
On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
Post by Aslak Johannessen
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy
On Wed, Feb 10, 2010 at 3:54 AM, Aslak Johannessen
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year
or
so. Now i'm starting up a C# .NET project and want to take the tool
with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap:  Kalkulator
  Som en bruker
  Ønsker jeg å få hjelp til å regne
  Slik at jeg ikke får regne feil
  Scenario: Legge sammen
     Gitt at jeg trykker "4" pluss "4"
     Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
    kalkulator = new Kalkulator.Kalkulator();
    kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would really
like some help to see that the implementation is done correctly and makes
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for
all
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way to
go
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow
it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-17 09:29:10 UTC
Permalink
On Wed, Feb 17, 2010 at 9:33 AM, Richard Lawrence <
Post by Richard Lawrence
Would you also want to do language-specific versions of Before, After,
and Pending? If so, be aware that Before and After are about to get
Since these words aren't part of Gherkin we don't have translations for
those in the YAML file. Moreover, they are used less frequently than GWT, so
there is no need to translate them. We only need translations of what's
printed in snippets: GWT.

Aslak
Post by Richard Lawrence
tag support (via a constructor overload); the generator should be
easily extended for this.
Have you written tests to confirm that Cuke4Nuke handles the attribute
subclasses correctly?
Thanks,
Richard
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages
supported
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable
as
Post by Aslak Johannessen
possible. With that in mind I would appreciate feedback.
To support other languages one should only need to write a new
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.
Hope this solves more than my problem.
--aslakjo
On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
Post by Aslak Johannessen
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy
On Wed, Feb 10, 2010 at 3:54 AM, Aslak Johannessen <
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last
year
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
Post by Aslak Johannessen
or
so. Now i'm starting up a C# .NET project and want to take the tool with me.
But as far as I can see from the current source it does not support for
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would really
like some help to see that the implementation is done correctly and makes
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class
for
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
all
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way
to
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
go
about this is code generation.
The gherkin gem has a simple API that can be used to access the
various
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile (It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
A similar script could generate a .cs source file for every step keyword.
Then we can just run the script again whenever someone contributes a new
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily
borrow
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
it
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication
when
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
writing the norwegian steps since they only contained boilerplate
code.
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
Post by Richard Lawrence
Post by Aslak Johannessen
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google
Groups
Post by Aslak Johannessen
Post by Richard Lawrence
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
Post by Richard Lawrence
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by Aslak Johannessen
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-17 09:52:00 UTC
Permalink
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable as
possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke and
Duke4Nuke.

The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the compile
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this class
and provide project-specific templates in their own build system. The main
reason I think it belongs in the Gherkin project rather than Cucumber is
that it is "closer" to Gherkin, which is strictly about the Gherkin language
and all the i18n.

Some other areas of improvement:
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make a
gwt_keywords method)
* Make strip_illegal_characters! and strip_keyword_of_paranteses! return the
result and use gsub instead
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq

The current generator generates one file for all keywords. That's fine for
C#, but for Java I think we need a file per keyword. (Only one public class
per file IIRC).

I'd love to hve this API:

# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})

# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})

The generator could look at the first argument to figure out whether it is a
directory or not. If it is a directory, generate one file per keyword,
assigning each keyword (after making it legal) to a 'keyword' variable that
the template picks up. Otherwise, genrate a file, assigning all legalised
keywords to a 'keywords' variable.

Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will make
a Cuke4IPhone one day too, based on Obj-C :-)

WDYT?

Aslak

To support other languages one should only need to write a new
Post by Aslak Johannessen
i18n_steps.<fill in extention of your language>.erb, and hook this up via
the a new rake task.
Hope this solves more than my problem.
--aslakjo
On Wed, Feb 10, 2010 at 2:53 PM, Richard Lawrence <
Post by Richard Lawrence
The Given, When, and Then attributes just inherit from StepDefinition;
they don't actually do anything. So, I'd be comfortable having a
single generated cs file with attributes for all the i18n GWT
keywords. If someone adds a task to the Cuke4Nuke rake file to do this
code generation, I'll gladly include it in the next release.
Thanks,
Richard
On Wed, Feb 10, 2010 at 12:59 PM, aslak hellesoy <
Post by aslak hellesoy
Post by Aslak Johannessen
Hi
I have been using cucumber for some rails projects over the last year
or
Post by aslak hellesoy
Post by Aslak Johannessen
so. Now i'm starting up a C# .NET project and want to take the tool
with me.
Post by aslak hellesoy
Post by Aslak Johannessen
But as far as I can see from the current source it does not support
for
Post by aslak hellesoy
Post by Aslak Johannessen
ex. Norwegian step definitions.
[Code in Norwegian]
In the feature.
# language: no
Egenskap: Kalkulator
Som en bruker
Ønsker jeg å få hjelp til å regne
Slik at jeg ikke får regne feil
Scenario: Legge sammen
Gitt at jeg trykker "4" pluss "4"
Så skal jeg få "8"
In the steps.cs file
public void AtJegTrykker4Pluss4(string tall, string annetTall)
{
kalkulator = new Kalkulator.Kalkulator();
kalkulator.LeggSammen(int.Parse(tall), int.Parse(annetTall));
}
The ruby side is no problem cucumber supports this perfectly. On the
cuke4nuke side the Gitt(Given in English) attribute is not present.
I have in my fork of cuke4nuke added support for the Norwegian
attributes. Since i am kinda new to the cuke4nuke project i would
really
Post by aslak hellesoy
Post by Aslak Johannessen
like some help to see that the implementation is done correctly and
makes
Post by aslak hellesoy
Post by Aslak Johannessen
sens to some other then my self.
I need to do the same for Cuke4Duke - generate an annotation class for
all
Post by aslak hellesoy
of the i18n keywords.
(http://github.com/aslakhellesoy/cuke4duke/issues#issue/28). The way
to go
Post by aslak hellesoy
about this is code generation.
The gherkin gem has a simple API that can be used to access the various
keywords of all supported i18n languages.
Here is an example of how the Gherkin gem is used for code generation
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/Rakefile(It
uses ERb as a template engine).
http://github.com/bmabey/gherkin-pygments-lexer/blob/master/gherkin_lexer/__init__.py
Post by aslak hellesoy
A similar script could generate a .cs source file for every step
keyword.
Post by aslak hellesoy
Then we can just run the script again whenever someone contributes a
new
Post by aslak hellesoy
i18n language or adds a synonym.
If you write a script for cuke4nuke that does this I'll happily borrow
it
Post by aslak hellesoy
for cuke4duke :-)
Aslak
Aha, this sounds more viable a solution. It feelt like duplication when
writing the norwegian steps since they only contained boilerplate code.
I will look into code generation as soon as i get some free time on my
hands. It looks quite straight forward. Might not happen until next
week, so
if some one can get there before me, be my guest.
--aslakjo
--
You received this message because you are subscribed to the Google
Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-17 10:31:38 UTC
Permalink
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable as
possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke and
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the compile
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this class
and provide project-specific templates in their own build system. The main
reason I think it belongs in the Gherkin project rather than Cucumber is
that it is "closer" to Gherkin, which is strictly about the Gherkin language
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make a
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses! return
the result and use gsub instead
Agreed

* remove_duplication_in_keywords can replaced with a single call to
Post by aslak hellesoy
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make. The
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics. Relying on
ordering is fragile, maybe a real object is called for.
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine for
C#, but for Java I think we need a file per keyword. (Only one public class
per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether it is
a directory or not. If it is a directory, generate one file per keyword,
assigning each keyword (after making it legal) to a 'keyword' variable that
the template picks up. Otherwise, genrate a file, assigning all legalised
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change. I'll
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will
make a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!

Thanks to both Aslak and Richard for the review and suggestions!

--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-17 10:41:36 UTC
Permalink
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing /rake
generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke and
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the compile
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this class
and provide project-specific templates in their own build system. The main
reason I think it belongs in the Gherkin project rather than Cucumber is
that it is "closer" to Gherkin, which is strictly about the Gherkin language
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make a
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses! return
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Post by aslak hellesoy
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make. The
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics. Relying on
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber (such
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a StepKeyword
Attribute class, and have all of the generated i18n attributes extend from
that. This way the generator won't have treat English as a special case - it
will just be generated just like other languages.

Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.

Aslak
Post by Aslak Johannessen
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine for
C#, but for Java I think we need a file per keyword. (Only one public class
per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether it is
a directory or not. If it is a directory, generate one file per keyword,
assigning each keyword (after making it legal) to a 'keyword' variable that
the template picks up. Otherwise, genrate a file, assigning all legalised
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change. I'll
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will
make a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Richard Lawrence
2010-02-17 10:45:29 UTC
Permalink
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
  - illegal characters
  - duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke and
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the compile
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this class
and provide project-specific templates in their own build system. The main
reason I think it belongs in the Gherkin project rather than Cucumber is
that it is "closer" to Gherkin, which is strictly about the Gherkin language
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make a
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses! return
the result and use gsub instead
Agreed
Post by aslak hellesoy
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make. The
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics. Relying on
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber (such
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a StepKeyword
Attribute class, and have all of the generated i18n attributes extend from
that. This way the generator won't have treat English as a special case - it
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs)

Richard
Post by aslak hellesoy
Aslak
Post by Aslak Johannessen
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine
for C#, but for Java I think we need a file per keyword. (Only one public
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether it
is a directory or not. If it is a directory, generate one file per keyword,
assigning each keyword (after making it legal) to a 'keyword' variable that
the template picks up. Otherwise, genrate a file, assigning all legalised
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change. I'll
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will make
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-17 11:58:42 UTC
Permalink
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which
is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this
class
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
and provide project-specific templates in their own build system. The
main
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
reason I think it belongs in the Gherkin project rather than Cucumber
is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make
a
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
the result and use gsub instead
Agreed
Post by aslak hellesoy
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make. The
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics. Relying
on
Post by aslak hellesoy
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber
(such
Post by aslak hellesoy
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Post by aslak hellesoy
Attribute class, and have all of the generated i18n attributes extend
from
Post by aslak hellesoy
that. This way the generator won't have treat English as a special case -
it
Post by aslak hellesoy
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template. I'll
make the next one reflect that there is no diffrence between given when then
and and.

--aslakjo
Post by Richard Lawrence
Post by aslak hellesoy
Aslak
Post by Aslak Johannessen
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether it
is a directory or not. If it is a directory, generate one file per
keyword,
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
assigning each keyword (after making it legal) to a 'keyword' variable
that
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by aslak hellesoy
Post by Aslak Johannessen
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will
make
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
--
You received this message because you are subscribed to the Google
Groups
Post by aslak hellesoy
Post by Aslak Johannessen
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by aslak hellesoy
Post by Aslak Johannessen
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Cukes" group.
To unsubscribe from this group, send email to
.
Post by aslak hellesoy
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-18 21:48:23 UTC
Permalink
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which
is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber.
Cuke4Duke,
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
Cuke4Nuke (and others in the future) could then just use/extend this
class
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
and provide project-specific templates in their own build system. The
main
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
reason I think it belongs in the Gherkin project rather than Cucumber
is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and
make a
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
the result and use gsub instead
Agreed
Post by aslak hellesoy
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make.
The
Post by aslak hellesoy
Post by Aslak Johannessen
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics.
Relying on
Post by aslak hellesoy
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber
(such
Post by aslak hellesoy
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Post by aslak hellesoy
Attribute class, and have all of the generated i18n attributes extend
from
Post by aslak hellesoy
that. This way the generator won't have treat English as a special case
- it
Post by aslak hellesoy
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template. I'll
make the next one reflect that there is no diffrence between given when then
and and.
--aslakjo
Post by Richard Lawrence
Post by aslak hellesoy
Aslak
Post by Aslak Johannessen
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations',
lambda{|lang_name|
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether
it
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
is a directory or not. If it is a directory, generate one file per
keyword,
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
assigning each keyword (after making it legal) to a 'keyword' variable
that
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by aslak hellesoy
Post by Aslak Johannessen
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone
will make
Post by aslak hellesoy
Post by Aslak Johannessen
Post by aslak hellesoy
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
After some refactoring does the code generator look much nicer. It is also
moved to /Gherkin:CodeGeneration/.
Cuke4Nuke is now equipped with /rake generate:attributes/ which uses Gherkin
to generate code togheter with its own template. I have no C# compiler at
hand so the compile check has to wait until tomorrow. When it is performed i
think that we are good to go.

The Gherkin code genrator is done how ever it still lacks support for
outputing to diffrent files with diffrent filenames, which is required for
cuke4duke support. That has to wait, for my part anyoneelse are welcome to
pitch in if they like.

gherkin at http://github.com/aslakjo/gherkin
cuke4nuke at http://github.com/aslakjo/Cuke4Nuke

--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-19 01:07:59 UTC
Permalink
Post by Aslak Johannessen
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
On Tue, Feb 16, 2010 at 9:44 PM, Aslak Johannessen <
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then,
which is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by aslak hellesoy
Post by Aslak Johannessen
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber.
Cuke4Duke,
Post by aslak hellesoy
Post by Aslak Johannessen
Cuke4Nuke (and others in the future) could then just use/extend this
class
Post by aslak hellesoy
Post by Aslak Johannessen
and provide project-specific templates in their own build system. The
main
Post by aslak hellesoy
Post by Aslak Johannessen
reason I think it belongs in the Gherkin project rather than Cucumber
is
Post by aslak hellesoy
Post by Aslak Johannessen
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by aslak hellesoy
Post by Aslak Johannessen
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and
make a
Post by aslak hellesoy
Post by Aslak Johannessen
gwt_keywords method)
Agreed
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by aslak hellesoy
Post by Aslak Johannessen
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array
is
Post by aslak hellesoy
Post by Aslak Johannessen
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make.
The
Post by aslak hellesoy
Post by Aslak Johannessen
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics.
Relying on
Post by aslak hellesoy
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber
(such
Post by aslak hellesoy
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Post by aslak hellesoy
Attribute class, and have all of the generated i18n attributes extend
from
Post by aslak hellesoy
that. This way the generator won't have treat English as a special case
- it
Post by aslak hellesoy
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template. I'll
make the next one reflect that there is no diffrence between given when then
and and.
--aslakjo
Post by Richard Lawrence
Post by aslak hellesoy
Aslak
Post by Aslak Johannessen
The current generator generates one file for all keywords. That's
fine
Post by aslak hellesoy
Post by Aslak Johannessen
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by aslak hellesoy
Post by Aslak Johannessen
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations',
lambda{|lang_name|
Post by aslak hellesoy
Post by Aslak Johannessen
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether
it
Post by aslak hellesoy
Post by Aslak Johannessen
is a directory or not. If it is a directory, generate one file per
keyword,
Post by aslak hellesoy
Post by Aslak Johannessen
assigning each keyword (after making it legal) to a 'keyword'
variable that
Post by aslak hellesoy
Post by Aslak Johannessen
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by aslak hellesoy
Post by Aslak Johannessen
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by aslak hellesoy
Post by Aslak Johannessen
see what i can do.
Having a versatile code generator like this would be really useful
for
Post by aslak hellesoy
Post by Aslak Johannessen
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone
will make
Post by aslak hellesoy
Post by Aslak Johannessen
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
After some refactoring does the code generator look much nicer. It is also
moved to /Gherkin:CodeGeneration/.
Cuke4Nuke is now equipped with /rake generate:attributes/ which uses
Gherkin to generate code togheter with its own template. I have no C#
compiler at hand so the compile check has to wait until tomorrow. When it is
performed i think that we are good to go.
apt-get install mono :-)

awesome - looking forward to taking a new peek.

Aslak
Post by Aslak Johannessen
The Gherkin code genrator is done how ever it still lacks support for
outputing to diffrent files with diffrent filenames, which is required for
cuke4duke support. That has to wait, for my part anyoneelse are welcome to
pitch in if they like.
gherkin at http://github.com/aslakjo/gherkin
cuke4nuke at http://github.com/aslakjo/Cuke4Nuke
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-22 12:08:30 UTC
Permalink
Post by Aslak Johannessen
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
Post by aslak hellesoy
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
On Tue, Feb 16, 2010 at 9:44 PM, Aslak Johannessen <
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then,
which is
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke
and
Post by aslak hellesoy
Post by Aslak Johannessen
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by aslak hellesoy
Post by Aslak Johannessen
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber.
Cuke4Duke,
Post by aslak hellesoy
Post by Aslak Johannessen
Cuke4Nuke (and others in the future) could then just use/extend this
class
Post by aslak hellesoy
Post by Aslak Johannessen
and provide project-specific templates in their own build system. The
main
Post by aslak hellesoy
Post by Aslak Johannessen
reason I think it belongs in the Gherkin project rather than Cucumber
is
Post by aslak hellesoy
Post by Aslak Johannessen
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by aslak hellesoy
Post by Aslak Johannessen
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and
make a
Post by aslak hellesoy
Post by Aslak Johannessen
gwt_keywords method)
Agreed
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by aslak hellesoy
Post by Aslak Johannessen
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array
is
Post by aslak hellesoy
Post by Aslak Johannessen
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make.
The
Post by aslak hellesoy
Post by Aslak Johannessen
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics.
Relying on
Post by aslak hellesoy
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber
(such
Post by aslak hellesoy
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Post by aslak hellesoy
Attribute class, and have all of the generated i18n attributes extend
from
Post by aslak hellesoy
that. This way the generator won't have treat English as a special case
- it
Post by aslak hellesoy
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template. I'll
make the next one reflect that there is no diffrence between given when then
and and.
--aslakjo
Post by Richard Lawrence
Post by aslak hellesoy
Aslak
Post by Aslak Johannessen
The current generator generates one file for all keywords. That's
fine
Post by aslak hellesoy
Post by Aslak Johannessen
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by aslak hellesoy
Post by Aslak Johannessen
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations',
lambda{|lang_name|
Post by aslak hellesoy
Post by Aslak Johannessen
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether
it
Post by aslak hellesoy
Post by Aslak Johannessen
is a directory or not. If it is a directory, generate one file per
keyword,
Post by aslak hellesoy
Post by Aslak Johannessen
assigning each keyword (after making it legal) to a 'keyword'
variable that
Post by aslak hellesoy
Post by Aslak Johannessen
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by aslak hellesoy
Post by Aslak Johannessen
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by aslak hellesoy
Post by Aslak Johannessen
see what i can do.
Having a versatile code generator like this would be really useful
for
Post by aslak hellesoy
Post by Aslak Johannessen
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone
will make
Post by aslak hellesoy
Post by Aslak Johannessen
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
After some refactoring does the code generator look much nicer. It is also
moved to /Gherkin:CodeGeneration/.
Cuke4Nuke is now equipped with /rake generate:attributes/ which uses
Gherkin to generate code togheter with its own template. I have no C#
compiler at hand so the compile check has to wait until tomorrow. When it is
performed i think that we are good to go.
The Gherkin code genrator is done how ever it still lacks support for
outputing to diffrent files with diffrent filenames, which is required for
cuke4duke support. That has to wait, for my part anyoneelse are welcome to
pitch in if they like.
gherkin at http://github.com/aslakjo/gherkin
cuke4nuke at http://github.com/aslakjo/Cuke4Nuke
Hi again,

Inspired by what you've done to generate i18n attributes for Cuke4Duke I
decided to do the same for Cuke4Duke. A couple of examples:

*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/NO.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/EN.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/ZHCN.java

I tried to do this with the code generator you have added to your gherkin
fork, but found that it didn't quite meet my needs. (I need to generate one
file per language). However, I was able to generate the code above with just
a tiny change to gherkin:

*
http://github.com/aslakhellesoy/gherkin/commit/ac19df63e9270fa46cc8b19c5b2e81f51a23898c

And a simple Rake task of 15 lines and an ERB template of 19 lines. (No
separate code generator class):

* http://github.com/aslakhellesoy/cuke4duke/blob/master/Rakefile
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/code_generator/java_annotation.erb

Since it turned out to be so simple this has made me question the utility of
a separate code generator class like we talked about (and that you have
contributed).
With some effort we could probably come up with a code generator class that
satisfies various needs, but I think the effort will be bigger than just
hand-rolling one like I have done.

So my initial advice to implement a generic code generator was probably bad
advice. Sorry about that. Do you think you could refactor the Cuke4Nuke code
generator following the style I have used for Cuke4Duke? I think the total
would tally up to a simpler overall solution.

Aslak
Post by Aslak Johannessen
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Aslak Johannessen
2010-02-22 13:34:15 UTC
Permalink
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
On Wed, Feb 17, 2010 at 11:31 AM, Aslak Johannessen <
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
On Tue, Feb 16, 2010 at 9:44 PM, Aslak Johannessen <
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by Aslak Johannessen
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by Aslak Johannessen
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then,
which is
Post by Aslak Johannessen
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when
then
Post by Aslak Johannessen
Post by Aslak Johannessen
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by Aslak Johannessen
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke
and
Post by Aslak Johannessen
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke
and
Post by Aslak Johannessen
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by Aslak Johannessen
task depends upon). I think it would make more sense if the base
code
Post by Aslak Johannessen
generator lived in the Gherkin project rather than Cucumber.
Cuke4Duke,
Post by Aslak Johannessen
Cuke4Nuke (and others in the future) could then just use/extend this
class
Post by Aslak Johannessen
and provide project-specific templates in their own build system.
The main
Post by Aslak Johannessen
reason I think it belongs in the Gherkin project rather than
Cucumber is
Post by Aslak Johannessen
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by Aslak Johannessen
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and
make a
Post by Aslak Johannessen
gwt_keywords method)
Agreed
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by Aslak Johannessen
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array
is
Post by Aslak Johannessen
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make.
The
Post by Aslak Johannessen
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics.
Relying on
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber
(such
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Attribute class, and have all of the generated i18n attributes extend
from
that. This way the generator won't have treat English as a special
case - it
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template. I'll
make the next one reflect that there is no diffrence between given when then
and and.
--aslakjo
Post by Richard Lawrence
Aslak
Post by Aslak Johannessen
The current generator generates one file for all keywords. That's
fine
Post by Aslak Johannessen
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by Aslak Johannessen
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations',
lambda{|lang_name|
Post by Aslak Johannessen
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether
it
Post by Aslak Johannessen
is a directory or not. If it is a directory, generate one file per
keyword,
Post by Aslak Johannessen
assigning each keyword (after making it legal) to a 'keyword'
variable that
Post by Aslak Johannessen
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by Aslak Johannessen
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by Aslak Johannessen
see what i can do.
Having a versatile code generator like this would be really useful
for
Post by Aslak Johannessen
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone
will make
Post by Aslak Johannessen
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
After some refactoring does the code generator look much nicer. It is also
moved to /Gherkin:CodeGeneration/.
Cuke4Nuke is now equipped with /rake generate:attributes/ which uses
Gherkin to generate code togheter with its own template. I have no C#
compiler at hand so the compile check has to wait until tomorrow. When it is
performed i think that we are good to go.
The Gherkin code genrator is done how ever it still lacks support for
outputing to diffrent files with diffrent filenames, which is required for
cuke4duke support. That has to wait, for my part anyoneelse are welcome to
pitch in if they like.
gherkin at http://github.com/aslakjo/gherkin
cuke4nuke at http://github.com/aslakjo/Cuke4Nuke
Hi again,
Inspired by what you've done to generate i18n attributes for Cuke4Duke I
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/NO.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/EN.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/ZHCN.java
I tried to do this with the code generator you have added to your gherkin
fork, but found that it didn't quite meet my needs. (I need to generate one
file per language). However, I was able to generate the code above with just
*
http://github.com/aslakhellesoy/gherkin/commit/ac19df63e9270fa46cc8b19c5b2e81f51a23898c
And a simple Rake task of 15 lines and an ERB template of 19 lines. (No
* http://github.com/aslakhellesoy/cuke4duke/blob/master/Rakefile
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/code_generator/java_annotation.erb
Since it turned out to be so simple this has made me question the utility
of a separate code generator class like we talked about (and that you have
contributed).
With some effort we could probably come up with a code generator class that
satisfies various needs, but I think the effort will be bigger than just
hand-rolling one like I have done.
So my initial advice to implement a generic code generator was probably bad
advice. Sorry about that. Do you think you could refactor the Cuke4Nuke code
generator following the style I have used for Cuke4Duke? I think the total
would tally up to a simpler overall solution.
I have looked at your implementation, and I see your point of not needing a
code generation class. The generator got this big and complex since
I didn't fully understand who there is no difference in the use of Give When
Then step implementations on the lower levels.

I'll change the cuke4nuke rake task and give Richard a ping.

Funny how code isn't the only contribution one can do to the community :D

--aslakjo
Post by aslak hellesoy
Aslak
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-22 15:26:05 UTC
Permalink
Post by Aslak Johannessen
Post by aslak hellesoy
Post by Aslak Johannessen
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 11:45 AM, Richard Lawrence <
Post by Richard Lawrence
On Wed, Feb 17, 2010 at 12:41 PM, aslak hellesoy
On Wed, Feb 17, 2010 at 11:31 AM, Aslak Johannessen <
Post by Aslak Johannessen
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy
On Tue, Feb 16, 2010 at 9:44 PM, Aslak Johannessen <
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By
doing
Post by Aslak Johannessen
Post by Aslak Johannessen
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains
several
Post by Aslak Johannessen
Post by Aslak Johannessen
namespaces and class definitions required to do all i18n languages
supported
Post by Aslak Johannessen
Post by Aslak Johannessen
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then,
which is
Post by Aslak Johannessen
Post by Aslak Johannessen
already implemented and 2) regarding languages where given when
then
Post by Aslak Johannessen
Post by Aslak Johannessen
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as
readable
Post by Aslak Johannessen
Post by Aslak Johannessen
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to
Cuke4Duke and
Post by Aslak Johannessen
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke
and
Post by Aslak Johannessen
Cuke4Nuke (Ideally they would have a source:generate task that the
compile
Post by Aslak Johannessen
task depends upon). I think it would make more sense if the base
code
Post by Aslak Johannessen
generator lived in the Gherkin project rather than Cucumber.
Cuke4Duke,
Post by Aslak Johannessen
Cuke4Nuke (and others in the future) could then just use/extend
this class
Post by Aslak Johannessen
and provide project-specific templates in their own build system.
The main
Post by Aslak Johannessen
reason I think it belongs in the Gherkin project rather than
Cucumber is
Post by Aslak Johannessen
that it is "closer" to Gherkin, which is strictly about the Gherkin
language
Post by Aslak Johannessen
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and
make a
Post by Aslak Johannessen
gwt_keywords method)
Agreed
* Make strip_illegal_characters! and strip_keyword_of_paranteses!
return
Post by Aslak Johannessen
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Array.uniq
The problem here is that the order of keywords in the returned array
is
Post by Aslak Johannessen
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make.
The
Post by Aslak Johannessen
distinction is not important in cuke4nuke(imho, since all do
actually
Post by Aslak Johannessen
inherit from StepDefinitionAttribute) but it ads some semantics.
Relying on
Post by Aslak Johannessen
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish
between
Given, When and Then - and neither should any derivative of Cucumber
(such
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a
StepKeyword
Attribute class, and have all of the generated i18n attributes extend
from
that. This way the generator won't have treat English as a special
case - it
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for
StepKeyword
instead of Given, When or Then.
No refactoring necessary: GivenAttribute, WhenAttribute, and
ThenAttribute already inherit from StepDefinitionAttribute. So should
the i18n attributes. (See, for example,
http://github.com/richardlawrence/Cuke4Nuke/blob/master/Cuke4Nuke/Framework/GivenAttribute.cs
)
Richard
Thats correct, I missed Aslaks point when making the first template.
I'll make the next one reflect that there is no diffrence between given when
then and and.
--aslakjo
Post by Richard Lawrence
Aslak
Post by Aslak Johannessen
The current generator generates one file for all keywords. That's
fine
Post by Aslak Johannessen
for C#, but for Java I think we need a file per keyword. (Only one
public
Post by Aslak Johannessen
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations',
lambda{|lang_name|
Post by Aslak Johannessen
make_legal(lang_name)})
# C# usage
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs',
lambda{|lang_name|
Post by Aslak Johannessen
make_legal(lang_name)})
The generator could look at the first argument to figure out
whether it
Post by Aslak Johannessen
is a directory or not. If it is a directory, generate one file per
keyword,
Post by Aslak Johannessen
assigning each keyword (after making it legal) to a 'keyword'
variable that
Post by Aslak Johannessen
the template picks up. Otherwise, genrate a file, assigning all
legalised
Post by Aslak Johannessen
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change.
I'll
Post by Aslak Johannessen
see what i can do.
Having a versatile code generator like this would be really useful
for
Post by Aslak Johannessen
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone
will make
Post by Aslak Johannessen
a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
After some refactoring does the code generator look much nicer. It is
also moved to /Gherkin:CodeGeneration/.
Cuke4Nuke is now equipped with /rake generate:attributes/ which uses
Gherkin to generate code togheter with its own template. I have no C#
compiler at hand so the compile check has to wait until tomorrow. When it is
performed i think that we are good to go.
The Gherkin code genrator is done how ever it still lacks support for
outputing to diffrent files with diffrent filenames, which is required for
cuke4duke support. That has to wait, for my part anyoneelse are welcome to
pitch in if they like.
gherkin at http://github.com/aslakjo/gherkin
cuke4nuke at http://github.com/aslakjo/Cuke4Nuke
Hi again,
Inspired by what you've done to generate i18n attributes for Cuke4Duke I
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/NO.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/EN.java
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/java/cuke4duke/annotation/ZHCN.java
I tried to do this with the code generator you have added to your gherkin
fork, but found that it didn't quite meet my needs. (I need to generate one
file per language). However, I was able to generate the code above with just
*
http://github.com/aslakhellesoy/gherkin/commit/ac19df63e9270fa46cc8b19c5b2e81f51a23898c
And a simple Rake task of 15 lines and an ERB template of 19 lines. (No
* http://github.com/aslakhellesoy/cuke4duke/blob/master/Rakefile
*
http://github.com/aslakhellesoy/cuke4duke/blob/master/cuke4duke/src/main/code_generator/java_annotation.erb
Since it turned out to be so simple this has made me question the utility
of a separate code generator class like we talked about (and that you have
contributed).
With some effort we could probably come up with a code generator class
that satisfies various needs, but I think the effort will be bigger than
just hand-rolling one like I have done.
So my initial advice to implement a generic code generator was probably
bad advice. Sorry about that. Do you think you could refactor the Cuke4Nuke
code generator following the style I have used for Cuke4Duke? I think the
total would tally up to a simpler overall solution.
I have looked at your implementation, and I see your point of not needing a
code generation class. The generator got this big and complex since
I didn't fully understand who there is no difference in the use of Give When
Then step implementations on the lower levels.
I'll change the cuke4nuke rake task and give Richard a ping.
Funny how code isn't the only contribution one can do to the community :D
I bet that if we had paired on this we would have found the simple solution
a lot quicker. Oh well.

I just added a rake task to generate i18n traits for Scala too:
http://bit.ly/d6Zc7C
This generates all the code into one file - similar to what you need for
Cuke4Nuke. Just 7 more LOC (plus the template)

Aslak
Post by Aslak Johannessen
--aslakjo
Post by aslak hellesoy
Aslak
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
aslak hellesoy
2010-02-17 10:45:36 UTC
Permalink
Post by aslak hellesoy
On Wed, Feb 17, 2010 at 10:52 AM, aslak hellesoy <
Post by aslak hellesoy
Post by Aslak Johannessen
I just now pushed a cuke code generator to github.
http://github.com/aslakjo/cucumber
It is now setup to do cuke4nuke step attribute generation. By doing
/rake generate:cuke4nuke/ you now get a steps.cs file. It contains several
namespaces and class definitions required to do all i18n languages supported
by Gherkin in cuke4nuke and C#. I'll push this file into cuke4nuke
http://github.com/aslakjo/Cuke4Nuke
To make the steps compile directly I had to do some striping of;
- illegal characters
- duplication of keywords 1) with respect to given when then, which is
already implemented and 2) regarding languages where given when then
translate to the same keyword.
This complicates the task a bit but i have tried to keep it as readable
as possible. With that in mind I would appreciate feedback.
Great work Aslak, this is going to be a big improvement to Cuke4Duke and
Duke4Nuke.
The projects that are going to do the code generation are Cuke4Duke and
Cuke4Nuke (Ideally they would have a source:generate task that the compile
task depends upon). I think it would make more sense if the base code
generator lived in the Gherkin project rather than Cucumber. Cuke4Duke,
Cuke4Nuke (and others in the future) could then just use/extend this class
and provide project-specific templates in their own build system. The main
reason I think it belongs in the Gherkin project rather than Cucumber is
that it is "closer" to Gherkin, which is strictly about the Gherkin language
and all the i18n.
Gherkin looks like the correct place for the generator, I'll move it there.
Post by aslak hellesoy
* step keywords can be fetched simply with
step_keywords-and_keywords-but_keywords. (Or we could refactor and make a
gwt_keywords method)
Agreed
Post by aslak hellesoy
* Make strip_illegal_characters! and strip_keyword_of_paranteses! return
the result and use gsub instead
Agreed
* remove_duplication_in_keywords can replaced with a single call to
Post by aslak hellesoy
Array.uniq
The problem here is that the order of keywords in the returned array is
defining which of them are translation of given, when or then. It is
important for the erb file to know which of the classes not to make. The
distinction is not important in cuke4nuke(imho, since all do actually
inherit from StepDefinitionAttribute) but it ads some semantics. Relying on
ordering is fragile, maybe a real object is called for.
Ah! I forgot to comment on that. Cucumber does not distinguish between
Given, When and Then - and neither should any derivative of Cucumber (such
as Cuke4Nuke. The best solution for Cuke4Nuke would be to have a StepKeyword
Attribute class, and have all of the generated i18n attributes extend from
that. This way the generator won't have treat English as a special case - it
will just be generated just like other languages.
Cuke4Nuke would have to be slightly refactored to look for StepKeyword
instead of Given, When or Then.
Aslak
Post by aslak hellesoy
The current generator generates one file for all keywords. That's fine
for C#, but for Java I think we need a file per keyword. (Only one public
class per file IIRC).
# Java usage
generator = Gherkin::CodeGenerator.new(java_erb_template)
generator.generate('src/java/cuke4duke/annotations', lambda{|lang_name|
make_legal(lang_name)})
Better:

generator.generate('src/java/cuke4duke/annotations',
class_name=lambda{|lang_name| class_name_for(lang_name)},
file_name=lambda{|lang_name| class_name_for(lang_name) + ".java"})

(We need to pass to procs - one to create a class name (to use inside the
template) and one to generate the file name to write to.)

Aslak

# C# usage
Post by aslak hellesoy
Post by aslak hellesoy
generator = Gherkin::CodeGenerator.new(csharp_erb_template)
generator.generate('src/Cuke4Nuke/Attributes.cs', lambda{|lang_name|
make_legal(lang_name)})
The generator could look at the first argument to figure out whether it
is a directory or not. If it is a directory, generate one file per keyword,
assigning each keyword (after making it legal) to a 'keyword' variable that
the template picks up. Otherwise, genrate a file, assigning all legalised
keywords to a 'keywords' variable.
I like this concept! And it should not be to hard making the change. I'll
see what i can do.
Post by aslak hellesoy
Having a versatile code generator like this would be really useful for
upcoming tools like http://github.com/dgfitch/Cuke4Lua and
http://github.com/paoloambrosio/spike-cuke4cpp. I suspect someone will
make a Cuke4IPhone one day too, based on Obj-C :-)
Most definitely!
Thanks to both Aslak and Richard for the review and suggestions!
--aslakjo
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group, send email to
.
For more options, visit this group at
http://groups.google.com/group/cukes?hl=en.
--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to cukes+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
Loading...