Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Use .absent? in parser rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fpsvogel committed Mar 15, 2023
1 parent 64ebb5d commit 7f51f31
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/litter/parsing/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ def initialize(config)

rule(:newline) { str("\n") }
rule(:space) { match('\s').repeat(1) }
rule(:digit) { match('[0-9]') }
rule(:date_sep) { str(config.fetch(:date_sep)) }
rule(:loc_char) { str(config.fetch(:loc_char)) }
rule(:qty_char) { str(config.fetch(:qty_char)) }
rule(:tag_char) { str(config.fetch(:tag_char)) }
rule(:not_tag) { match( "[^\\n\\#{config.fetch(:tag_char)}]") }
rule(:not_tag) { newline.absent? >> tag_char.absent? >> any }
rule(:not_special) {
match("[^\\n\\#{config[:qty_char]}\\#{config[:loc_char]}\\#{config[:tag_char]}]")
newline.absent? >> qty_char.absent? >> loc_char.absent? >> tag_char.absent? >> any
}

rule(:year) { match('[0-9]').repeat(4,4) }
rule(:day_or_month) { match('[0-9]').repeat(1,2) }
rule(:year) { digit.repeat(4,4) }
rule(:day_or_month) { digit.repeat(1,2) }
rule(:date) { (year >> date_sep >> day_or_month >> date_sep >> day_or_month).as(:date) }

rule(:location) { space.maybe >> loc_char >> not_tag.repeat(1).as(:location)}
rule(:date_line) { date >> location.maybe >> newline }

rule(:name) { not_special.repeat(1).as(:name) }
rule(:quantity) { qty_char >> match('[0-9]').repeat(1).as(:quantity) }
rule(:quantity) { qty_char >> digit.repeat(1).as(:quantity) }
rule(:tag) { space.maybe >> tag_char >> match('[^\n]').repeat(1).as(:tag) }
rule(:item) { name >> quantity.maybe >> location.maybe >> tag.maybe }

Expand Down

0 comments on commit 7f51f31

Please sign in to comment.