packcr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +73 -0
  4. data/lib/packcr/context.rb +1 -1
  5. data/lib/packcr/generated/context.rb +121 -78
  6. data/lib/packcr/generated/node/action_node.rb +2 -2
  7. data/lib/packcr/generated/node/alternate_node.rb +2 -2
  8. data/lib/packcr/generated/node/capture_node.rb +1 -1
  9. data/lib/packcr/generated/node/charclass_node.rb +9 -9
  10. data/lib/packcr/generated/node/eof_node.rb +1 -1
  11. data/lib/packcr/generated/node/error_node.rb +2 -2
  12. data/lib/packcr/generated/node/expand_node.rb +2 -2
  13. data/lib/packcr/generated/node/predicate_node.rb +2 -2
  14. data/lib/packcr/generated/node/quantity_node.rb +30 -31
  15. data/lib/packcr/generated/node/reference_node.rb +2 -2
  16. data/lib/packcr/generated/node/rule_node.rb +7 -7
  17. data/lib/packcr/generated/node/string_node.rb +4 -4
  18. data/lib/packcr/parser.rb +619 -613
  19. data/lib/packcr/templates/context/header.c.erb +3 -3
  20. data/lib/packcr/templates/context/source.c.erb +417 -403
  21. data/lib/packcr/templates/context/source.rb.erb +42 -25
  22. data/lib/packcr/templates/node/action.c.erb +2 -2
  23. data/lib/packcr/templates/node/alternate.c.erb +2 -2
  24. data/lib/packcr/templates/node/capture.c.erb +2 -2
  25. data/lib/packcr/templates/node/charclass.c.erb +4 -4
  26. data/lib/packcr/templates/node/charclass_any.c.erb +2 -2
  27. data/lib/packcr/templates/node/charclass_one.c.erb +4 -4
  28. data/lib/packcr/templates/node/charclass_utf8.c.erb +2 -2
  29. data/lib/packcr/templates/node/eof.c.erb +1 -1
  30. data/lib/packcr/templates/node/error.c.erb +4 -4
  31. data/lib/packcr/templates/node/expand.c.erb +2 -2
  32. data/lib/packcr/templates/node/predicate.c.erb +1 -1
  33. data/lib/packcr/templates/node/predicate_neg.c.erb +1 -1
  34. data/lib/packcr/templates/node/quantity_many.c.erb +9 -7
  35. data/lib/packcr/templates/node/quantity_one.c.erb +9 -7
  36. data/lib/packcr/templates/node/quantity_one.rb.erb +4 -4
  37. data/lib/packcr/templates/node/reference.c.erb +6 -6
  38. data/lib/packcr/templates/node/rule.c.erb +9 -9
  39. data/lib/packcr/templates/node/string_many.c.erb +2 -2
  40. data/lib/packcr/templates/node/string_one.c.erb +2 -2
  41. data/lib/packcr/util.rb +1 -1
  42. data/lib/packcr/version.rb +1 -1
  43. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f6f8510a8922ec8a3f379de4470af6889a01a0f98aebf46b69f16e2c398c64
4
- data.tar.gz: aa728bb984a9a343c71099fe6652b7a37c5a3a20b535ad6d5cbc29feaaa776d0
3
+ metadata.gz: cacf5e781ba49bcc7d755ac5ba6e348646a08e4a807efd4375ba720232262556
4
+ data.tar.gz: ce70800733fbc71527539174f373786489f3fdda416b5435bf8aa687de1cd321
5
5
  SHA512:
6
- metadata.gz: ceee0d72c7fa96a8a71fd76d8015591f70c4ba321242966ed295522d55e37e2ce71cf8ab51bda644971f5b0ad675c4c0dbdd225e8f2eded2d5eb8f5a3957922f
7
- data.tar.gz: fd819a73b1b16827316ddef020068383952cf6d188ac728f5d06157330b49b0010561552676fce3652cc90b0f838f7750242622b83d0677335e6bc6235199d4f
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).
@@ -84,7 +84,7 @@ class Packcr
84
84
  end
85
85
 
86
86
  def prefix
87
- @prefix || "pcc"
87
+ @prefix || "packcr"
88
88
  end
89
89
 
90
90
  def pass_value_code(var)