packcr 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +73 -0
- data/lib/packcr/context.rb +1 -1
- data/lib/packcr/generated/context.rb +121 -78
- data/lib/packcr/generated/node/action_node.rb +2 -2
- data/lib/packcr/generated/node/alternate_node.rb +2 -2
- data/lib/packcr/generated/node/capture_node.rb +1 -1
- data/lib/packcr/generated/node/charclass_node.rb +9 -9
- data/lib/packcr/generated/node/eof_node.rb +1 -1
- data/lib/packcr/generated/node/error_node.rb +2 -2
- data/lib/packcr/generated/node/expand_node.rb +2 -2
- data/lib/packcr/generated/node/predicate_node.rb +2 -2
- data/lib/packcr/generated/node/quantity_node.rb +30 -31
- data/lib/packcr/generated/node/reference_node.rb +2 -2
- data/lib/packcr/generated/node/rule_node.rb +7 -7
- data/lib/packcr/generated/node/string_node.rb +4 -4
- data/lib/packcr/parser.rb +619 -613
- data/lib/packcr/templates/context/header.c.erb +3 -3
- data/lib/packcr/templates/context/source.c.erb +417 -403
- data/lib/packcr/templates/context/source.rb.erb +42 -25
- data/lib/packcr/templates/node/action.c.erb +2 -2
- data/lib/packcr/templates/node/alternate.c.erb +2 -2
- data/lib/packcr/templates/node/capture.c.erb +2 -2
- data/lib/packcr/templates/node/charclass.c.erb +4 -4
- data/lib/packcr/templates/node/charclass_any.c.erb +2 -2
- data/lib/packcr/templates/node/charclass_one.c.erb +4 -4
- data/lib/packcr/templates/node/charclass_utf8.c.erb +2 -2
- data/lib/packcr/templates/node/eof.c.erb +1 -1
- data/lib/packcr/templates/node/error.c.erb +4 -4
- data/lib/packcr/templates/node/expand.c.erb +2 -2
- data/lib/packcr/templates/node/predicate.c.erb +1 -1
- data/lib/packcr/templates/node/predicate_neg.c.erb +1 -1
- data/lib/packcr/templates/node/quantity_many.c.erb +9 -7
- data/lib/packcr/templates/node/quantity_one.c.erb +9 -7
- data/lib/packcr/templates/node/quantity_one.rb.erb +4 -4
- data/lib/packcr/templates/node/reference.c.erb +6 -6
- data/lib/packcr/templates/node/rule.c.erb +9 -9
- data/lib/packcr/templates/node/string_many.c.erb +2 -2
- data/lib/packcr/templates/node/string_one.c.erb +2 -2
- data/lib/packcr/util.rb +1 -1
- data/lib/packcr/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cacf5e781ba49bcc7d755ac5ba6e348646a08e4a807efd4375ba720232262556
|
4
|
+
data.tar.gz: ce70800733fbc71527539174f373786489f3fdda416b5435bf8aa687de1cd321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0cf28feb81c97f094f6b098656ab4ec30f312e99c84789c5e5f53cf8a520c4c63a561d48a240b7ab0699d2e063820e3b923118d33e2a9e3b5dfc2884993ac9d
|
7
|
+
data.tar.gz: c858ad58e577af40013bbd7438eb3c4066d0c76b0a6407c5ab051ae63a379936594da974a1c203a72659d3dcebc4794c0aaaf5beea2ab98169388a89c0c79773
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PackCR: a packrat parser generator for C as ruby library.
|
2
|
+
|
3
|
+
Copyright (c) 2022 wanabe All rights reserved.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# PackCR
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
PackCR is a parser generator for C or Ruby.
|
6
|
+
This library is a port of PackCC rewritten in ruby.
|
7
|
+
The Original PackCC is https://github.com/arithy/packcc.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
You can get Packcr object with `Packcr.new(peg_path)` and it can generate C source and header with `Packcr#run`.
|
12
|
+
|
13
|
+
Example(1):
|
14
|
+
|
15
|
+
```
|
16
|
+
$ cat ./tmp/example1.sh
|
17
|
+
#!/bin/sh
|
18
|
+
set -e
|
19
|
+
cd $0/..
|
20
|
+
cp ../packcc/examples/calc.peg calc.c.peg
|
21
|
+
bundle exec ruby -e 'require "packcr"; Packcr.new("calc.c.peg").run'
|
22
|
+
gcc calc.c
|
23
|
+
echo "1 + 2 * 3 - 4 / 2" | ./a.out
|
24
|
+
|
25
|
+
$ ./tmp/example1.sh
|
26
|
+
answer=5
|
27
|
+
```
|
28
|
+
|
29
|
+
Example(2):
|
30
|
+
|
31
|
+
```
|
32
|
+
$ cat ./tmp/example2.sh
|
33
|
+
#!/bin/sh
|
34
|
+
set -e
|
35
|
+
cd $0/..
|
36
|
+
cp ../examples/calc.rb.peg .
|
37
|
+
bundle exec ruby -e 'require "packcr"; Packcr.new("calc.rb.peg").run'
|
38
|
+
ruby calc.rb "1 + 2 * 3 - 4 / 2"
|
39
|
+
|
40
|
+
$ ./tmp/example2.sh
|
41
|
+
answer=5
|
42
|
+
```
|
43
|
+
|
44
|
+
## Syntax
|
45
|
+
|
46
|
+
The syntax is almost the same as PackCC.
|
47
|
+
Additional syntax is shown below.
|
48
|
+
|
49
|
+
**`%location` `{` _source code_ `}`**
|
50
|
+
|
51
|
+
It defines your own location structure.
|
52
|
+
It should have some definitions for C:
|
53
|
+
|
54
|
+
- struct
|
55
|
+
- `packcr_location_t`
|
56
|
+
- function
|
57
|
+
- `void packcr_location_init(packcr_location_t *lp)`
|
58
|
+
- `void packcr_location_forward(packcr_location_t *lp, char *buf, size_t n)`
|
59
|
+
- `packcr_location_t packcr_location_add(packcr_location_t l1, packcr_location_t l2)`
|
60
|
+
- `packcr_location_t packcr_location_sub(packcr_location_t l1, packcr_location_t l2)`
|
61
|
+
- (The functions can be `static` and/or `inline`)
|
62
|
+
|
63
|
+
Or it should have some definitions for ruby:
|
64
|
+
- class
|
65
|
+
- `Location`
|
66
|
+
- method
|
67
|
+
- `Location#initialize(...)`
|
68
|
+
- `Location#+(loc)`
|
69
|
+
- `Location#-(loc)`
|
70
|
+
- `Location#forward(str, index, n)`
|
71
|
+
|
72
|
+
Locations are captured and they can be refer with **`$`**_n_**`sl`** and **`$`**_n_**`el`**.
|
73
|
+
You can see the examples [examples/calc_loc.peg](examples/calc_loc.peg) and [examples/calc_loc.rb.peg](examples/calc_loc.rb.peg).
|