Skip to content

Commit

Permalink
Move all generated lexers to gherkin/lexer - for all languages. Prior…
Browse files Browse the repository at this point in the history
… to this different platforms used inconsistent packages
  • Loading branch information
aslakhellesoy committed Jul 8, 2012
1 parent 6446921 commit 9d01754
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 29 deletions.
7 changes: 6 additions & 1 deletion java/src/main/java/gherkin/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String getUnderscoredIsoCode() {
}

public Lexer lexer(Listener listener) {
String qualifiedI18nLexerClassName = "gherkin.lexer.i18n." + localeName().toUpperCase();
String qualifiedI18nLexerClassName = "gherkin.lexer." + capitalize(getUnderscoredIsoCode());
try {
Class<?> delegateClass = getClass().getClassLoader().loadClass(qualifiedI18nLexerClassName);
return (Lexer) delegateClass.getConstructor(Listener.class).newInstance(listener);
Expand All @@ -108,6 +108,11 @@ public Lexer lexer(Listener listener) {
}
}

private String capitalize(String s) {
return s.substring(0, 1).toUpperCase() + s.substring(1);
}


/**
* Workaround for he and id bugs in the JDK.
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457127
Expand Down
46 changes: 46 additions & 0 deletions java/src/main/java/gherkin/lexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Ar.java
Bg.java
Bm.java
Ca.java
Cs.java
Cy_gb.java
Da.java
De.java
En.java
En_au.java
En_lol.java
En_pirate.java
En_scouse.java
En_tx.java
Eo.java
Es.java
Et.java
Fi.java
Fr.java
He.java
Hr.java
Hu.java
Id.java
Is.java
It.java
Ja.java
Ko.java
Lt.java
Lu.java
Lv.java
Nl.java
No.java
Pl.java
Pt.java
Ro.java
Ru.java
Sk.java
Sr_cyrl.java
Sr_latn.java
Sv.java
Tr.java
Uk.java
Uz.java
Vi.java
Zh_cn.java
Zh_tw.java
1 change: 0 additions & 1 deletion java/src/main/java/gherkin/lexer/i18n/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions java/src/main/java/gherkin/parser/StateMachineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import gherkin.lexer.Lexer;
import gherkin.lexer.Listener;
import gherkin.lexer.i18n.EN;
import gherkin.lexer.En;
import gherkin.util.FixJava;

import java.util.ArrayList;
Expand All @@ -18,7 +18,7 @@ public StateMachineReader(String name) {

public List<List<String>> transitionTable() {
transitionTable = new ArrayList<List<String>>();
Lexer lexer = new EN(this);
Lexer lexer = new En(this);
lexer.scan(FixJava.readResource(machinePath));
return transitionTable;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/gherkin/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def c(listener)
end

def rb(listener)
require "gherkin/rb_lexer/#{underscored_iso_code}"
RbLexer.const_get(underscored_iso_code.capitalize).new(listener)
require "gherkin/lexer/#{underscored_iso_code}"
Lexer.const_get(underscored_iso_code.capitalize).new(listener)
end

def underscored_iso_code
Expand Down
46 changes: 46 additions & 0 deletions lib/gherkin/lexer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ar.rb
bg.rb
bm.rb
ca.rb
cs.rb
cy_gb.rb
da.rb
de.rb
en.rb
en_au.rb
en_lol.rb
en_pirate.rb
en_scouse.rb
en_tx.rb
eo.rb
es.rb
et.rb
fi.rb
fr.rb
he.rb
hr.rb
hu.rb
id.rb
is.rb
it.rb
ja.rb
ko.rb
lt.rb
lu.rb
lv.rb
nl.rb
no.rb
pl.rb
pt.rb
ro.rb
ru.rb
sk.rb
sr_cyrl.rb
sr_latn.rb
sv.rb
tr.rb
uk.rb
uz.rb
vi.rb
zh_cn.rb
zh_tw.rb
2 changes: 1 addition & 1 deletion lib/gherkin/native/therubyracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self
def new(*args)
js = {
'Gherkin::Formatter::JSONFormatter' => 'js/lib/gherkin/formatter/json_formatter.js',
'Gherkin::RbLexer::En' => 'js/lib/gherkin/lexer/en.js'
'Gherkin::Lexer::En' => 'js/lib/gherkin/lexer/en.js'
}[self.name]
if(js)
Proxy.new(js, *args)
Expand Down
1 change: 0 additions & 1 deletion lib/gherkin/rb_lexer/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions lib/gherkin/rb_lexer/README.rdoc

This file was deleted.

6 changes: 3 additions & 3 deletions ragel/lexer.java.rl.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gherkin.lexer.i18n;
package gherkin.lexer;

import java.io.UnsupportedEncodingException;
import java.util.List;
Expand All @@ -8,7 +8,7 @@ import gherkin.lexer.Lexer;
import gherkin.lexer.Listener;
import gherkin.lexer.LexingError;

public class <%= @i18n.underscored_iso_code.upcase %> implements Lexer {
public class <%= @i18n.underscored_iso_code.capitalize %> implements Lexer {
%%{
machine lexer;
alphtype byte;
Expand Down Expand Up @@ -151,7 +151,7 @@ public class <%= @i18n.underscored_iso_code.upcase %> implements Lexer {

private final Listener listener;

public <%= @i18n.underscored_iso_code.upcase %>(Listener listener) {
public <%= @i18n.underscored_iso_code.capitalize %>(Listener listener) {
this.listener = listener;
}

Expand Down
2 changes: 1 addition & 1 deletion ragel/lexer.rb.rl.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'gherkin/native'

module Gherkin
module RbLexer
module Lexer
class <%= @i18n.underscored_iso_code.capitalize %> #:nodoc:
native_impl('gherkin')

Expand Down
4 changes: 2 additions & 2 deletions spec/gherkin/rb_lexer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#encoding: utf-8
require 'spec_helper'
require 'gherkin/rb_lexer/en'
require 'gherkin/lexer/en'

module Gherkin
module Lexer
describe "Ruby Lexer" do
before do
@listener = Gherkin::SexpRecorder.new
@lexer = Gherkin::RbLexer::En.new(@listener)
@lexer = Gherkin::Lexer::En.new(@listener)
end

it_should_behave_like "a Gherkin lexer"
Expand Down
4 changes: 0 additions & 4 deletions tasks/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ CLEAN.include [
'pkg', 'tmp',
'**/*.{o,bundle,jar,so,obj,pdb,lib,def,exp,log,rbc}', 'ext',
'java/target',
'ragel/i18n/*.rl',
'lib/gherkin/rb_lexer/*.rb',
'lib/*.dll',
'ext/**/*.c',
'java/src/main/java/gherkin/lexer/i18n/*.java',
'java/src/main/resources/gherkin/*.properties',
'js/lib/gherkin/lexer/*.js',
'doc'
]

Expand Down
16 changes: 13 additions & 3 deletions tasks/ragel_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def define_tasks
deps = [lang_ragel, common_ragel]
deps.unshift(UGLIFYJS) if(@lang == 'js')

min_target = target.gsub(/\.js$/, '.min.js')
file target => deps do
mkdir_p(File.dirname(target)) unless File.directory?(File.dirname(target))
sh "ragel #{flags} #{lang_ragel} -o #{target}"
Expand All @@ -32,10 +33,15 @@ def define_tasks
sh %{#{sed} 's/ESCAPED_TRIPLE_QUOTE/\\\\\\\\\\\\"\\\\\\\\\\\\"\\\\\\\\\\\\"/' #{target}}

# Minify
sh %{node #{UGLIFYJS} #{target} > #{target.gsub(/\.js$/, '.min.js')}}
sh %{node #{UGLIFYJS} #{target} > #{min_target}}
end
end

CLEAN.include(target)
if(@lang == 'js')
CLEAN.include(min_target)
end

file UGLIFYJS do
unless File.exist?(UGLIFYJS)
Dir.chdir('js') do
Expand All @@ -47,17 +53,21 @@ def define_tasks
file lang_ragel => lang_erb do
write(ERB.new(IO.read(lang_erb)).result(binding), lang_ragel)
end

CLEAN.include(lang_ragel)

file common_ragel => common_erb do
write(ERB.new(IO.read(common_erb)).result(binding), common_ragel)
end

CLEAN.include(common_ragel)
end

def target
{
'c' => "ext/gherkin_lexer_#{@i18n.underscored_iso_code}/gherkin_lexer_#{@i18n.underscored_iso_code}.c",
'java' => "java/src/main/java/gherkin/lexer/i18n/#{@i18n.underscored_iso_code.upcase}.java",
'rb' => "lib/gherkin/rb_lexer/#{@i18n.underscored_iso_code}.rb",
'java' => "java/src/main/java/gherkin/lexer/#{@i18n.underscored_iso_code.capitalize}.java",
'rb' => "lib/gherkin/lexer/#{@i18n.underscored_iso_code}.rb",
'js' => "js/lib/gherkin/lexer/#{@i18n.underscored_iso_code}.js"
}[@lang]
end
Expand Down

0 comments on commit 9d01754

Please sign in to comment.