yarp 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +76 -0
  3. data/CONTRIBUTING.md +51 -0
  4. data/LICENSE.md +7 -0
  5. data/Makefile.in +79 -0
  6. data/README.md +86 -0
  7. data/config.h.in +25 -0
  8. data/config.yml +2147 -0
  9. data/configure +4487 -0
  10. data/docs/build_system.md +85 -0
  11. data/docs/building.md +26 -0
  12. data/docs/configuration.md +56 -0
  13. data/docs/design.md +53 -0
  14. data/docs/encoding.md +116 -0
  15. data/docs/extension.md +20 -0
  16. data/docs/fuzzing.md +93 -0
  17. data/docs/heredocs.md +36 -0
  18. data/docs/mapping.md +117 -0
  19. data/docs/ripper.md +36 -0
  20. data/docs/serialization.md +130 -0
  21. data/docs/testing.md +55 -0
  22. data/ext/yarp/api_node.c +3680 -0
  23. data/ext/yarp/api_pack.c +256 -0
  24. data/ext/yarp/extconf.rb +131 -0
  25. data/ext/yarp/extension.c +547 -0
  26. data/ext/yarp/extension.h +18 -0
  27. data/include/yarp/ast.h +1412 -0
  28. data/include/yarp/defines.h +54 -0
  29. data/include/yarp/diagnostic.h +24 -0
  30. data/include/yarp/enc/yp_encoding.h +94 -0
  31. data/include/yarp/node.h +36 -0
  32. data/include/yarp/pack.h +141 -0
  33. data/include/yarp/parser.h +389 -0
  34. data/include/yarp/regexp.h +19 -0
  35. data/include/yarp/unescape.h +42 -0
  36. data/include/yarp/util/yp_buffer.h +39 -0
  37. data/include/yarp/util/yp_char.h +75 -0
  38. data/include/yarp/util/yp_constant_pool.h +64 -0
  39. data/include/yarp/util/yp_list.h +67 -0
  40. data/include/yarp/util/yp_memchr.h +14 -0
  41. data/include/yarp/util/yp_newline_list.h +54 -0
  42. data/include/yarp/util/yp_state_stack.h +24 -0
  43. data/include/yarp/util/yp_string.h +57 -0
  44. data/include/yarp/util/yp_string_list.h +28 -0
  45. data/include/yarp/util/yp_strpbrk.h +29 -0
  46. data/include/yarp/version.h +5 -0
  47. data/include/yarp.h +69 -0
  48. data/lib/yarp/lex_compat.rb +759 -0
  49. data/lib/yarp/node.rb +7428 -0
  50. data/lib/yarp/pack.rb +185 -0
  51. data/lib/yarp/ripper_compat.rb +174 -0
  52. data/lib/yarp/serialize.rb +389 -0
  53. data/lib/yarp.rb +330 -0
  54. data/src/diagnostic.c +25 -0
  55. data/src/enc/yp_big5.c +79 -0
  56. data/src/enc/yp_euc_jp.c +85 -0
  57. data/src/enc/yp_gbk.c +88 -0
  58. data/src/enc/yp_shift_jis.c +83 -0
  59. data/src/enc/yp_tables.c +509 -0
  60. data/src/enc/yp_unicode.c +2320 -0
  61. data/src/enc/yp_windows_31j.c +83 -0
  62. data/src/node.c +2011 -0
  63. data/src/pack.c +493 -0
  64. data/src/prettyprint.c +1782 -0
  65. data/src/regexp.c +580 -0
  66. data/src/serialize.c +1576 -0
  67. data/src/token_type.c +347 -0
  68. data/src/unescape.c +576 -0
  69. data/src/util/yp_buffer.c +78 -0
  70. data/src/util/yp_char.c +229 -0
  71. data/src/util/yp_constant_pool.c +147 -0
  72. data/src/util/yp_list.c +50 -0
  73. data/src/util/yp_memchr.c +31 -0
  74. data/src/util/yp_newline_list.c +119 -0
  75. data/src/util/yp_state_stack.c +25 -0
  76. data/src/util/yp_string.c +207 -0
  77. data/src/util/yp_string_list.c +32 -0
  78. data/src/util/yp_strncasecmp.c +20 -0
  79. data/src/util/yp_strpbrk.c +66 -0
  80. data/src/yarp.c +13211 -0
  81. data/yarp.gemspec +100 -0
  82. metadata +125 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 51ee2a88319b74a9937ab37fbaa9bb71586caf26a8f31282c2d2431735a484b6
4
+ data.tar.gz: efe7ac9662cd199e3ba0c8a00f913912a2830843bc0c87cdfc3b258d724eafd8
5
+ SHA512:
6
+ metadata.gz: 535d2f88c7ff324dbbc0e94dce1e4356125e1b08367c247c48cb083a00dccd997bf3bb73f4534effd8c6797373a588c0e76f6782e60afc36933c21a50b8f9900
7
+ data.tar.gz: 1e9f92c56e9863d076b0ade0e82917a0e8df50063337d51cda1b9a8df1ea5bdc858b1b153179fd189eaabe313cff8e34213b68daad4488658316cd1dc077eedc
@@ -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,51 @@
1
+ # Contributing
2
+
3
+ Thank you for your interest in contributing to YARP! 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:yarp test
29
+ ```
30
+
31
+ ## Documentation
32
+
33
+ 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.
34
+
35
+ ## Developing
36
+
37
+ To get `clangd` support in the editor for development, generate the compilation database. This command will
38
+ create an ignored `compile_commands.json` file at the project root, which is used by clangd to provide functionality.
39
+
40
+ You will need `bear` which can be installed on macOS with `brew install bear`.
41
+
42
+ ```sh
43
+ bundle exec rake bear
44
+ ```
45
+
46
+ ## Debugging
47
+
48
+ Some useful rake tasks:
49
+
50
+ - `test:valgrind` runs the test suite under valgrind to look for illegal memory access or memory leaks
51
+ - `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.in ADDED
@@ -0,0 +1,79 @@
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 = $(shell pwd)/fuzz/output
10
+
11
+ SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12
+
13
+ DEFS := @DEFS@
14
+ CPPFLAGS := @DEFS@ -Iinclude
15
+ CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -fPIC -fvisibility=hidden
16
+ CC := @CC@
17
+
18
+ HEADERS := $(shell find include -name '*.h')
19
+ SOURCES := $(shell find src -name '*.c')
20
+ SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
21
+ STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
22
+
23
+ all: shared static
24
+
25
+ shared: build/librubyparser.$(SOEXT)
26
+ static: build/librubyparser.a
27
+
28
+ build/librubyparser.$(SOEXT): $(SHARED_OBJECTS)
29
+ $(ECHO) "linking $@"
30
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
31
+
32
+ build/librubyparser.a: $(STATIC_OBJECTS)
33
+ $(ECHO) "building $@"
34
+ $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
35
+
36
+ build/shared/%.o: src/%.c Makefile $(HEADERS)
37
+ $(ECHO) "compiling $@"
38
+ $(Q) mkdir -p $(@D)
39
+ $(Q) $(CC) $(DEBUG_FLAGS) -DYP_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
40
+
41
+ build/static/%.o: src/%.c Makefile $(HEADERS)
42
+ $(ECHO) "compiling $@"
43
+ $(Q) mkdir -p $(@D)
44
+ $(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
45
+
46
+ build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
47
+ $(ECHO) "building $* fuzzer"
48
+ $(ECHO) "building main fuzz binary"
49
+ $(Q) AFL_HARDEN=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
50
+ $(ECHO) "building cmplog binary"
51
+ $(Q) AFL_HARDEN=1 AFL_LLVM_CMPLOG=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@.cmplog $^
52
+
53
+ build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
54
+ $(Q) AFL_HARDEN=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
55
+
56
+ fuzz-debug:
57
+ $(ECHO) "entering debug shell"
58
+ $(Q) docker run -it --rm -e HISTFILE=/yarp/fuzz/output/.bash_history -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz
59
+
60
+ fuzz-docker-build: fuzz/docker/Dockerfile
61
+ $(ECHO) "building docker image"
62
+ $(Q) docker build -t yarp/fuzz fuzz/docker/
63
+
64
+ fuzz-run-%: FORCE fuzz-docker-build
65
+ $(ECHO) "running $* fuzzer"
66
+ $(Q) docker run --rm -v $(shell pwd):/yarp yarp/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
67
+ $(ECHO) "starting AFL++ run"
68
+ $(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
69
+ $(Q) docker run -it --rm -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
70
+ FORCE:
71
+
72
+ clean:
73
+ $(Q) rm -f -r build
74
+
75
+ .PHONY: clean
76
+
77
+ all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
78
+ all-no-debug: OPTFLAGS := -O3
79
+ all-no-debug: all
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Yet Another Ruby Parser
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. It is currently being integrated into [CRuby](https://github.com/ruby/ruby), [JRuby](https://github.com/jruby/jruby), [TruffleRuby](https://github.com/oracle/truffleruby), [Sorbet](https://github.com/sorbet/sorbet), and [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree).
4
+
5
+ ## Overview
6
+
7
+ The repository contains the infrastructure for both a shared library (librubyparser) 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.
8
+
9
+ ```
10
+ .
11
+ ├── Makefile.in configuration to compile the shared library and native tests
12
+ ├── Rakefile configuration to compile the native extension and run the Ruby tests
13
+ ├── bin
14
+ │   ├── lex runs the lexer on a file or string, prints the tokens, and compares to ripper
15
+ │   └── parse runs the parser on a file or string and prints the syntax tree
16
+ ├── config.yml specification for tokens and nodes in the tree
17
+ ├── configure.ac configuration to generate the Makefile
18
+ ├── docs documentation about the project
19
+ ├── ext
20
+ │   └── yarp
21
+ │   ├── extconf.rb configuration to generate the Makefile for the native extension
22
+ │   └── extension.c the native extension that interacts with librubyparser
23
+ ├── fuzz files related to fuzz testing
24
+ ├── include
25
+ │   ├── yarp header files for the shared library
26
+ │   └── yarp.h main header file for the shared library
27
+ ├── java Java bindings for the shared library
28
+ ├── lib
29
+ │   ├── yarp Ruby library files
30
+ │   └── yarp.rb main entrypoint for the Ruby library
31
+ ├── rakelib various Rake tasks for the project
32
+ ├── src
33
+ │   ├── enc various encoding files
34
+ │   ├── util various utility files
35
+ │   └── yarp.c main entrypoint for the shared library
36
+ ├── templates contains ERB templates generated by templates/template.rb
37
+ │   └── template.rb generates code from the nodes and tokens configured by config.yml
38
+ └── test
39
+    ├── fixtures Ruby code used for testing
40
+    └── snapshots snapshots of generated syntax trees corresponding to fixtures
41
+ ```
42
+
43
+ ## Getting started
44
+
45
+ To compile the shared library, you will need:
46
+
47
+ * A C99 compiler
48
+ * autotools (autoconf, automake, libtool)
49
+ * make
50
+ * Ruby 3.3.0-preview1 or later
51
+
52
+ Once you have these dependencies, run:
53
+
54
+ ```
55
+ bundle install
56
+ ```
57
+
58
+ to fetch the Ruby dependencies. Finally, run:
59
+
60
+ ```
61
+ rake compile
62
+ ```
63
+
64
+ to compile the shared library. It will be built in the `build` directory. To test that everything is working, run:
65
+
66
+ ```
67
+ bin/parse -e "1 + 2"
68
+ ```
69
+
70
+ to see the syntax tree for the expression `1 + 2`.
71
+
72
+ ## Contributing
73
+
74
+ See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. We additionally have documentation about the overall design of the project as well as various subtopics.
75
+
76
+ * [Building](docs/building.md)
77
+ * [Configuration](docs/configuration.md)
78
+ * [Design](docs/design.md)
79
+ * [Encoding](docs/encoding.md)
80
+ * [Extension](docs/extension.md)
81
+ * [Fuzzing](docs/fuzzing.md)
82
+ * [Heredocs](docs/heredocs.md)
83
+ * [Mapping](docs/mapping.md)
84
+ * [Ripper](docs/ripper.md)
85
+ * [Serialization](docs/serialization.md)
86
+ * [Testing](docs/testing.md)
data/config.h.in ADDED
@@ -0,0 +1,25 @@
1
+ /* config.h.in. Generated from configure.ac by autoheader. */
2
+
3
+ /* Define to 1 if you have the `mmap' function. */
4
+ #undef HAVE_MMAP
5
+
6
+ /* Define to 1 if you have the `snprintf' function. */
7
+ #undef HAVE_SNPRINTF
8
+
9
+ /* Define to the address where bug reports for this package should be sent. */
10
+ #undef PACKAGE_BUGREPORT
11
+
12
+ /* Define to the full name of this package. */
13
+ #undef PACKAGE_NAME
14
+
15
+ /* Define to the full name and version of this package. */
16
+ #undef PACKAGE_STRING
17
+
18
+ /* Define to the one symbol short name of this package. */
19
+ #undef PACKAGE_TARNAME
20
+
21
+ /* Define to the home page for this package. */
22
+ #undef PACKAGE_URL
23
+
24
+ /* Define to the version of this package. */
25
+ #undef PACKAGE_VERSION