swissparser 0.11.1 → 1.0.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.
@@ -1,60 +0,0 @@
1
- module Swiss
2
-
3
- # Methods of this class are accessible to rules and actions.
4
- # Methods defined in +helpers+ block are added to this class.
5
- class ParsingContext
6
-
7
- def initialize(parameters)
8
- @params__ = parameters
9
- @skip__ = false
10
- end
11
-
12
- # Retrieves a parsing parameter by key. Returns nil if
13
- # there is no parameter with the provided key.
14
- def param( key )
15
- @params__[key]
16
- end
17
-
18
- def skip_entry!()
19
- @skip__ = true
20
- end
21
-
22
- def should_skip?()
23
- @skip__
24
- end
25
-
26
- def reset_skip()
27
- @skip__ = false
28
- end
29
-
30
-
31
- module InstanceExecHelper #:nodoc:
32
- end
33
-
34
- include InstanceExecHelper
35
-
36
- #Method instance_exec exists since version 1.9
37
- if RUBY_VERSION < "1.9"
38
- #Used to execuxte rules and action using the ParsingContext as context
39
- #Stolen from http://eigenclass.org/hiki/bounded+space+instance_exec
40
- def instance_exec(*args, &block)
41
- begin
42
- old_critical, Thread.critical = Thread.critical, true
43
- n = 0
44
- n += 1 while respond_to?(mname="__instance_exec#{n}")
45
- InstanceExecHelper.module_eval{ define_method(mname, &block) }
46
- ensure
47
- Thread.critical = old_critical
48
- end
49
- begin
50
- ret = send(mname, *args)
51
- ensure
52
- InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
53
- end
54
- ret
55
- end
56
- end
57
-
58
- end
59
-
60
- end
@@ -1,39 +0,0 @@
1
- module Swiss
2
-
3
- # This class defines parsing rules. Its methods
4
- # are accessible within the +rules+ section of
5
- # a parser definition.
6
- class ParsingRules
7
-
8
- attr_reader :separator, :actions
9
-
10
- # *Do* *not* create directly this class but access it
11
- # through a +rules+ section in a parser definition.
12
- def initialize
13
- @actions = { :text => {} }
14
- end
15
-
16
- # Sets the entry separator line. Default: "//"
17
- def set_separator(string)
18
- @separator = string
19
- end
20
-
21
- # Defines how to parse a line starting with +key+. The +proc+
22
- # takes two arguments:
23
- # * the rest of the line
24
- # * the entry object
25
- def with( key, &proc )
26
- @actions[key] = proc
27
- end
28
-
29
- # Defines how to parse a line without key coming *after*
30
- # a specified key. The +proc+ takes two arguments:
31
- # * the rest of the line
32
- # * the entry object
33
- def with_text_after( key, &proc )
34
- @actions[:text][key] = proc
35
- end
36
-
37
- end
38
-
39
- end