diff --git a/README.md b/README.md index 4b888a4..33e7355 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`. - [X] Rename `message find` to `message read`, since other finders return a multihash. - [X] Message.ingest should be the only code path to message authoring. - [X] Don't allow any type of whitespace in `kind` or `string` keys. Write a test for this. + - [X] Run Flog / Flay and friends to find duplications. Will aid in port to other languages. - [ ] Make all methods private except those required for the CLI. - - [ ] Run Flog / Flay and friends to find duplications. Will aid in port to other languages. - [ ] Make CLI names consistent with API names. Eg: find vs. read. - [ ] Add Lipmaa links like the Bamboo folks do. - [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes. diff --git a/dist/pigeon/lexer.rb b/dist/pigeon/lexer.rb index 2185651..435d06f 100644 --- a/dist/pigeon/lexer.rb +++ b/dist/pigeon/lexer.rb @@ -1,5 +1,26 @@ module Pigeon class Lexer + def initialize(bundle_string) + @bundle_string = bundle_string + @scanner = StringScanner.new(bundle_string) + @tokens = [] + @state = HEADER + end + + def tokenize + until scanner.eos? + case @state + when HEADER then do_header + when BODY then do_body + when FOOTER then do_footer + end + end + maybe_end_message! + return tokens + end + + private + 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. @@ -37,27 +58,6 @@ module Pigeon new(bundle_string).tokenize end - def tokenize - until scanner.eos? - case @state - when HEADER then do_header - when BODY then do_body - when FOOTER then do_footer - end - end - maybe_end_message! - return tokens - end - - private - - def initialize(bundle_string) - @bundle_string = bundle_string - @scanner = StringScanner.new(bundle_string) - @tokens = [] - @state = HEADER - end - def flunk!(why) raise LexError, "Syntax error at #{scanner.pos}. #{why}" end