update (failing) tests. Add better lex error messages

This commit is contained in:
Netscape Navigator 2020-04-01 08:25:27 -05:00
parent 94009bc725
commit 1c1caae42b
3 changed files with 9 additions and 9 deletions

View File

@ -13,7 +13,7 @@ module Pigeon
File.write(file_path, content + CR)
end
def self.ingest(file_path)
def self.ingest(file_path = DEFAULT_BUNDLE_PATH)
bundle = File.read(file_path)
tokens = Pigeon::Lexer.tokenize(bundle)
Pigeon::Parser.parse(tokens).map(&:save!)

13
dist/pigeon/lexer.rb vendored
View File

@ -3,12 +3,12 @@ module Pigeon
attr_reader :bundle_string, :scanner, :tokens
# TODO: Change all the `{40,90}` values in ::Lexer to real values
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
FEED_VALUE = /@.{40,90}.ed25519/
FEED_VALUE = /@.{43,45}.ed25519/
DEPTH_COUNT = /\d{1,7}/
MESG_VALUE = /%.{40,90}.sha256/
BLOB_VALUE = /&.{40,90}.sha256/
NULL_VALUE = /NONE/
STRG_VALUE = /\".{1,64}\"/
STRG_VALUE = /".{1,64}"/
ALPHANUMERICISH = /[a-zA-Z\d\._]{1,64}/
ALL_VALUES = [
FEED_VALUE,
@ -57,8 +57,8 @@ module Pigeon
@state = HEADER
end
def flunk!
raise LexError, "Syntax error at #{scanner.pos}"
def flunk!(why)
raise LexError, "Syntax error at #{scanner.pos}. #{why}"
end
# This might be a mistake or uneccessary. NN 20 MAR 2020
@ -98,7 +98,8 @@ module Pigeon
@tokens << [:HEADER_END]
return
end
flunk!
flunk!("Failed to read header field.")
end
def do_body
@ -114,7 +115,7 @@ module Pigeon
return
end
flunk!
flunk!("Failed to read body field.")
end
def do_footer

View File

@ -34,7 +34,6 @@ RSpec.describe Pigeon::Message do
Pigeon::LocalIdentity.instance_variable_set(:@current, ident)
create_fake_messages
Pigeon::Bundle.create
actual_bundle = File.read(Pigeon::DEFAULT_BUNDLE_PATH)
binding.pry
Pigeon::Bundle.ingest
end
end