0
我正在嘗試學習與Treetop PEG語法分析器一起工作,但我從一開始就感到奇怪的錯誤。Ruby&Treetop - 沒有這樣的文件或目錄@ rb_sysopen
我有文件的
node_extensions.rb parser.rb tranlan.treetop
和內容是以下這個文件結構(列表是上面列出文件的順序)
node_extensions.rb
# node_extensions.rb
module TranLan
end
parser.rb
# parser.rb
require 'treetop'
# Find out what our base path is
base_path = File.expand_path(File.dirname(__FILE__))
# Load our custom syntax node classes so the parser can use them
require File.join(base_path, 'node_extensions.rb')
class Parser
base_path = File.expand_path(File.dirname(__FILE__))
Treetop.load(File.join(base_path, 'tranlan_parser.treetop'))
@@parser = SexpParser.new
def self.parse(data)
tree = @@parser.parse(data)
raise Exception, "Parser error at offset: #{@@parser.index}" if tree.nil?
tree
end
end
tranlan.treetop
# tranlan.treetop
grammar TranLan
end
當我運行parser.rb,我得到這個錯誤
/Users/maca/.rvm/gems/ruby-2.1.4/gems/treetop-1.5.3/lib/treetop/compiler/grammar_compiler.rb:37:in `initialize': No such file or directory @ rb_sysopen - /Users/maca/devel/playground/treetop-grammar/tranlan_parser.treetop (Errno::ENOENT)
from /Users/maca/.rvm/gems/ruby-2.1.4/gems/treetop-1.5.3/lib/treetop/compiler/grammar_compiler.rb:37:in `open'
from /Users/maca/.rvm/gems/ruby-2.1.4/gems/treetop-1.5.3/lib/treetop/compiler/grammar_compiler.rb:37:in `load'
from parser.rb:17:in `<class:Parser>'
from parser.rb:10:in `<main>'
有什麼不對?任何幫助?
您已創建tranlan.treetop,但您正在加載tranlan_parser.treetop –
嘿,你是對的。我是一個白癡。謝謝!!! –
@FrederickCheung,請定期回答,以便我可以將其標記爲正確答案。非常感謝。 –