rsec 0.4.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/c_minus.rb +7 -6
- data/examples/little_markdown.rb +1 -1
- data/examples/nasm_manual.rb +2 -2
- data/examples/slow_json.rb +1 -1
- data/lib/rsec.rb +1 -1
- data/lib/rsec/parsers/misc.rb +1 -1
- data/test/test_misc.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8977b875ff6997eb73fd119f4227073e59cc8f03252b7393d730169177930373
|
4
|
+
data.tar.gz: 7493d1f6ae1f5e2a8d85d32d0fc1f5c98e1f3dbfed06453dad2c1bc5c02075d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e3f20dca6a450a0ef36da2b619ea7bd5083ac99c900b82da08302a02b7ca05db3ea95861fd76f8e87e0518076fc0d8b17091f30dd859094a55a42b9d8fd48be
|
7
|
+
data.tar.gz: 332d704b8ba296f4dd09de79fed738ba23e2e95162ef8230f6da862d0eda05a7379a36ab79c876c1b0d525d9157453129253c294b8fbe5fcf4e73d1e0efcad7b
|
data/examples/c_minus.rb
CHANGED
@@ -91,7 +91,7 @@ class CMinus
|
|
91
91
|
# p expr.parse! "gcd (v ,u- u/v *v)"
|
92
92
|
expr.map{|e| Expr[e] }
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
# statement parser builder, returns [stmt, block]
|
96
96
|
def statement var_decl
|
97
97
|
expr = expression()
|
@@ -114,9 +114,10 @@ class CMinus
|
|
114
114
|
}
|
115
115
|
stmt = block | if_stmt | while_stmt | return_stmt | expr_stmt
|
116
116
|
# p if_stmt.parse! 'if(v == 0)return u;'
|
117
|
+
# p block.parse! '{ int x; }'
|
117
118
|
[stmt, block]
|
118
119
|
end
|
119
|
-
|
120
|
+
|
120
121
|
def initialize
|
121
122
|
type_id = seq_(TYPE, ID).cached
|
122
123
|
# p type_id.parse! 'int a'
|
@@ -137,10 +138,10 @@ class CMinus
|
|
137
138
|
[ty, id, *maybe_bra]
|
138
139
|
}
|
139
140
|
params = param.join(COMMA).even | 'void'.r{[]}
|
140
|
-
|
141
|
-
fun_decl = seq_(type_id,
|
142
|
-
|
143
|
-
Function[
|
141
|
+
paren_args = seq_('(', params, ')')[1]
|
142
|
+
fun_decl = seq_(type_id, paren_args, block){|results|
|
143
|
+
type_id_result, params_result, block_result = results
|
144
|
+
Function[*type_id_result, params_result, block_result]
|
144
145
|
}
|
145
146
|
# p fun_decl.parse! 'int gcd(int u, int v){return 2;}'
|
146
147
|
@program = SPACE.join(fun_decl | var_decl | EOSTMT).odd.eof
|
data/examples/little_markdown.rb
CHANGED
@@ -65,7 +65,7 @@ class LittleMarkdown
|
|
65
65
|
"<span id='#{id}'>#{text}</span>"
|
66
66
|
}
|
67
67
|
line = (img | link | strong | em | code | escape | id | text).star
|
68
|
-
line.eof.map
|
68
|
+
line.eof.map {|parts, _| parts.join }
|
69
69
|
end
|
70
70
|
|
71
71
|
# pseudo xml tag parser, except <br> and <hr> and <script>
|
data/examples/nasm_manual.rb
CHANGED
@@ -42,7 +42,7 @@ module NASMManualParser
|
|
42
42
|
tr_class = 'TR3/4/5/6/7'
|
43
43
|
classes = (imm_class.r | memoffs_class | mem_class | reg_class | tr_class).fail 'operand class'
|
44
44
|
reg = reg_parser.fail 'register'
|
45
|
-
num = /\d/.r
|
45
|
+
num = /\d/.r{|n, _| n.to_i }.fail 'num'
|
46
46
|
# memoffs should be left of mem
|
47
47
|
operand = classes | reg | num
|
48
48
|
operands = operand.join('/').even.join(',').even
|
@@ -107,7 +107,7 @@ module NASMManualParser
|
|
107
107
|
parsed = ''
|
108
108
|
parser = instruction_parser.eof
|
109
109
|
src = File.read filename
|
110
|
-
src.lines.
|
110
|
+
src.lines.to_a.each_with_index do |raw_line, idx|
|
111
111
|
line = raw_line.strip
|
112
112
|
# this shapy shows the line is something defining an nemonic
|
113
113
|
if line =~ /^\w+\s+[^;\[]+;\ [^;\[]+\[.+\]$/
|
data/examples/slow_json.rb
CHANGED
@@ -40,7 +40,7 @@ class SlowJSON
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def generate_parser
|
43
|
-
string = '"'.r >> chars_parser.star.map
|
43
|
+
string = '"'.r >> chars_parser.star.map{|cs, _| cs.join } << '"'
|
44
44
|
# -? int frac? exp?
|
45
45
|
number = prim(:double, allowed_sign: '-')
|
46
46
|
@value = string | number | lazy{@object} | lazy{@array} |
|
data/lib/rsec.rb
CHANGED
data/lib/rsec/parsers/misc.rb
CHANGED
data/test/test_misc.rb
CHANGED
@@ -41,6 +41,18 @@ class TestMisc < TC
|
|
41
41
|
ase 'bb', p.parse('b')
|
42
42
|
ase INVALID, p.parse('.')
|
43
43
|
end
|
44
|
+
|
45
|
+
def test_seq_map
|
46
|
+
p = seq('"'.r, /\w/.r, '"'.r).map{|(_, n, _)| n*2}
|
47
|
+
ase 'bb', p.parse('"b"')
|
48
|
+
ase INVALID, p.parse('.')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_seq_map_with_context
|
52
|
+
p = seq('"'.r, /\w/.r, '"'.r).map{|(_, n, _), ctx| n*ctx.pos}
|
53
|
+
ase 'bbb', p.parse('"b"')
|
54
|
+
ase INVALID, p.parse('.')
|
55
|
+
end
|
44
56
|
|
45
57
|
def test_fail
|
46
58
|
p = 'v'.r.fail 'omg!'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easy and extreme fast dynamic PEG parser combinator.
|
14
14
|
email:
|