Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the tokenizer with a flex-based scanner #3846

Merged
merged 17 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ lib/linguist/samples.json
/node_modules
test/fixtures/ace_modes.json
/vendor/gems/
/tmp
*.bundle
*.so
23 changes: 21 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'bundler/setup'
require 'rake/clean'
require 'rake/testtask'
require 'rake/extensiontask'
require 'yaml'
require 'yajl'
require 'open-uri'
Expand All @@ -10,8 +11,14 @@ task :default => :test

Rake::TestTask.new

gem_spec = Gem::Specification.load('github-linguist.gemspec')

Rake::ExtensionTask.new('linguist', gem_spec) do |ext|
ext.lib_dir = File.join('lib', 'linguist')
end

# Extend test task to check for samples and fetch latest Ace modes
task :test => [:check_samples, :fetch_ace_modes]
task :test => [:compile, :check_samples, :fetch_ace_modes]

desc "Check that we have samples.json generated"
task :check_samples do
Expand All @@ -34,12 +41,24 @@ task :fetch_ace_modes do
end
end

task :samples do
task :samples => :compile do
require 'linguist/samples'
json = Yajl.dump(Linguist::Samples.data, :pretty => true)
File.write 'lib/linguist/samples.json', json
end

FLEX_MIN_VER = [2, 5, 39]
task :flex do
if `flex -V` !~ /^flex (\d+)\.(\d+)\.(\d+)/
fail "flex not detected"
end
maj, min, rev = $1.to_i, $2.to_i, $3.to_i
if maj < FLEX_MIN_VER[0] || (maj == FLEX_MIN_VER[0] && (min < FLEX_MIN_VER[1] || (min == FLEX_MIN_VER[1] && rev < FLEX_MIN_VER[2])))
fail "building linguist's lexer requires at least flex #{FLEX_MIN_VER.join(".")}"
end
system "cd ext/linguist && flex tokenizer.l"
end

task :build_gem => :samples do
rm_rf "grammars"
sh "script/convert-grammars"
Expand Down
3 changes: 3 additions & 0 deletions ext/linguist/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'mkmf'
dir_config('linguist')
create_makefile('linguist/linguist')
Loading