Class: Parser::Base
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- Parser::Base
- Defined in:
- lib/parser/base.rb
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#source_buffer ⇒ Object
readonly
The source file currently being parsed.
-
#static_env ⇒ Object
readonly
Returns the value of attribute static_env.
Class Method Summary collapse
Instance Method Summary collapse
- #in_def? ⇒ Boolean
-
#initialize(builder = Parser::Builders::Default.new) ⇒ Base
constructor
A new instance of Base.
- #parse(source_buffer) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(builder = Parser::Builders::Default.new) ⇒ Base
Returns a new instance of Base.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/parser/base.rb', line 31 def initialize(builder=Parser::Builders::Default.new) @diagnostics = Diagnostic::Engine.new @static_env = StaticEnvironment.new @comments = [] @lexer = Lexer.new(version) @lexer.diagnostics = @diagnostics @lexer.static_env = @static_env @builder = builder @builder.parser = self if self.class::Racc_debug_parser && ENV['RACC_DEBUG'] @yydebug = true end reset end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
25 26 27 |
# File 'lib/parser/base.rb', line 25 def diagnostics @diagnostics end |
#source_buffer ⇒ Object (readonly)
The source file currently being parsed.
29 30 31 |
# File 'lib/parser/base.rb', line 29 def source_buffer @source_buffer end |
#static_env ⇒ Object (readonly)
Returns the value of attribute static_env.
26 27 28 |
# File 'lib/parser/base.rb', line 26 def static_env @static_env end |
Class Method Details
.parse(string, file = '(string)', line = 1) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/parser/base.rb', line 4 def self.parse(string, file='(string)', line=1) parser = new parser.diagnostics.all_errors_are_fatal = true parser.diagnostics.ignore_warnings = true # Temporary, for manual testing convenience parser.diagnostics.consumer = lambda do |diagnostic| $stderr.puts(diagnostic.render) end source_buffer = Source::Buffer.new(file, line) source_buffer.source = string parser.parse(source_buffer) end |
.parse_file(filename) ⇒ Object
21 22 23 |
# File 'lib/parser/base.rb', line 21 def self.parse_file(filename) parse(File.read(filename), filename) end |
Instance Method Details
#in_def? ⇒ Boolean
73 74 75 |
# File 'lib/parser/base.rb', line 73 def in_def? @def_level > 0 end |
#parse(source_buffer) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/parser/base.rb', line 62 def parse(source_buffer) @source_buffer = source_buffer @lexer.source_buffer = source_buffer do_parse ensure # Don't keep references to the source file. @source_buffer = nil @lexer.source_buffer = nil end |
#reset ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/parser/base.rb', line 52 def reset @source_buffer = nil @def_level = 0 # count of nested def's. @lexer.reset @static_env.reset self end |