Make most of Pigeon::Lexer methods and attrs private
This commit is contained in:
parent
866bd9d2d0
commit
a699607c6d
|
@ -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] 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] 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] 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.
|
- [ ] 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.
|
- [ ] Make CLI names consistent with API names. Eg: find vs. read.
|
||||||
- [ ] Add Lipmaa links like the Bamboo folks do.
|
- [ ] Add Lipmaa links like the Bamboo folks do.
|
||||||
- [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes.
|
- [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes.
|
||||||
|
|
|
@ -1,5 +1,26 @@
|
||||||
module Pigeon
|
module Pigeon
|
||||||
class Lexer
|
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
|
attr_reader :bundle_string, :scanner, :tokens
|
||||||
# TODO: Change all the `{40,90}` values in ::Lexer to real values
|
# TODO: Change all the `{40,90}` values in ::Lexer to real values
|
||||||
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
|
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
|
||||||
|
@ -37,27 +58,6 @@ module Pigeon
|
||||||
new(bundle_string).tokenize
|
new(bundle_string).tokenize
|
||||||
end
|
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)
|
def flunk!(why)
|
||||||
raise LexError, "Syntax error at #{scanner.pos}. #{why}"
|
raise LexError, "Syntax error at #{scanner.pos}. #{why}"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue