Class: Flexr::Generator
- Inherits:
-
Object
- Object
- Flexr::Generator
- Defined in:
- lib/flexr/generator.rb
Constant Summary collapse
- INLINE_EMIT =
/\Aemit(?:\s+(.+?))?\z/- INLINE_EMIT_ARGUMENTS =
/\A(?::[A-Za-z_]\w*|true|false|nil|-?\d+(?:\.\d+)?|"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|text(?:\.(?:to_f|to_i|bytesize|byteslice\([^()\n]+\)))?|lineno|line)(?:\s*,\s*(?::[A-Za-z_]\w*|true|false|nil|-?\d+(?:\.\d+)?|"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|text(?:\.(?:to_f|to_i|bytesize|byteslice\([^()\n]+\)))?|lineno|line))*\z/- RUNTIME_SOURCES =
%w[ version.rb errors.rb diagnostics.rb action_resolver.rb configuration.rb ir.rb unicode/version.rb automaton/types.rb automaton/dfa.rb automaton/analysis.rb automaton/accel.rb runtime/location.rb runtime/token.rb runtime/buffer.rb runtime/errors.rb runtime/interpreter.rb runtime/core.rb dsl.rb lexer.rb generated.rb ].freeze
- MATCHER_RUNTIME_SOURCES =
%w[ regexp/ast.rb regexp/parser.rb regexp/unsupported.rb unicode/utf8_splitter.rb unicode/data/properties.rb unicode/data/case_folding.rb unicode/property.rb unicode/reference_regexp.rb unicode/case_fold.rb ].freeze
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(path, output: nil, eval_mode: false, options: {}) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(path, output: nil, eval_mode: false, options: {}) ⇒ Generator
Returns a new instance of Generator.
29 30 31 32 33 34 35 |
# File 'lib/flexr/generator.rb', line 29 def initialize(path, output: nil, eval_mode: false, options: {}) @path = path @output = output @eval_mode = eval_mode @options = @diagnostics = [] end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
11 12 13 |
# File 'lib/flexr/generator.rb', line 11 def diagnostics @diagnostics end |
Instance Method Details
#generate ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/flexr/generator.rb', line 37 def generate ArtifactWriter.ensure_distinct!(@path, @output) if @output # Keep generated source stable when a checkout presents the spec with # Windows line endings. All offsets consumed by the parser and # passthrough writer are relative to this normalized source. source = File.binread(@path).gsub(/\r\n?/, "\n").force_encoding(Encoding::UTF_8) result = if @eval_mode generate_from_runtime(source) else parsed = Source::PrismReader.new(source, path: @path).read generate_static(parsed) end ArtifactWriter.write!(@output, result, source_path: @path) if @output result end |