c_lexer 2.5.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
data/ext/lexer/stack.h ADDED
@@ -0,0 +1,41 @@
1
+ #define define_stack_type(name, member_type, zero) \
2
+ typedef struct name { \
3
+ member_type *top; \
4
+ member_type *bottom; \
5
+ int size; /* used when growing dynamically */ \
6
+ } name; \
7
+ static inline void name ## _init(name *stack) { \
8
+ member_type *buf = xmalloc(4 * sizeof(member_type)); \
9
+ stack->size = 4; \
10
+ stack->top = stack->bottom = buf; \
11
+ } \
12
+ static inline void name ## _dealloc(name *stack) { \
13
+ xfree(stack->bottom); \
14
+ } \
15
+ static inline void name ## _clear(name *stack) { \
16
+ stack->top = stack->bottom; \
17
+ } \
18
+ static inline void name ## _push(name *stack, member_type item) { \
19
+ if (stack->top == (stack->bottom + stack->size)) { \
20
+ member_type *buf = xmalloc(stack->size * 2 * sizeof(member_type)); \
21
+ memcpy(buf, stack->bottom, stack->size * sizeof(member_type)); \
22
+ xfree(stack->bottom); \
23
+ stack->top = buf + (stack->top - stack->bottom); \
24
+ stack->bottom = buf; \
25
+ stack->size = stack->size * 2; \
26
+ } \
27
+ *stack->top++ = item; \
28
+ } \
29
+ static inline member_type name ## _pop(name *stack) { \
30
+ if (stack->top > stack->bottom) { \
31
+ return *--stack->top; \
32
+ } else { \
33
+ return (member_type)zero; \
34
+ } \
35
+ } \
36
+ static inline member_type* name ## _top(name *stack) { \
37
+ if (stack->top > stack->bottom) \
38
+ return stack->top - 1; \
39
+ else \
40
+ return NULL; \
41
+ }
@@ -0,0 +1,48 @@
1
+ typedef int stack_state;
2
+
3
+ define_stack_type(ss_stack, stack_state, 0);
4
+
5
+ static inline int stack_state_push(stack_state *ss, int bit)
6
+ {
7
+ bit = bit ? 1 : 0;
8
+ *ss = (*ss << 1) | bit;
9
+ return bit;
10
+ }
11
+
12
+ static inline int stack_state_pop(stack_state *ss)
13
+ {
14
+ int bit = *ss & 1;
15
+ *ss >>= 1;
16
+ return bit;
17
+ }
18
+
19
+ static inline int stack_state_lexpop(stack_state *ss)
20
+ {
21
+ *ss = ( (*ss >> 1) | (*ss & 1) );
22
+ return *ss & 1;
23
+ }
24
+
25
+ static inline int stack_state_active(stack_state *ss)
26
+ {
27
+ return *ss & 1;
28
+ }
29
+
30
+ static inline void stack_state_clear(stack_state *ss)
31
+ {
32
+ *ss = 0;
33
+ }
34
+
35
+ static inline VALUE stack_state_empty_p(stack_state *ss)
36
+ {
37
+ return *ss == 0 ? Qtrue : Qfalse;
38
+ }
39
+
40
+ static inline int stack_state_value(stack_state *ss)
41
+ {
42
+ return *ss;
43
+ }
44
+
45
+ static inline void stack_set_value(stack_state *ss, int value)
46
+ {
47
+ *ss = value;
48
+ }
data/lib/c_lexer.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'c_lexer/version'
2
+ require 'parser/ruby25'
3
+
4
+ require_relative 'lexer'
5
+
6
+ module Parser
7
+ class CLexer
8
+ class CmdargProxyStack
9
+ def initialize(lexer)
10
+ @lexer = lexer
11
+ @value = nil
12
+ end
13
+
14
+ def push(value); @lexer.push_cmdarg_state(value); end
15
+ def pop; @lexer.pop_cmdarg_state; end
16
+ def lexpop; @lexer.lexpop_cmdarg_state; end
17
+ def clear; @lexer.clear_cmdarg_state; end
18
+ def empty?; @lexer.cmdarg_state_empty?; end
19
+ def value; @value || @lexer.cmdarg_state_value; end
20
+ def initialize_copy(original)
21
+ @value = original.value
22
+ end
23
+
24
+ def to_s
25
+ "[#{value.to_s(2)} <= cmdarg]"
26
+ end
27
+ end
28
+
29
+ class CondProxyStack
30
+ def initialize(lexer)
31
+ @lexer = lexer
32
+ @value = nil
33
+ end
34
+
35
+ def push(value); @lexer.push_cond_state(value); end
36
+ def pop; @lexer.pop_cond_state; end
37
+ def lexpop; @lexer.lexpop_cond_state; end
38
+ def clear; @lexer.clear_cond_state; end
39
+ def empty?; @lexer.cond_state_empty?; end
40
+ def value; @value || @lexer.cond_state_value; end
41
+ def initialize_copy(original)
42
+ @value = original.value
43
+ end
44
+
45
+ def to_s
46
+ "[#{value.to_s(2)} <= cond]"
47
+ end
48
+ end
49
+
50
+ def cmdarg
51
+ @cmdarg ||= CmdargProxyStack.new(self)
52
+ end
53
+
54
+ def cond
55
+ @cond ||= CondProxyStack.new(self)
56
+ end
57
+
58
+ def cmdarg=(cmdarg)
59
+ set_cmdarg_state(cmdarg.value)
60
+ @cmdarg = nil
61
+ end
62
+
63
+ def cond=(cond)
64
+ set_cond_state(cond.value)
65
+ @cond = nil
66
+ end
67
+ end
68
+
69
+ class Ruby25WithCLexer < Ruby25
70
+ def initialize(builder=Parser::Builders::Default.new)
71
+ super(builder)
72
+ @lexer = ::Parser::CLexer.new(version)
73
+ @lexer.diagnostics = @diagnostics
74
+ @lexer.static_env = @static_env
75
+ end
76
+ end
77
+ end
78
+
79
+ module CLexer
80
+ end
@@ -0,0 +1,3 @@
1
+ module CLexer
2
+ VERSION = '2.5.1.0.pre1'
3
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: c_lexer
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.1.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Ilya Bylich
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ast
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.15.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.15.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: racc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.4.14
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.4.14
125
+ - !ruby/object:Gem::Dependency
126
+ name: cliver
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.3.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.3.2
139
+ description: A Ruby parser written in C
140
+ email:
141
+ - ibylich@gmail.com
142
+ executables: []
143
+ extensions:
144
+ - ext/lexer/extconf.rb
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".gitmodules"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - README.md
153
+ - Rakefile
154
+ - bin/c-ruby-parse
155
+ - bin/console
156
+ - bin/setup
157
+ - c_lexer.gemspec
158
+ - ext/lexer/cmdarg.h
159
+ - ext/lexer/cond.h
160
+ - ext/lexer/emit_tables.h
161
+ - ext/lexer/extconf.rb
162
+ - ext/lexer/lexer.c
163
+ - ext/lexer/lexer.h
164
+ - ext/lexer/lexer.rl
165
+ - ext/lexer/literal.h
166
+ - ext/lexer/literal/methods.h
167
+ - ext/lexer/literal/type.h
168
+ - ext/lexer/stack.h
169
+ - ext/lexer/stack_state.h
170
+ - lib/c_lexer.rb
171
+ - lib/c_lexer/version.rb
172
+ homepage: https://github.com/iliabylich/c_lexer
173
+ licenses: []
174
+ metadata: {}
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">"
187
+ - !ruby/object:Gem::Version
188
+ version: 1.3.1
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 2.7.6
192
+ signing_key:
193
+ specification_version: 4
194
+ summary: A Ruby parser written in C
195
+ test_files: []