Class: OrigenSTIL::Syntax::Parser
- Inherits:
-
Object
- Object
- OrigenSTIL::Syntax::Parser
- Defined in:
- lib/origen_stil/syntax/parser.rb
Class Method Summary collapse
- .file ⇒ Object
- .last_error_msg ⇒ Object
- .parse(data, options = {}) ⇒ Object
- .parse_file(path, options = {}) ⇒ Object
- .parser ⇒ Object
Class Method Details
.file ⇒ Object
48 49 50 |
# File 'lib/origen_stil/syntax/parser.rb', line 48 def self.file @file end |
.last_error_msg ⇒ Object
44 45 46 |
# File 'lib/origen_stil/syntax/parser.rb', line 44 def self.last_error_msg @last_error_msg || [] end |
.parse(data, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/origen_stil/syntax/parser.rb', line 18 def self.parse(data, = {}) @file = [:file] tree = parser.parse(data) # If the AST is nil then there was an error during parsing, # we need to report a simple error message to help the user if tree.nil? && ![:quiet] parser.failure_reason =~ /^(Expected .+) (after|at)/m @last_error_msg = [] @last_error_msg << "#{Regexp.last_match(1).gsub("\n", '$NEWLINE')}:" if Regexp.last_match(1) if parser.failure_line >= data.lines.to_a.size @last_error_msg << 'EOF' else @last_error_msg << data.lines.to_a[parser.failure_line - 1].gsub("\t", ' ') end @last_error_msg << "#{'~' * (parser.failure_column - 1)}^" Origen.log.error "Failed parsing STIL file: #{file}" @last_error_msg.each do |line| Origen.log.error line.rstrip end end if tree tree.to_ast end end |
.parse_file(path, options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/origen_stil/syntax/parser.rb', line 13 def self.parse_file(path, = {}) stil = OrigenSTIL::Pattern.new(path) parse(stil.frontmatter, .merge(file: stil.path)) end |
.parser ⇒ Object
6 7 8 9 10 11 |
# File 'lib/origen_stil/syntax/parser.rb', line 6 def self.parser @parser ||= begin require "#{Origen.root!}/grammars/stil" GrammarParser.new end end |