frausto 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/faust2ruby.rb ADDED
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "faust2ruby/version"
4
+ require_relative "faust2ruby/lexer"
5
+ require_relative "faust2ruby/ast"
6
+ require_relative "faust2ruby/parser"
7
+ require_relative "faust2ruby/library_mapper"
8
+ require_relative "faust2ruby/ir_builder"
9
+ require_relative "faust2ruby/ruby_generator"
10
+
11
+ module Faust2Ruby
12
+ class Error < StandardError; end
13
+ class ParseError < Error; end
14
+
15
+ # Convert Faust source code to Ruby DSL code.
16
+ #
17
+ # @param source [String] Faust DSP source code
18
+ # @param options [Hash] Conversion options
19
+ # @option options [Boolean] :expression_only Output only the process expression
20
+ # @option options [Integer] :indent Indentation level (default: 2)
21
+ # @return [String] Ruby DSL code
22
+ #
23
+ # @example
24
+ # faust_code = 'process = os.osc(440) : *(0.5);'
25
+ # ruby_code = Faust2Ruby.to_ruby(faust_code)
26
+ # # => "osc(440) >> gain(0.5)"
27
+ #
28
+ def self.to_ruby(source, **options)
29
+ parser = Parser.new(source)
30
+ program = parser.parse
31
+
32
+ unless parser.errors.empty?
33
+ raise ParseError, "Parse errors:\n#{parser.errors.join("\n")}"
34
+ end
35
+
36
+ generator = RubyGenerator.new(options)
37
+ generator.generate(program)
38
+ end
39
+
40
+ # Parse Faust source and return the AST.
41
+ #
42
+ # @param source [String] Faust DSP source code
43
+ # @return [AST::Program] Parsed program
44
+ #
45
+ def self.parse(source)
46
+ parser = Parser.new(source)
47
+ program = parser.parse
48
+
49
+ unless parser.errors.empty?
50
+ raise ParseError, "Parse errors:\n#{parser.errors.join("\n")}"
51
+ end
52
+
53
+ program
54
+ end
55
+
56
+ # Tokenize Faust source and return tokens.
57
+ #
58
+ # @param source [String] Faust DSP source code
59
+ # @return [Array<Lexer::Token>] Token array
60
+ #
61
+ def self.tokenize(source)
62
+ lexer = Lexer.new(source)
63
+ lexer.tokenize
64
+ end
65
+
66
+ # Convert Faust file to Ruby DSL.
67
+ #
68
+ # @param input_path [String] Path to Faust .dsp file
69
+ # @param output_path [String, nil] Output path (nil for stdout)
70
+ # @param options [Hash] Conversion options
71
+ #
72
+ def self.convert_file(input_path, output_path = nil, **options)
73
+ source = File.read(input_path)
74
+ ruby_code = to_ruby(source, **options)
75
+
76
+ if output_path
77
+ File.write(output_path, ruby_code)
78
+ else
79
+ ruby_code
80
+ end
81
+ end
82
+ end
data/lib/frausto.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby2faust"
4
+ require_relative "faust2ruby"
5
+
6
+ module Frausto
7
+ VERSION = Ruby2Faust::VERSION
8
+ end