summaryrefslogtreecommitdiff
path: root/prism
AgeCommit message (Collapse)Author
2024-03-27[PRISM] Include file and line in error messageKevin Newton
2024-03-27[ruby/prism] Add option for inlining messages for error formattingKevin Newton
https://github.com/ruby/prism/commit/af0204a8ab
2024-03-27[PRISM] Fix up some error formatting edge casesKevin Newton
2024-03-26[ruby/prism] Fix an incorrect range of `Prism::Location` when ↵Koichi ITO
`PM_ERR_RETURN_INVALID` This PR fixes the following incorrect range of `Prism::Location` when `PM_ERR_RETURN_INVALID`. It may be hard to tell from the text, but this Ruby error highlights `return`: ```console $ ruby -e 'class Foo return end' -e:1: Invalid return in class/module body class Foo return end -e: compile error (SyntaxError) ``` Previously, the error's `Prism::Location` pointed to `end`: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("class Foo return end").errors' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:return_invalid @message="invalid `return` in a class or module body" @location=#<Prism::Location @start_offset=17 @length=3 start_line=1> @level=:fatal>] After this fix, it will indicate `return`. ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.parse("class Foo return end").errors' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:return_invalid @message="invalid `return` in a class or module body" @location=#<Prism::Location @start_offset=10 @length=6 start_line=1> @level=:fatal>] ``` For reference, here are the before and after of `Prism::Translation::Parser`. Before: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("class Foo return end")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] (string):1:18: error: invalid `return` in a class or module body (string):1: class Foo return end (string):1: ^~~ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72:in `process': invalid `return` in a class or module body (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:220:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` After: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("class Foo return end")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] (string):1:11: error: invalid `return` in a class or module body (string):1: class Foo return end (string):1: ^~~~~~ /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/diagnostic/engine.rb:72:in `process': invalid `return` in a class or module body (Parser::SyntaxError) from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:220:in `block in unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `each' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:218:in `unwrap' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:49:in `parse' from /Users/koic/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/parser-3.3.0.5/lib/parser/base.rb:33:in `parse' from -e:1:in `<main>' ``` This PR ensures that the originally intended `return` is highlighted as it should be. https://github.com/ruby/prism/commit/1f9af4d2ad
2024-03-26[ruby/prism] Properly handle freeing ephemeral node listsKevin Newton
https://github.com/ruby/prism/commit/f49261a9b9
2024-03-26[ruby/prism] Handle regexp split between heredocsKevin Newton
https://github.com/ruby/prism/commit/c1400d8aed
2024-03-26[ruby/prism] Freeze internal parts, againKevin Newton
https://github.com/ruby/prism/commit/50372fee5c
2024-03-26[ruby/prism] Fix typosKoichi ITO
After finding the "if if" typo, some additional typos identified by running `codespell` are also being corrected: https://github.com/codespell-project/codespell https://github.com/ruby/prism/commit/e6a34cfeeb
2024-03-25[ruby/prism] Revert "Frozen parts"Kevin Newton
https://github.com/ruby/prism/commit/48f2e8c169
2024-03-25[ruby/prism] Mark interpolated nodes as static literalKevin Newton
https://github.com/ruby/prism/commit/d00977a9bd
2024-03-25[ruby/prism] Mark inner parts of interpolated* nodes as frozenKevin Newton
https://github.com/ruby/prism/commit/58a127cd5d
2024-03-25[ruby/prism] Fix up minimal build settingKevin Newton
https://github.com/ruby/prism/commit/98c85c4acb
2024-03-25[ruby/prism] Handle CLRF in regexpKevin Newton
https://github.com/ruby/prism/commit/b96bada9ae
2024-03-25[ruby/prism] Refactor regexp lexing to make it easier to support CLRFKevin Newton
https://github.com/ruby/prism/commit/60805d85ca
2024-03-25[ruby/prism] Handle CLRF inside string contentsKevin Newton
https://github.com/ruby/prism/commit/aac606301e
2024-03-25[ruby/prism] Handle CLRF inside heredoc contentsKevin Newton
https://github.com/ruby/prism/commit/1fbac72485
2024-03-25[ruby/prism] Fix build error for C99 and C23 CI matrixKoichi ITO
This PR fixes the following build error for C99 and C23 Ruby's CI matrix: ```console ../src/prism/prism.c:1241:19: error: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] 1241 | char *word = unknown_flags_length >= 2 ? "options" : "option"; | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assembling ../src/coroutine/amd64/Context.S ``` - c99 ... https://github.com/ruby/ruby/actions/runs/8419905079/job/23053543994#step:10:249 - c23 ... https://github.com/ruby/ruby/actions/runs/8419905079/job/23053544274#step:10:257 This is an incorrect code introduced in https://github.com/ruby/prism/pull/2618. https://github.com/ruby/prism/commit/4d9d73fcb9
2024-03-25[ruby/prism] Add missing symbol in comment for binding powers for `||=`Franck Trouillez
This adds in the descriptive comment the `||=` operator corresponding to `PM_TOKEN_PIPE_PIPE_EQUAL` for pm_binding_powers[PM_TOKEN_MAXIMUM] in prism.c https://github.com/ruby/prism/commit/315ca16e23
2024-03-25[ruby/prism] Fix comment typos in prism.cFranck Trouillez
This fixes some comment typos in English in the prism.c file. It fixes some typos and follows the current conventions: - Sentences in comments end with `.` - Use infinitive instead of 3rd person present simple to describe functions https://github.com/ruby/prism/commit/01324e89db
2024-03-25[ruby/prism] Fix incorrect paring when using invalid regexp optionsKoichi ITO
Fixes https://github.com/ruby/prism/pull/2617. There was an issue with the lexer as follows. The following are valid regexp options: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/io").value.map {|token| token[0].type }' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :EOF] ``` The following are invalid regexp options. Unnecessary the `IDENTIFIER` token is appearing: ```console $ bundle exec ruby -Ilib -rprism -ve 'p Prism.lex("/x/az").value.map {|token| token[0].type }' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [:REGEXP_BEGIN, :STRING_CONTENT, :REGEXP_END, :IDENTIFIER, :EOF] ``` As a behavior of Ruby, when given `A` to `Z` and `a` to `z`, they act as invalid regexp options. e.g., ```console $ ruby -e '/regexp/az' -e:1: unknown regexp options - az /regexp/az -e: compile error (SyntaxError) ``` Thus, it should probably not be construed as `IDENTIFIER` token. Therefore, `pm_byte_table` has been adapted to accept those invalid regexp option values. Whether it is a valid regexp option or not is checked by `pm_regular_expression_flags_create`. For invalid regexp options, `PM_ERR_REGEXP_UNKNOWN_OPTIONS` is added to diagnostics. https://github.com/ruby/prism/commit/d2a6096fcf
2024-03-20[ruby/prism] Provide options for reducing sizeKevin Newton
https://github.com/ruby/prism/commit/592128de4d
2024-03-19[ruby/prism] Fix a diagnostic incompatibilityKoichi ITO
This PR fixes a diagnostic incompatibility when using no anonymous keyword rest parameter: ```ruby foo(**) ``` Note, although the actual update applies only to the `foo(**)` case, for reference, `foo(*)` and `foo(&) are also mentioned below. ## Ruby (Expected) ```console $ ruby -cve 'foo(*)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous rest parameter -e: compile error (SyntaxError) $ ruby -cve 'foo(**)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous keyword rest parameter -e: compile error (SyntaxError) $ ruby -cve 'foo(&)' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] -e:1: no anonymous block parameter -e: compile error (SyntaxError) ``` ## Prism (Actual) Before: ```console $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(*)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star @message="unexpected `*` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(**)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:expect_expression_after_splat_hash @message="expected an expression after `**` in a hash" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(&)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_amp @message="unexpected `&` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] ``` After: ```console $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(*)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star @message="unexpected `*` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(**)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_star_star @message="unexpected `**` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:fatal>] $ bundle exec ruby -Ilib -rprism -wve 'p Prism.parse("foo(&)").errors' ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseError @type=:argument_no_forwarding_amp @message="unexpected `&` when the parent method is not forwarding" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:fatal>] ``` https://github.com/ruby/prism/commit/633c9d9fd4
2024-03-19[ruby/prism] [Compatibility] Improve printf formatHASUMI Hitoshi
For better compatibility, this patch suggests using __MINGW_PRINTF_FORMAT that GCC provides for MINGW environment. https://github.com/ruby/prism/commit/a3a792b64f
2024-03-18[ruby/prism] Warn on frozen_string_literal after tokensKevin Newton
https://github.com/ruby/prism/commit/edece87801
2024-03-18[ruby/prism] CRuby error message for lonely elseKevin Newton
https://github.com/ruby/prism/commit/1219a709e4
2024-03-18[ruby/prism] Use `require_relative` in the Prism codebaseKoichi ITO
If there are many searches in the `$LOAD_PATH` in the user environment, require will perform unnecessary searches that are not needed. In contrast, `require_relative` is efficient because it uses a relative path. https://github.com/ruby/prism/commit/438ccc67bd
2024-03-15[ruby/prism] Add PM_STRING_FLAGS_FROZEN / PM_STRING_FLAGS_MUTABLE on ↵Jean Boussier
PM_SOURCE_FILE_NODE For all intent and purposes, `__FILE__` is a string literal subject to the `# frozen_string_literal: true/false` comment and to the global `--enable-frozen-string-literal / --disable-frozen-string-literal` CLI flags. https://github.com/ruby/prism/commit/7e33c92afd
2024-03-15[ruby/prism] Shareable constant nodesKevin Newton
https://github.com/ruby/prism/commit/473cfed6d0
2024-03-13[ruby/prism] Warn for maximum number variablesKevin Newton
https://github.com/ruby/prism/commit/2cdbf81c95
2024-03-13[ruby/prism] Only use e suffix for floats if followed by +, -, or digitKevin Newton
https://github.com/ruby/prism/commit/164de502c9
2024-03-13[PRISM] Remove ssize_t definition from prismKevin Newton
2024-03-13[ruby/prism] Remove ssize_t usageKevin Newton
https://github.com/ruby/prism/commit/64c4f1268b
2024-03-13[ruby/prism] FSL follow-upKevin Newton
https://github.com/ruby/prism/commit/097fd2a54f
2024-03-13[ruby/prism] Change `frozen_string_literal` to be a tri-stateJean Boussier
An explicit `false` is not equivalent to the comment being missing, because the default can be switched with a runtime flag: ```bash $ ruby --enable-frozen-string-literal -e 'p "foo".frozen?' true ``` https://github.com/ruby/prism/commit/4660f58775
2024-03-13[ruby/prism] Track parentheses in patternsKevin Newton
https://github.com/ruby/prism/commit/62db99f156
2024-03-13[ruby/prism] Warn `&` interpreted as argument prefixKoichi ITO
This PR makes `Prism` warn `&` interpreted as argument prefix. This carries a similar meaning to the following Ruby warning: ```console $ ruby -cwe "foo &bar" -e:1: warning: `&' interpreted as argument prefix Syntax OK ``` Previously, it did not issue a warning: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo &bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [] ``` From now on, it will issue a warning similar to Ruby's: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo &bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseWarning @type=:ambiguous_prefix_amp @message="ambiguous `&` has been interpreted as an argument prefix" @location=#<Prism::Location @start_offset=4 @length=1 start_line=1> @level=:verbose>] ``` https://github.com/ruby/prism/commit/312f99cd1e
2024-03-13[ruby/prism] Warn `**` interpreted as argument prefixKoichi ITO
This PR makes Prism warn `**` interpreted as argument prefix. This carries a similar meaning to the following Ruby warning: ```console $ ruby -cwe "foo **bar" -e:1: warning: `**' interpreted as argument prefix Syntax OK ``` Previously, it did not issue a warning: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo **bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [] ``` From now on, it will issue a warning similar to Ruby's: ```console $ bundle exec ruby -rprism -ve "p Prism.parse('foo **bar').warnings" ruby 3.3.0 (2023-12-25 revision https://github.com/ruby/prism/commit/5124f9ac75) [x86_64-darwin22] [#<Prism::ParseWarning @type=:ambiguous_prefix_star_star @message="ambiguous `**` has been interpreted as an argument prefix" @location=#<Prism::Location @start_offset=4 @length=2 start_line=1> @level=:verbose>] ``` https://github.com/ruby/prism/commit/f6cb5c314c
2024-03-13[ruby/prism] Allow newline before block localsKevin Newton
https://github.com/ruby/prism/commit/1d4df7d874
2024-03-12[ruby/prism] Move index tracking into a call node flagKevin Newton
https://github.com/ruby/prism/commit/2a2e216558
2024-03-12[ruby/prism] Add warning for chained comparisonsKevin Newton
https://github.com/ruby/prism/commit/f9f3620d44
2024-03-12[ruby/prism] Add whitespace warningsKevin Newton
https://github.com/ruby/prism/commit/01d137a0cb
2024-03-12[ruby/prism] Warnings for incorrect character literal syntaxKevin Newton
https://github.com/ruby/prism/commit/909508296e
2024-03-12[ruby/prism] Consolidate warnings for conditional predicatesKevin Newton
* Also add warnings for literals in predicates * Also create flip-flops in while/until https://github.com/ruby/prism/commit/a6b5c523c2
2024-03-12Define `ssize_t` on mswin buildNobuyoshi Nakada
2024-03-12[ruby/prism] Static literals inspectKevin Newton
https://github.com/ruby/prism/commit/4913d112da
2024-03-11[ruby/prism] Document `InstanceVariableWriteNode` fieldsmatthew healy
(https://github.com/ruby/prism/pull/2161) * Document InstanceVariableWriteNode fields * Reference lexing docs in name field documentation * Update config.yml --------- https://github.com/ruby/prism/commit/015b3a857e Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-03-11[ruby/prism] Document `ClassVariableWriteNode` fieldsmatthew healy
(https://github.com/ruby/prism/pull/2162) * Make ClassVariableWriteNode operator_loc non-nullable * Document ClassVariableWriteNode fields * Update config.yml --------- https://github.com/ruby/prism/commit/659b133888 Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2024-03-11[ruby/prism] Provide more documentation for pm_integer_parse_digit_valuesKevin Newton
https://github.com/ruby/prism/commit/c3fcb5031f
2024-03-11[ruby/prism] Stop crashing on invalid integersKevin Newton
https://github.com/ruby/prism/commit/afac2d6646
2024-03-11[ruby/prism] Support offsetKevin Newton
https://github.com/ruby/prism/commit/665f533373