minival_refi 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,11 @@
2
2
 
3
3
  require 'polyglot'
4
4
  require 'treetop'
5
+ require 'pp'
6
+ require 'string_extensions_refi'
5
7
 
6
- #mg_path = File.join(File.dirname(__FILE__),'/minival_grammar.treetop')
7
- #Treetop.load(mg_path)
8
-
9
- Treetop.load('minival_refi/minival_grammar.treetop'
10
-
11
- #module Minival
8
+ mg_path = File.join(File.dirname(__FILE__),'/minival_refi/minival_grammar.treetop')
9
+ Treetop.load(mg_path)
12
10
 
13
11
  # extending the MinivalGrammarParser a little
14
12
  class MinivalGrammarParser
@@ -17,32 +15,43 @@ class MinivalGrammarParser
17
15
  end
18
16
  end
19
17
 
18
+
20
19
  class Minival
21
- #@@parser = MinivalGrammarParser.new
20
+
22
21
  def initialize(minival_str)
23
22
  @parser = MinivalGrammarParser.new
24
23
  @parse_result = @parser.parse(minival_str)
25
24
  @val = nil
26
25
  end
27
- def valid
28
- return true if @parse_result
29
- return false
26
+
27
+ def is_valid
28
+ if @parse_result
29
+ return true
30
+ else
31
+ return false
32
+ end
30
33
  end
34
+
31
35
  def assert_valid
32
- unless valid
33
- report_errors
34
- # TODO
35
- #dperr 777,'Minival assert_valid failed'
36
+ if is_valid()
37
+ return @get_value
38
+ else
39
+ report_errors()
40
+ return nil
36
41
  end
37
42
  end
38
- def report_errors
39
- pp @parser.get_errors
43
+
44
+ def report_errors()
45
+ pp @parser.get_errors()
40
46
  end
41
- def compute_val
42
- @val = @parse_result.content
47
+
48
+ def compute_val()
49
+ @val = @parse_result.content()
43
50
  end
44
- def get_value
45
- return @val || compute_val
51
+
52
+ def get_value()
53
+ return @val || compute_val()
46
54
  end
55
+
47
56
  end
48
57
 
@@ -83,7 +83,7 @@ grammar MinivalGrammar
83
83
  rule str_inner
84
84
  ( ( ( "\\\\" )* "\\\"") / !'"' . )* {
85
85
  def content
86
- return text_value.unescape_c_str
86
+ return text_value.unescape_c_string
87
87
  end
88
88
  }
89
89
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Fey
@@ -47,6 +47,21 @@ dependencies:
47
47
  version: 1.4.9
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: string_extensions_refi
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - "="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 1
61
+ - 0
62
+ version: 0.1.0
63
+ type: :runtime
64
+ version_requirements: *id003
50
65
  description: |-
51
66
  supports: nil, string, integer, array, hash
52
67
  the syntax is similar to to ruby