Repository navigation
Read local foox' 1 as defining foo + x's value, not foo, and stop the AST formatter from splitting it to local foo x' 1 - #384
Merged
Merged
Conversation
…er from splitting it StataMP 18 defines foo3 for `local foo`x' 1` when x is 3. The parser split the name at the macro, so it emitted a macro_def named foo with value "`x' 1": Sight defined foo, and the AST formatter printed `local foo `x' 1`, which does define foo. The parser now reads a local/global name, and an extended function name, joined across touching macro references with the rule name-words.ts uses (moved to src/utils so the parser shares it). The macro_def keeps the whole name and gets name_parts; the analyzer and go-to-definition treat it as defining nothing. gen, egen, input, rename, confirm variable, scalar and matrix read their target names as words too, so `gen v`i' = 1` defines no variable v. sight parse --json: a macro's name is the name as written, with a new name_parts (null for a plain name); program args are words with name_parts. schema_version stays 1, agreed with do2r. Also accept a macro as an extended function's name (`local x : `ch'(scalars)`), which raised a false syntax error and broke the rest of the program.
The lexer splits 1bar into a number and a word, and neither is a macro, so local foo`x'1bar ended the name at foo`x'1, and tempvar t`x'1b defined b. Once a word has a macro reference, any touching name text continues it (StataMP 18: foo31bar, t31b).
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 42 minutes. View limit details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
local foo`x' 1definesfoo3whenxis 3, notfoo. Sight's parser split the name at the macro, producing amacro_defnamedfoowith value`x' 1. As a result, Sight definedfoo, and a later`foo'got no warning. The same split madegen v`i' = 1define a variablev,scalar sc`x' = 1a scalarsc, andsight parse --jsonlistargs a`x' bas three names.Formatter fix. The AST formatter printed
local foo`x' 1aslocal foo `x' 1, which does definefoowith value3 1, so formatting changed what the program did. It now prints the name unchanged in both modes.What changed
The parser reads a
local/globalname joined across touching macro references as one name. It uses the rule #382 added inname-words.ts, which moves tosrc/utils/so the parser and the analyzer share it. A quote ends the name. Once a name has a macro in it, touching letters and digits continue it (foo`x'1bar; the lexer splits1bar). Themacro_defkeeps the whole name (foo`x') and getsname_parts. The analyzer and go-to-definition treat such a name as defining nothing, and a later`foo'is still reported.gen,egen,input,rename,confirm variable,scalarandmatrixalso read their target names as words.The parser also accepts a macro as an extended function's name:
local s : `ch'(scalars)runse(scalars)whenchise, andlocal h : `what'names mrunsrownames. On main, this raised a false "Expected function name after colon" error and broke the rest of the program. Joined names exposed it on 3 more lines, so this PR fixes it. It clears the 425 false warnings indiscrim_estat_common.ado.Names that start with a macro (
local `x' 9,local `a'`b' 1) staycommandnodes, as before.sight parse --jsonschema_versionstays 1. The do2r maintainers agreed this is a bug fix, sincenamestill means the name as written.local foo`x' 1name: "foo",value: "x' 1"`name: "foox'",value: "1",name_parts: [text "foo", macro_ref`x']`local foo 1name: "foo"name: "foo",name_parts: nullargs a`x' b(programargs)a,`x',b{name: "ax'", name_parts: [...]},{name: "b", name_parts: null}`gen v`i' = 1varlistalready hadv`i'withpartslocal s : `ch'(scalars)extended: {function: "ch'", args: "(scalars)"}`name_partsuses the sametextandmacro_refobjects as a varlist'spartsand a macro'svalue_parts. A non-nullname_partsmeans the name can't be resolved statically. docs/cli.md describes it. The golden fixture haslocal,global,: fcn,= exp,++,#delimit ;,argsandgencases.Corpus:
sight checkover Stata 18's 3,780 base adosdiscrim_estat_common,storedresults,mkassertandds_utilno longer lose the rest of a program to a false parse error.local trace`nth'opts,local any`i',local opts`i', andaligninmkassert).discrim_estat_common:2474:`subcmd'really is undefined inChkIfEVars. Main never parsed that far.mfp_10:395:his first set at line 416, later in the loop. Main hid this with the falselocal h`i'at line 159.dvech:90andmgarch_dvech:83come from a separate gap (below).local constant`i' `constant'used to defineconstantitself.Found, not fixed
syntax [, noCONStant]defines`constant'in Stata, but Sight registers nothing for it, and 525 base-adosyntaxlines use anooption.UNDEFINED_VARIABLEis never turned on outside tests:undefinedVariableinsight.tomldoesn't reach the analyzer. Item 3's variable fixes show in completion, hover, references and the outline, not in diagnostics.extract_confirm_variablelowercasesvariable/varbefore comparing, against the exact-case rule.Proof: StataMP 18 on voyager defines
foo3,foo3bar,foo7(${g}and$g),gg3,q33(quote ends the name),a3/bfor args,v2/e2/sc3/w2and nov/sc,foo31barandt31b, and accepts: `ch'(scalars). 31 of the 40 new tests fail on main (parser, analyzer, providers, and the AST formatter mode); the 9 that pass are guards and source-preserving formatter cases. The golden fixture's expected output differs on main. All four gates pass. The corpus result is above.Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in T3 Code (Claude Code harness), reviewed by gpt-6.1-sol in Codex.