Class: Flexr::Importer
- Inherits:
-
Object
- Object
- Flexr::Importer
- Defined in:
- lib/flexr/importer.rb
Defined Under Namespace
Classes: Result, UnsupportedFormatError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path, source) ⇒ Importer
constructor
A new instance of Importer.
- #run ⇒ Object
Constructor Details
#initialize(path, source) ⇒ Importer
Returns a new instance of Importer.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flexr/importer.rb', line 15 def initialize(path, source) @path = path @source = source.force_encoding(Encoding::UTF_8) @warnings = [] @complete = true @macros = {} @states = {} @rules = [] @eof_rules = [] @last_action = nil end |
Class Method Details
.import(path) ⇒ Object
11 12 13 |
# File 'lib/flexr/importer.rb', line 11 def self.import(path) new(path, File.binread(path)).run end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flexr/importer.rb', line 27 def run case File.extname(@path).downcase when ".l", ".lex" parse_flex when ".rex" parse_rexical else raise UnsupportedFormatError, "import expects a flex .l or rexical .rex file" end Result.new(source: render, warnings: @warnings.freeze, complete?: @complete) end |