tomlrb 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,32 +2,42 @@ require 'strscan'
2
2
 
3
3
  module Tomlrb
4
4
  class Scanner
5
- COMMENT = /#.*/
5
+ COMMENT = /#[^\u0000-\u0008\u000A-\u001F\u007F]*/
6
6
  IDENTIFIER = /[A-Za-z0-9_-]+/
7
- SPACE = /[ \t\r\n]/
8
- STRING_BASIC = /(["])(?:\\?.)*?\1/
9
- STRING_MULTI = /"{3}([\s\S]*?"{3,4})/m
10
- STRING_LITERAL = /(['])(?:\\?.)*?\1/
11
- STRING_LITERAL_MULTI = /'{3}([\s\S]*?'{3})/m
12
- DATETIME = /(-?\d{4})-(\d{2})-(\d{2})(?:(?:t|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?))?(z|[-+]\d{2}:\d{2})?/i
13
- FLOAT = /[+-]?(?:[0-9_]+\.[0-9_]*|\d+(?=[eE]))(?:[eE][+-]?[0-9_]+)?/
14
- FLOAT_INF = /[+-]?inf/
15
- FLOAT_NAN = /[+-]?nan/
7
+ SPACE = /[ \t]/
8
+ NEWLINE = /(\r?\n)/
9
+ STRING_BASIC = /(["])(?:\\?[^\u0000-\u0008\u000A-\u001F\u007F])*?\1/
10
+ STRING_MULTI = /"{3}([^\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]*?(?<!\\)"{3,5})/m
11
+ STRING_LITERAL = /(['])(?:\\?[^\u0000-\u0008\u000A-\u001F\u007F])*?\1/
12
+ STRING_LITERAL_MULTI = /'{3}([^\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]*?'{3,5})/m
13
+ DATETIME = /(-?\d{4})-(\d{2})-(\d{2})(?:(?:t|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?))?(z|[-+]\d{2}:\d{2})/i
14
+ LOCAL_DATETIME = /(-?\d{4})-(\d{2})-(\d{2})(?:t|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/i
15
+ LOCAL_DATE = /(-?\d{4})-(\d{2})-(\d{2})/
16
+ LOCAL_TIME = /(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/
17
+ FLOAT = /[+-]?(?:(?:\d|[1-9](?:_?\d)*)\.\d(?:_?\d)*|\d+(?=[eE]))(?:[eE][+-]?[0-9_]+)?(?!\w)/
18
+ FLOAT_INF = /[+-]?inf\b/
19
+ FLOAT_NAN = /[+-]?nan\b/
16
20
  INTEGER = /[+-]?([1-9](_?\d)*|0)(?![A-Za-z0-9_-]+)/
21
+ HEX_INTEGER = /0x[0-9A-Fa-f][0-9A-Fa-f_]*/
22
+ OCT_INTEGER = /0o[0-7][0-7_]*/
23
+ BIN_INTEGER = /0b[01][01_]*/
17
24
  TRUE = /true/
18
25
  FALSE = /false/
19
26
 
20
27
  def initialize(io)
21
28
  @ss = StringScanner.new(io.read)
29
+ @eos = false
22
30
  end
23
31
 
24
32
  def next_token
25
- return if @ss.eos?
26
-
27
33
  case
34
+ when @ss.eos? then process_eos
28
35
  when @ss.scan(SPACE) then next_token
29
36
  when @ss.scan(COMMENT) then next_token
30
37
  when @ss.scan(DATETIME) then process_datetime
38
+ when @ss.scan(LOCAL_DATETIME) then process_local_datetime
39
+ when @ss.scan(LOCAL_DATE) then process_local_date
40
+ when @ss.scan(LOCAL_TIME) then process_local_time
31
41
  when text = @ss.scan(STRING_MULTI) then [:STRING_MULTI, text[3..-4]]
32
42
  when text = @ss.scan(STRING_BASIC) then [:STRING_BASIC, text[1..-2]]
33
43
  when text = @ss.scan(STRING_LITERAL_MULTI) then [:STRING_LITERAL_MULTI, text[3..-4]]
@@ -36,12 +46,14 @@ module Tomlrb
36
46
  when text = @ss.scan(FLOAT_INF) then [:FLOAT_INF, text]
37
47
  when text = @ss.scan(FLOAT_NAN) then [:FLOAT_NAN, text]
38
48
  when text = @ss.scan(INTEGER) then [:INTEGER, text]
49
+ when text = @ss.scan(HEX_INTEGER) then [:HEX_INTEGER, text]
50
+ when text = @ss.scan(OCT_INTEGER) then [:OCT_INTEGER, text]
51
+ when text = @ss.scan(BIN_INTEGER) then [:BIN_INTEGER, text]
39
52
  when text = @ss.scan(TRUE) then [:TRUE, text]
40
53
  when text = @ss.scan(FALSE) then [:FALSE, text]
54
+ when text = @ss.scan(NEWLINE) then [:NEWLINE, text]
41
55
  when text = @ss.scan(IDENTIFIER) then [:IDENTIFIER, text]
42
- else
43
- x = @ss.getch
44
- [x, x]
56
+ else x = @ss.getch; [x, x]
45
57
  end
46
58
  end
47
59
 
@@ -54,5 +66,27 @@ module Tomlrb
54
66
  args = [@ss[1], @ss[2], @ss[3], @ss[4] || 0, @ss[5] || 0, @ss[6].to_f, offset]
55
67
  [:DATETIME, args]
56
68
  end
69
+
70
+ def process_local_datetime
71
+ args = [@ss[1], @ss[2], @ss[3], @ss[4] || 0, @ss[5] || 0, @ss[6].to_f]
72
+ [:LOCAL_DATETIME, args]
73
+ end
74
+
75
+ def process_local_date
76
+ args = [@ss[1], @ss[2], @ss[3]]
77
+ [:LOCAL_DATE, args]
78
+ end
79
+
80
+ def process_local_time
81
+ args = [@ss[1], @ss[2], @ss[3].to_f]
82
+ [:LOCAL_TIME, args]
83
+ end
84
+
85
+ def process_eos
86
+ return if @eos
87
+
88
+ @eos = true
89
+ [:EOS, nil]
90
+ end
57
91
  end
58
92
  end
@@ -12,7 +12,13 @@ module Tomlrb
12
12
  }.freeze
13
13
 
14
14
  def self.multiline_replacements(str)
15
- strip_spaces(str).gsub(/\\\n\s+/, '')
15
+ strip_spaces(str).gsub(/\\+\s*\n\s*/) {|matched|
16
+ if matched.match(/\\+/)[0].length.odd?
17
+ matched.gsub(/\\\s*\n\s*/, '')
18
+ else
19
+ matched
20
+ end
21
+ }
16
22
  end
17
23
 
18
24
  def self.replace_escaped_chars(str)
@@ -1,3 +1,3 @@
1
1
  module Tomlrb
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomlrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Bernier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A racc based toml parser
14
14
  email:
@@ -21,6 +21,9 @@ files:
21
21
  - lib/tomlrb.rb
22
22
  - lib/tomlrb/generated_parser.rb
23
23
  - lib/tomlrb/handler.rb
24
+ - lib/tomlrb/local_date.rb
25
+ - lib/tomlrb/local_date_time.rb
26
+ - lib/tomlrb/local_time.rb
24
27
  - lib/tomlrb/parser.rb
25
28
  - lib/tomlrb/parser.y
26
29
  - lib/tomlrb/scanner.rb
@@ -45,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
48
  - !ruby/object:Gem::Version
46
49
  version: '0'
47
50
  requirements: []
48
- rubygems_version: 3.0.6
51
+ rubygems_version: 3.1.4
49
52
  signing_key:
50
53
  specification_version: 4
51
54
  summary: A racc based toml parser