prism 2.0.0.rc1-arm64-darwin

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.
Files changed (216) hide show
  1. checksums.yaml +7 -0
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +870 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/LICENSE.md +7 -0
  7. data/Makefile +145 -0
  8. data/README.md +81 -0
  9. data/config.yml +4752 -0
  10. data/docs/build_system.md +119 -0
  11. data/docs/configuration.md +69 -0
  12. data/docs/cruby_compilation.md +27 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +121 -0
  15. data/docs/fuzzing.md +81 -0
  16. data/docs/heredocs.md +36 -0
  17. data/docs/javascript.md +133 -0
  18. data/docs/local_variable_depth.md +229 -0
  19. data/docs/mapping.md +117 -0
  20. data/docs/parser_translation.md +24 -0
  21. data/docs/parsing_rules.md +22 -0
  22. data/docs/releasing.md +147 -0
  23. data/docs/relocation.md +32 -0
  24. data/docs/ripper_translation.md +63 -0
  25. data/docs/ruby_api.md +45 -0
  26. data/docs/ruby_parser_translation.md +19 -0
  27. data/docs/serialization.md +230 -0
  28. data/docs/testing.md +72 -0
  29. data/ext/prism/api_node.c +7005 -0
  30. data/ext/prism/extconf.rb +126 -0
  31. data/ext/prism/extension.c +1783 -0
  32. data/ext/prism/extension.h +19 -0
  33. data/include/prism/arena.h +37 -0
  34. data/include/prism/ast.h +10371 -0
  35. data/include/prism/buffer.h +52 -0
  36. data/include/prism/comments.h +55 -0
  37. data/include/prism/compiler/accel.h +24 -0
  38. data/include/prism/compiler/align.h +36 -0
  39. data/include/prism/compiler/assume.h +25 -0
  40. data/include/prism/compiler/exported.h +24 -0
  41. data/include/prism/compiler/fallthrough.h +22 -0
  42. data/include/prism/compiler/filesystem.h +32 -0
  43. data/include/prism/compiler/flex_array.h +19 -0
  44. data/include/prism/compiler/force_inline.h +21 -0
  45. data/include/prism/compiler/format.h +25 -0
  46. data/include/prism/compiler/inline.h +17 -0
  47. data/include/prism/compiler/nodiscard.h +22 -0
  48. data/include/prism/compiler/nonnull.h +18 -0
  49. data/include/prism/compiler/unused.h +18 -0
  50. data/include/prism/constant_pool.h +81 -0
  51. data/include/prism/diagnostic.h +93 -0
  52. data/include/prism/errors_format.h +53 -0
  53. data/include/prism/excludes.h +29 -0
  54. data/include/prism/integer.h +41 -0
  55. data/include/prism/internal/allocator.h +68 -0
  56. data/include/prism/internal/allocator_debug.h +88 -0
  57. data/include/prism/internal/arena.h +108 -0
  58. data/include/prism/internal/bit.h +42 -0
  59. data/include/prism/internal/buffer.h +91 -0
  60. data/include/prism/internal/char.h +145 -0
  61. data/include/prism/internal/comments.h +53 -0
  62. data/include/prism/internal/constant_pool.h +152 -0
  63. data/include/prism/internal/diagnostic.h +389 -0
  64. data/include/prism/internal/encoding.h +242 -0
  65. data/include/prism/internal/integer.h +68 -0
  66. data/include/prism/internal/isinf.h +16 -0
  67. data/include/prism/internal/line_offset_list.h +34 -0
  68. data/include/prism/internal/list.h +62 -0
  69. data/include/prism/internal/magic_comments.h +23 -0
  70. data/include/prism/internal/memchr.h +15 -0
  71. data/include/prism/internal/node.h +38 -0
  72. data/include/prism/internal/options.h +232 -0
  73. data/include/prism/internal/parser.h +984 -0
  74. data/include/prism/internal/regexp.h +26 -0
  75. data/include/prism/internal/serialize.h +39 -0
  76. data/include/prism/internal/source.h +72 -0
  77. data/include/prism/internal/static_literals.h +100 -0
  78. data/include/prism/internal/stringy.h +35 -0
  79. data/include/prism/internal/strncasecmp.h +18 -0
  80. data/include/prism/internal/strpbrk.h +33 -0
  81. data/include/prism/internal/tokens.h +11 -0
  82. data/include/prism/json.h +32 -0
  83. data/include/prism/line_offset_list.h +61 -0
  84. data/include/prism/magic_comments.h +35 -0
  85. data/include/prism/node.h +94 -0
  86. data/include/prism/options.h +354 -0
  87. data/include/prism/parser.h +404 -0
  88. data/include/prism/prettyprint.h +31 -0
  89. data/include/prism/serialize.h +115 -0
  90. data/include/prism/source.h +155 -0
  91. data/include/prism/stream.h +28 -0
  92. data/include/prism/string_query.h +63 -0
  93. data/include/prism/stringy.h +72 -0
  94. data/include/prism/version.h +38 -0
  95. data/include/prism.h +131 -0
  96. data/lib/prism/3.3/prism.bundle +0 -0
  97. data/lib/prism/3.4/prism.bundle +0 -0
  98. data/lib/prism/4.0/prism.bundle +0 -0
  99. data/lib/prism/compiler.rb +815 -0
  100. data/lib/prism/desugar_compiler.rb +463 -0
  101. data/lib/prism/dispatcher.rb +2383 -0
  102. data/lib/prism/dot_visitor.rb +4848 -0
  103. data/lib/prism/dsl.rb +1369 -0
  104. data/lib/prism/ffi.rb +740 -0
  105. data/lib/prism/inspect_visitor.rb +2425 -0
  106. data/lib/prism/lex_compat.rb +953 -0
  107. data/lib/prism/mutation_compiler.rb +780 -0
  108. data/lib/prism/node.rb +33204 -0
  109. data/lib/prism/node_ext.rb +504 -0
  110. data/lib/prism/node_find.rb +215 -0
  111. data/lib/prism/parse_result/errors.rb +72 -0
  112. data/lib/prism/parse_result/newlines.rb +423 -0
  113. data/lib/prism/parse_result.rb +1221 -0
  114. data/lib/prism/pattern.rb +314 -0
  115. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  116. data/lib/prism/polyfill/byteindex.rb +13 -0
  117. data/lib/prism/polyfill/scan_byte.rb +14 -0
  118. data/lib/prism/polyfill/unpack1.rb +14 -0
  119. data/lib/prism/polyfill/warn.rb +36 -0
  120. data/lib/prism/reflection.rb +427 -0
  121. data/lib/prism/relocation.rb +567 -0
  122. data/lib/prism/serialize.rb +5308 -0
  123. data/lib/prism/string_query.rb +46 -0
  124. data/lib/prism/translation/parser/builder.rb +70 -0
  125. data/lib/prism/translation/parser/compiler.rb +2226 -0
  126. data/lib/prism/translation/parser/lexer.rb +769 -0
  127. data/lib/prism/translation/parser.rb +376 -0
  128. data/lib/prism/translation/parser_current.rb +26 -0
  129. data/lib/prism/translation/parser_versions.rb +36 -0
  130. data/lib/prism/translation/ripper/filter.rb +53 -0
  131. data/lib/prism/translation/ripper/lexer.rb +133 -0
  132. data/lib/prism/translation/ripper/sexp.rb +118 -0
  133. data/lib/prism/translation/ripper/shim.rb +7 -0
  134. data/lib/prism/translation/ripper.rb +4278 -0
  135. data/lib/prism/translation/ruby_parser.rb +1721 -0
  136. data/lib/prism/translation.rb +20 -0
  137. data/lib/prism/visitor.rb +1440 -0
  138. data/lib/prism.rb +168 -0
  139. data/prism.gemspec +234 -0
  140. data/rbi/generated/prism/compiler.rbi +489 -0
  141. data/rbi/generated/prism/desugar_compiler.rbi +306 -0
  142. data/rbi/generated/prism/dispatcher.rbi +1138 -0
  143. data/rbi/generated/prism/dot_visitor.rbi +618 -0
  144. data/rbi/generated/prism/dsl.rbi +751 -0
  145. data/rbi/generated/prism/inspect_visitor.rbi +503 -0
  146. data/rbi/generated/prism/lex_compat.rbi +162 -0
  147. data/rbi/generated/prism/mutation_compiler.rbi +464 -0
  148. data/rbi/generated/prism/node.rbi +13681 -0
  149. data/rbi/generated/prism/node_ext.rbi +259 -0
  150. data/rbi/generated/prism/node_find.rbi +79 -0
  151. data/rbi/generated/prism/parse_result/errors.rbi +21 -0
  152. data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
  153. data/rbi/generated/prism/parse_result.rbi +764 -0
  154. data/rbi/generated/prism/pattern.rbi +134 -0
  155. data/rbi/generated/prism/reflection.rbi +89 -0
  156. data/rbi/generated/prism/relocation.rbi +329 -0
  157. data/rbi/generated/prism/serialize.rbi +181 -0
  158. data/rbi/generated/prism/string_query.rbi +36 -0
  159. data/rbi/generated/prism/translation.rbi +7 -0
  160. data/rbi/generated/prism/visitor.rbi +650 -0
  161. data/rbi/generated/prism.rbi +86 -0
  162. data/rbi/prism/translation/parser.rbi +11 -0
  163. data/rbi/prism/translation/parser_versions.rbi +28 -0
  164. data/rbi/prism/translation/ripper.rbi +15 -0
  165. data/rbi/rubyvm/node_find.rbi +14 -0
  166. data/sig/generated/prism/compiler.rbs +492 -0
  167. data/sig/generated/prism/desugar_compiler.rbs +305 -0
  168. data/sig/generated/prism/dispatcher.rbs +1292 -0
  169. data/sig/generated/prism/dot_visitor.rbs +635 -0
  170. data/sig/generated/prism/dsl.rbs +928 -0
  171. data/sig/generated/prism/inspect_visitor.rbs +509 -0
  172. data/sig/generated/prism/lex_compat.rbs +166 -0
  173. data/sig/generated/prism/mutation_compiler.rbs +464 -0
  174. data/sig/generated/prism/node.rbs +20160 -0
  175. data/sig/generated/prism/node_ext.rbs +290 -0
  176. data/sig/generated/prism/node_find.rbs +90 -0
  177. data/sig/generated/prism/parse_result/errors.rbs +22 -0
  178. data/sig/generated/prism/parse_result/newlines.rbs +223 -0
  179. data/sig/generated/prism/parse_result.rbs +859 -0
  180. data/sig/generated/prism/pattern.rbs +156 -0
  181. data/sig/generated/prism/reflection.rbs +101 -0
  182. data/sig/generated/prism/relocation.rbs +428 -0
  183. data/sig/generated/prism/serialize.rbs +195 -0
  184. data/sig/generated/prism/string_query.rbs +36 -0
  185. data/sig/generated/prism/translation.rbs +8 -0
  186. data/sig/generated/prism/visitor.rbs +1111 -0
  187. data/sig/generated/prism.rbs +84 -0
  188. data/sig/manifest.yaml +2 -0
  189. data/src/arena.c +117 -0
  190. data/src/buffer.c +380 -0
  191. data/src/char.c +289 -0
  192. data/src/comments.c +454 -0
  193. data/src/constant_pool.c +406 -0
  194. data/src/diagnostic.c +886 -0
  195. data/src/encoding.c +5345 -0
  196. data/src/errors_format.c +519 -0
  197. data/src/integer.c +681 -0
  198. data/src/json.c +5733 -0
  199. data/src/line_offset_list.c +100 -0
  200. data/src/list.c +24 -0
  201. data/src/memchr.c +37 -0
  202. data/src/node.c +4515 -0
  203. data/src/options.c +451 -0
  204. data/src/parser.c +349 -0
  205. data/src/prettyprint.c +9024 -0
  206. data/src/prism.c +23739 -0
  207. data/src/regexp.c +1706 -0
  208. data/src/serialize.c +2309 -0
  209. data/src/source.c +518 -0
  210. data/src/static_literals.c +685 -0
  211. data/src/string_query.c +166 -0
  212. data/src/stringy.c +91 -0
  213. data/src/strncasecmp.c +37 -0
  214. data/src/strpbrk.c +447 -0
  215. data/src/tokens.c +724 -0
  216. metadata +259 -0
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ - Using welcoming and inclusive language
18
+ - Being respectful of differing viewpoints and experiences
19
+ - Gracefully accepting constructive criticism
20
+ - Focusing on what is best for the community
21
+ - Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ - The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ - Trolling, insulting/derogatory comments, and personal or political attacks
28
+ - Public or private harassment
29
+ - Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ - Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at opensource@shopify.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,58 @@
1
+ # Contributing
2
+
3
+ Thank you for your interest in contributing to prism! Below are a couple of ways that you can help out.
4
+
5
+ ## Discussions
6
+
7
+ The discussions page on the GitHub repository are open. If you have a question or want to discuss the project, feel free to open a new discussion or comment on an existing one. This is the best place to ask questions about the project.
8
+
9
+ ## Code
10
+
11
+ If you want to contribute code, please first open or contribute to a discussion. A lot of the project is in flux, and we want to make sure that you are contributing to the right place. Once you have a discussion going, you can open a pull request with your changes. We will review your code and get it merged in.
12
+
13
+ ## Tests
14
+
15
+ We could always use more tests! One of the biggest challenges of this project is building up a big test suite. If you want to contribute tests, feel free to open a pull request. These will get merged in as soon as possible.
16
+
17
+ The `test` Rake task will not compile libraries or the C extension, and this is intentional (to make testing against an installed version easier). If you want to test your changes, please make sure you're also running either the task:
18
+
19
+ ``` sh
20
+ bundle exec rake
21
+ ```
22
+
23
+ or explicitly running the `compile` task:
24
+
25
+ ``` sh
26
+ bundle exec rake compile test
27
+ # or to just compile the C extension ...
28
+ bundle exec rake compile:prism test
29
+ ```
30
+
31
+ To test the rust bindings (with caveats about setting up your Rust environment properly first):
32
+
33
+ ``` sh
34
+ bundle exec rake compile test:rust
35
+ ```
36
+
37
+
38
+ ## Documentation
39
+
40
+ We could always use more documentation! If you want to contribute documentation, feel free to open a pull request. These will get merged in as soon as possible. Documenting functions or methods is always useful, but we also need more guides and tutorials. If you have an idea for a guide or tutorial, feel free to open an issue and we can discuss it.
41
+
42
+ ## Developing
43
+
44
+ To get `clangd` support in the editor for development, generate the compilation database. This command will
45
+ create an ignored `compile_commands.json` file at the project root, which is used by clangd to provide functionality.
46
+
47
+ You will need `bear` which can be installed on macOS with `brew install bear`.
48
+
49
+ ```sh
50
+ bundle exec rake bear
51
+ ```
52
+
53
+ ## Debugging
54
+
55
+ Some useful rake tasks:
56
+
57
+ - `test:valgrind` runs the test suite under valgrind to look for illegal memory access or memory leaks
58
+ - `test:gdb` and `test:lldb` run the test suite under those debuggers
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2022-present, Shopify Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,145 @@
1
+
2
+ # V=0 quiet, V=1 verbose. other values don't work.
3
+ V = 0
4
+ V0 = $(V:0=)
5
+ Q1 = $(V:1=)
6
+ Q = $(Q1:0=@)
7
+ ECHO1 = $(V:1=@ :)
8
+ ECHO = $(ECHO1:0=@ echo)
9
+ FUZZ_OUTPUT_DIR = $(CURDIR)/fuzz/output
10
+
11
+ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12
+
13
+ CPPFLAGS := -Iinclude $(CPPFLAGS)
14
+ CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(CFLAGS)
15
+ JAVA_WASM_CFLAGS := -g0 -O2 -Oz -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fno-sanitize=all -fno-stack-protector -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(JAVA_WASM_CFLAGS)
16
+ CC ?= cc
17
+ AR ?= ar
18
+ ARFLAGS ?= -r$(V0:1=v)
19
+ WASI_SDK_PATH := /opt/wasi-sdk
20
+
21
+ # Exporting a symbol makes it a GC root, so the JavaScript module exports only
22
+ # the symbols javascript/src/parsePrism.js calls. That lets --gc-sections drop
23
+ # the rest of the C API along with the wasi-libc code reachable from it.
24
+ WASM_EXPORTS := -Wl,--export=malloc,--export=free,--export=pm_buffer_new,--export=pm_buffer_value,--export=pm_buffer_length,--export=pm_buffer_free,--export=pm_serialize_parse
25
+
26
+ # Bind the library's own references to its own definitions at link time, so
27
+ # that the functions exported for FFI cannot be interposed by another copy of
28
+ # libprism loaded in the same process (for example the copy built into the
29
+ # interpreter next to the one built by a prism gem, when either copy was loaded
30
+ # with RTLD_GLOBAL). Mach-O and PE do this by default; only ELF needs the flag.
31
+ ifeq ($(SOEXT),so)
32
+ SHARED_LDFLAGS := -Wl,-Bsymbolic
33
+ endif
34
+
35
+ MAKEDIRS ?= mkdir -p
36
+ RMALL ?= rm -f -r
37
+
38
+ HEADERS := $(wildcard include/*.h include/*/*.h include/*/*/*.h)
39
+ SOURCES := $(wildcard src/*.c src/*/*.c)
40
+ SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
41
+ STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
42
+
43
+ all: shared static
44
+
45
+ shared: build/libprism.$(SOEXT)
46
+ static: build/libprism.a
47
+ wasm: javascript/src/prism.wasm
48
+ java-wasm: java/wasm/src/main/wasm/prism.wasm
49
+ playground: doc/playground
50
+
51
+ build/libprism.$(SOEXT): $(SHARED_OBJECTS)
52
+ $(ECHO) "linking $@ with $(CC)"
53
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared $(SHARED_LDFLAGS) -o $@ $(SHARED_OBJECTS)
54
+
55
+ build/libprism.a: $(STATIC_OBJECTS)
56
+ $(ECHO) "building $@ with $(AR)"
57
+ $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS)
58
+
59
+ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
60
+ $(ECHO) "building $@"
61
+ $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ \
62
+ $(DEBUG_FLAGS) \
63
+ -DPRISM_EXPORT_SYMBOLS -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON \
64
+ -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) \
65
+ $(WASM_EXPORTS) -Wl,--gc-sections -Wl,--strip-all -Wl,--lto-O3 -Wl,--no-entry -mexec-model=reactor \
66
+ -Oz -g0 -flto -fdata-sections -ffunction-sections \
67
+ -o $@ $(SOURCES)
68
+
69
+ # The playground parses with the JavaScript package built from this checkout, so
70
+ # the page is served the parser the rest of the site was generated from. The
71
+ # JavaScript half of the package is generated by `rake templates`.
72
+ doc/playground: javascript/src/prism.wasm
73
+ $(ECHO) "building $@"
74
+ $(Q) $(MAKEDIRS) $@
75
+ $(Q) cp javascript/src/*.js javascript/src/prism.wasm javascript/package.json $@
76
+
77
+ java/wasm/src/main/wasm/prism.wasm: Makefile $(SOURCES) $(HEADERS)
78
+ $(ECHO) "building $@"
79
+ $(Q) $(MAKEDIRS) $(@D)
80
+ $(Q) $(WASI_SDK_PATH)/bin/clang \
81
+ $(DEBUG_FLAGS) \
82
+ -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN \
83
+ -lwasi-emulated-mman $(CPPFLAGS) $(JAVA_WASM_CFLAGS) \
84
+ -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi \
85
+ -o $@ $(SOURCES)
86
+
87
+ build/shared/%.o: src/%.c Makefile $(HEADERS)
88
+ $(ECHO) "compiling $@"
89
+ $(Q) $(MAKEDIRS) $(@D)
90
+ $(Q) $(CC) $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
91
+
92
+ build/static/%.o: src/%.c Makefile $(HEADERS)
93
+ $(ECHO) "compiling $@"
94
+ $(Q) $(MAKEDIRS) $(@D)
95
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
96
+
97
+ build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
98
+ $(ECHO) "building $* fuzzer"
99
+ $(Q) $(MAKEDIRS) $(@D)
100
+ $(ECHO) "building main fuzz binary"
101
+ $(Q) afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
102
+ $(ECHO) "building cmplog binary"
103
+ $(Q) AFL_LLVM_CMPLOG=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@.cmplog $^
104
+
105
+ build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
106
+ $(Q) afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
107
+
108
+ fuzz-debug:
109
+ $(ECHO) "entering debug shell"
110
+ $(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
111
+
112
+ fuzz-docker-build: fuzz/docker/Dockerfile
113
+ $(ECHO) "building docker image"
114
+ $(Q) docker build -t prism/fuzz fuzz/docker/
115
+
116
+ fuzz-run-%: FORCE fuzz-docker-build
117
+ $(ECHO) "generating templates"
118
+ $(Q) bundle exec rake templates
119
+ $(ECHO) "running $* fuzzer"
120
+ $(Q) docker run --rm -v $(CURDIR):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
121
+ $(ECHO) "starting AFL++ run"
122
+ $(Q) $(MAKEDIRS) $(FUZZ_OUTPUT_DIR)/$*
123
+ $(Q) docker run -it --rm -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
124
+ FORCE:
125
+
126
+ fuzz-clean:
127
+ $(Q) $(RMALL) fuzz/output
128
+
129
+ clean:
130
+ $(Q) $(RMALL) build
131
+
132
+ .PHONY: clean doc/playground fuzz-clean
133
+
134
+ all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
135
+ all-no-debug: OPTFLAGS := -O3
136
+ all-no-debug: all
137
+
138
+ minimal: CFLAGS := $(CFLAGS) -DPRISM_BUILD_MINIMAL
139
+ minimal: all
140
+
141
+ run: Makefile $(STATIC_OBJECTS) $(HEADERS) test.c
142
+ $(ECHO) "compiling test.c"
143
+ $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) $(STATIC_OBJECTS) test.c
144
+ $(ECHO) "running test.c"
145
+ $(Q) ./a.out
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ <h1 align="center">Prism</h1>
2
+
3
+ This is a parser for the Ruby programming language. It is designed to be portable, error tolerant, and maintainable. It is written in C99 and has no dependencies.
4
+
5
+ ## Getting started
6
+
7
+ To compile the parser, you will need:
8
+
9
+ * C99 compiler
10
+ * GNU make
11
+ * Ruby 2.7.0 or later
12
+
13
+ Once you have these dependencies, run:
14
+
15
+ ```
16
+ bundle install
17
+ ```
18
+
19
+ to fetch the Ruby dependencies. Finally, run:
20
+
21
+ ```
22
+ bundle exec rake compile
23
+ ```
24
+
25
+ to compile the parser. It will be built in the `build` directory. To test that everything is working, run:
26
+
27
+ ```
28
+ bin/parse -e "1 + 2"
29
+ ```
30
+
31
+ to see the syntax tree for the expression `1 + 2`.
32
+
33
+ ## Overview
34
+
35
+ The repository contains the infrastructure for both a shared library (libprism) and a native CRuby extension. The shared library has no bindings to CRuby itself, and so can be used by other projects. The native CRuby extension links against `ruby.h`, and so is suitable in the context of CRuby.
36
+
37
+ ```
38
+ .
39
+ ├── Makefile configuration to compile the shared library and native tests
40
+ ├── Rakefile configuration to compile the native extension and Ruby tests
41
+ ├── bin
42
+ │   ├── lex runs the lexer on a file or string and prints the tokens
43
+ │   ├── parse runs the parse on a file or string and prints the AST
44
+ │   └── prism a CLI for development and debugging
45
+ ├── config.yml specification for tokens and nodes in the tree
46
+ ├── doc documentation website
47
+ ├── docs markdown documentation about the project
48
+ ├── ext
49
+ │   └── prism
50
+ │   ├── extconf.rb configuration to generate the Makefile for the native extension
51
+ │   └── extension.c the native extension that interacts with libprism
52
+ ├── fuzz files related to fuzz testing
53
+ ├── gemfiles gemfiles used by different Ruby versions in CI
54
+ ├── include
55
+ │   ├── prism header files for the shared library
56
+ │   └── prism.h main header file for the shared library
57
+ ├── java
58
+ | ├── api Java API for Prism
59
+ | ├── native Java native bindings for the shared library
60
+ | └── wasm Java WASM bindings for the shared library
61
+ ├── javascript JavaScript WASM bindings for the shared library
62
+ ├── lib
63
+ │   ├── prism Ruby library files
64
+ │   └── prism.rb main entrypoint for the Ruby library
65
+ ├── rakelib various Rake tasks for the project
66
+ ├── rbi RBI type signatures for the Ruby library
67
+ ├── rust
68
+ │   ├── ruby-prism Rustified crate for the shared library
69
+ │   └── ruby-prism-sys FFI binding for Rust
70
+ ├── sample
71
+ │ └── prism Sample code that uses the Ruby API for documentation purposes
72
+ ├── sig RBS type signatures for the Ruby library
73
+ ├── src
74
+ │   └── prism.c main entrypoint for the shared library
75
+ ├── templates contains ERB templates generated by templates/template.rb
76
+ │   └── template.rb generates code from the nodes and tokens configured by config.yml
77
+ └── test
78
+ └── prism
79
+ ├── fixtures Ruby code used for testing
80
+ └── snapshots snapshots of generated syntax trees corresponding to fixtures
81
+ ```