Permalink
Browse files

Initial scanner generation with leex using Rake-based automation

  • Loading branch information...
Tony Arcieri
Tony Arcieri committed May 11, 2008
1 parent 6747ba4 commit 4f602239c2797de4900f3535f212c13ca769d3f9
Showing with 38 additions and 0 deletions.
  1. +19 −0 Rakefile
  2. +19 −0 src/reia/scanner.xrl
@@ -0,0 +1,19 @@
task :default => :build
task :build => %w[leex]

rule ".beam" => ".erl" do |t|
sh "erlc +nowarn_unused_vars -o #{File.dirname(t.name)} #{t.source}"
end

task :leex => %w[src/leex/leex.beam src/reia/scanner.erl]

file "src/leex/leex.beam" => "src/leex/leex.erl"
file "src/reia/scanner.erl" => %w[src/reia/scanner.xrl src/leex/leex.beam] do
sh "erl -eval 'leex:file(\"src/reia/scanner.xrl\")' -pa src/leex -noshell -s init stop"
end

task :clean do
rm_f 'src/leex/leex.beam'
rm_f 'src/reia/scanner.erl'
rm_rf 'ebin'
end
@@ -0,0 +1,19 @@
Definitions.

Digit = [0-9]
Whitespace = [\000-\s]

Rules.

(\+|\-)?{Digit}+\.{Digit}+ : build_float(TokenChars, TokenLine).
(\+|\-)?{Digit}+ : build_integer(TokenChars, TokenLine).

Erlang code.

-export([build_integer/2, build_float/2]).

build_integer(Chars, Line) ->
{token, {integer, Line, list_to_integer(Chars)}}.

build_float(Chars, Line) ->
{token, {float, Line, list_to_float(Chars)}}.

0 comments on commit 4f60223

Please sign in to comment.