Class: EPUB::CFI::Parser

Inherits:
Racc::Parser
  • Object
show all
Includes:
Comparable
Defined in:
lib/epub/cfi/parser.rb,
lib/epub/cfi/parser.tab.rb

Constant Summary collapse

UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK_PATTERN =

excluding special chars and space(\u0020) and dot(\u002E) and colon(\u003A) and tilde(\u007E) and atmark(\u0040) and solidus(\u002F) and exclamation mark(\u0021)

/\u0009|\u000A|\u000D|[\u0022-\u0027]|[\u002A-\u002B]|\u002D|[\u0030-\u0039]|\u003C|[\u003E-\u0040]|[\u0041-\u005A]|\u005C|[\u005F-\u007D]|[\u007F-\uD7FF]|[\uE000-\uFFFD]|[\u10000-\u10FFFF]/
FRAGMENT_PREFIX =
"epubcfi("
FRAGMENT_PREFIX_LENGTH =
FRAGMENT_PREFIX.length
FRAGMENT_SUFFIX_LENGTH =
")".length
Racc_arg =
[
racc_action_table,
racc_action_check,
racc_action_default,
racc_action_pointer,
racc_goto_table,
racc_goto_check,
racc_goto_default,
racc_goto_pointer,
racc_nt_base,
racc_reduce_table,
racc_token_table,
racc_shift_n,
racc_reduce_n,
racc_use_result_var ]
Racc_token_to_s_table =
[
"$end",
"error",
"COMMA",
"EXCLAMATION_MARK",
"SOLIDUS",
"COLON",
"TILDE",
"ATMARK",
"DIGIT_NON_ZERO",
"ZERO",
"DOT",
"SEMICOLON",
"EQUAL",
"CIRCUMFLEX",
"OPENING_SQUARE_BRACKET",
"CLOSING_SQUARE_BRACKET",
"OPENING_PARENTHESIS",
"CLOSING_PARENTHESIS",
"SPACE",
"UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK",
"$start",
"fragment",
"path",
"range_zero_or_one",
"range",
"step",
"local_path",
"step_zero_or_more",
"redirected_path",
"offset_zero_or_one",
"offset",
"integer",
"assertion_part_zero_or_one",
"spatial_offset",
"number",
"spatial_offset_zero_or_one",
"opening_square_bracket",
"assertion",
"closing_square_bracket",
"digit_zero_or_more",
"fractional_portion_zero_or_one",
"fractional_portion",
"digit",
"value_csv_one_or_two",
"parameter_zero_or_more",
"value",
"parameter",
"value_no_space",
"csv",
"string_escaped_special_chars",
"string_escaped_special_chars_excluding_space",
"escaped_special_chars",
"square_brackets",
"parentheses",
"character_escaped_special",
"character_excluding_special_chars",
"character_escaped_special_excluding_space",
"character_excluding_special_chars_and_space",
"character_excluding_special_chars_and_space_and_dot_and_colon_and_tilde_and_atmark_and_solidus_and_exclamation_mark" ]
Racc_debug_parser =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug: $DEBUG) ⇒ Parser

Returns a new instance of Parser.



18
19
20
21
# File 'lib/epub/cfi/parser.rb', line 18

def initialize(debug: $DEBUG)
  @yydebug = debug
  super()
end

Class Method Details

.parse(string, debug: $DEBUG) ⇒ Object



13
14
15
# File 'lib/epub/cfi/parser.rb', line 13

def parse(string, debug: $DEBUG)
  new(debug: debug).parse(string)
end

Instance Method Details

#_reduce_none(val, _values, result) ⇒ Object

reduce 80 omitted



694
695
696
# File 'lib/epub/cfi/parser.tab.rb', line 694

def _reduce_none(val, _values, result)
  val[0]
end

#next_tokenObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/epub/cfi/parser.rb', line 32

def next_token
  return [false, false] if @scanner.eos?

  case
  when @scanner.scan(/[1-9]/)
    [:DIGIT_NON_ZERO, @scanner[0]]
  when @scanner.scan(/0/)
    [:ZERO, @scanner[0]]
  when @scanner.scan(/ /)
    [:SPACE, @scanner[0]]
  when @scanner.scan(/\^/)
    [:CIRCUMFLEX, @scanner[0]]
  when @scanner.scan(/\[/)
    [:OPENING_SQUARE_BRACKET, @scanner[0]]
  when @scanner.scan(/\]/)
    [:CLOSING_SQUARE_BRACKET, @scanner[0]]
  when @scanner.scan(/\(/)
    [:OPENING_PARENTHESIS, @scanner[0]]
  when @scanner.scan(/\)/)
    [:CLOSING_PARENTHESIS, @scanner[0]]
  when @scanner.scan(/,/)
    [:COMMA, @scanner[0]]
  when @scanner.scan(/;/)
    [:SEMICOLON, @scanner[0]]
  when @scanner.scan(/=/)
    [:EQUAL, @scanner[0]]
  when @scanner.scan(/\./)
    [:DOT, @scanner[0]]
  when @scanner.scan(/:/)
    [:COLON, @scanner[0]]
  when @scanner.scan(/~/)
    [:TILDE, @scanner[0]]
  when @scanner.scan(/@/)
    [:ATMARK, @scanner[0]]
  when @scanner.scan(/\//)
    [:SOLIDUS, @scanner[0]]
  when @scanner.scan(/!/)
    [:EXCLAMATION_MARK, @scanner[0]]
  when @scanner.scan(UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK_PATTERN)
    [:UNICODE_CHARACTER_EXCLUDING_SPECIAL_CHARS_AND_SPACE_AND_DOT_AND_COLON_AND_TILDE_AND_ATMARK_AND_SOLIDUS_AND_EXCLAMATION_MARK, @scanner[0]]
  else
    raise 'unexpected character'
  end
end

#parse(string) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/epub/cfi/parser.rb', line 23

def parse(string)
  if string.start_with? FRAGMENT_PREFIX
    string = string[FRAGMENT_PREFIX_LENGTH .. -(FRAGMENT_SUFFIX_LENGTH + 1)]
    # @type var string: String
  end
  @scanner = StringScanner.new(string, true)
  do_parse
end