Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support escaped named arguments #1103

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { RSymbol } from '../../../../model/nodes/r-symbol';
import { RawRType, RType } from '../../../../model/type';
import { normalizeSingleNode } from '../structure/normalize-single-node';
import type { NamedJsonEntry } from '../../../json/format';
import { startAndEndsWith } from '../../../../../../../util/strings';


/**
Expand Down Expand Up @@ -38,7 +39,7 @@ export function tryToNormalizeArgument(data: NormalizerData, objs: readonly Name
name = {
type: RType.Symbol,
location,
content: symbolOrExpr.name === RawRType.StringConst ? content.slice(1,-1) : content,
content: symbolOrExpr.name === RawRType.StringConst ? content.slice(1,-1) : (startAndEndsWith(content, '`') ? content.slice(1, -1) : content),
namespace: undefined,
lexeme: content,
info: {
Expand Down
109 changes: 48 additions & 61 deletions test/functionality/r-bridge/lang/ast/parse-function-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,67 +193,54 @@ describe('Parse function calls', withShell(shell => {
],
})
);
assertAst(label('string arguments', ['name-normal', 'call-normal', 'string-arguments', 'strings']),
shell,'f("a"=3,\'x\'=2)',
exprList({
type: RType.FunctionCall,
named: true,
location: rangeFrom(1, 1, 1, 1),
lexeme: 'f',
info: {},
functionName: {
type: RType.Symbol,
location: rangeFrom(1, 1, 1, 1),
lexeme: 'f',
content: 'f',
namespace: undefined,
info: {}
},
arguments: [
{
type: RType.Argument,
location: rangeFrom(1, 3, 1, 5),
name: {
type: RType.Symbol,
location: rangeFrom(1, 3, 1, 5),
lexeme: '"a"',
content: 'a',
namespace: undefined,
info: {}
},
lexeme: '"a"',
info: {},
value: {
type: RType.Number,
location: rangeFrom(1, 7, 1, 7),
lexeme: '3',
content: numVal(3),
info: {}
}
},
{
type: RType.Argument,
location: rangeFrom(1, 9, 1, 11),
name: {
type: RType.Symbol,
location: rangeFrom(1, 9, 1, 11),
lexeme: '\'x\'',
content: 'x',
namespace: undefined,
info: {}
},
lexeme: '\'x\'',
info: {},
value: {
type: RType.Number,
location: rangeFrom(1, 13, 1, 13),
lexeme: '2',
content: numVal(2),
info: {}
}
}
],
}));
for(const quote of ['"', "'", '`']) {
describe(`Escaped Arguments Using Quote ${quote}`, () => {
for(const firstArgName of ['a', 'a b', 'a(1)']) {
const argLength = firstArgName.length;
const arg = `${quote}${firstArgName}${quote}`;
assertAst(label(`${firstArgName}`, ['name-normal', 'call-normal', 'string-arguments', 'strings']),
shell, `f(${arg}=3)`,
exprList({
type: RType.FunctionCall,
named: true,
location: rangeFrom(1, 1, 1, 1),
lexeme: 'f',
info: {},
functionName: {
type: RType.Symbol,
location: rangeFrom(1, 1, 1, 1),
lexeme: 'f',
content: 'f',
namespace: undefined,
info: {}
},
arguments: [
{
type: RType.Argument,
location: rangeFrom(1, 3, 1, 4 + argLength),
name: {
type: RType.Symbol,
location: rangeFrom(1, 3, 1, 4 + argLength),
lexeme: arg,
content: firstArgName,
namespace: undefined,
info: {}
},
lexeme: arg,
info: {},
value: {
type: RType.Number,
location: rangeFrom(1, 4 + argLength + 2, 1, 4 + argLength + 2),
lexeme: '3',
content: numVal(3),
info: {}
}
}
]
}));
}
});
}
});
describe('directly called functions', () => {
assertAst(label('Directly call with 2', ['call-anonymous', 'formals-named', 'numbers', 'name-normal', 'normal-definition', 'grouping']),
Expand Down
Loading