Skip to content

Commit

Permalink
Allow Strings as Symbol-Names in Arguments (#502)
Browse files Browse the repository at this point in the history
feat: support strings as symbols when used as argument name
  • Loading branch information
EagleoutIce authored Nov 21, 2023
1 parent a99a7f8 commit 73ad957
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export function tryToNormalizeArgument(data: ParserData, objs: NamedXmlBasedJson
if(symbolOrExpr.name === RawRType.Expression) {
name = undefined
parsedValue = tryNormalizeSingleNode(data, symbolOrExpr)
} else if(symbolOrExpr.name === RawRType.SymbolSub) {
} else if(symbolOrExpr.name === RawRType.SymbolSub || symbolOrExpr.name === RawRType.StringConst) {
name = {
type: RType.Symbol,
location, content,
location,
content: symbolOrExpr.name === RawRType.StringConst ? content.slice(1,-1) : content,
namespace: undefined,
lexeme: content,
info: {
Expand Down
65 changes: 65 additions & 0 deletions test/functionality/r-bridge/lang/ast/parse-function-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,71 @@ describe('Parse function calls', withShell((shell) => {
],
})
)
const code = 'f("a"=3,\'x\'=2)'
assertAst(
`string arguments - ${code}`,
shell,
code,
exprList({
type: RType.FunctionCall,
flavor: 'named',
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: {}
}
}
],
})
)
})
describe('directly called functions', () => {
assertAst(
Expand Down

2 comments on commit 73ad957

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"artificial" Benchmark Suite

Benchmark suite Current: 73ad957 Previous: 243959c Ratio
Total per-file 3136.2815112727276 ms (3601.307170597766) 3190.570812409091 ms (3747.790963743062) 0.98
Retrieve AST from R code 66.69644581818181 ms (129.26249149995942) 68.74045054545455 ms (132.55959690808635) 0.97
Normalize R AST 93.84236736363636 ms (149.38992566482648) 96.19992009090909 ms (156.15063334620123) 0.98
Produce dataflow information 66.39288004545455 ms (168.13058075804264) 66.09041786363636 ms (169.92667998599904) 1.00
Total per-slice 1.8734408845595016 ms (1.3462662553095968) 1.8411702253695927 ms (1.267065280512554) 1.02
Static slicing 1.4104984189211314 ms (1.253224253828232) 1.3684034386686694 ms (1.1799623517395228) 1.03
Reconstruct code 0.44510725159934 ms (0.24537017466371341) 0.4553098527401606 ms (0.2299566392692304) 0.98
failed to reconstruct/re-parse 0 # 0 # NaN
times hit threshold 0 # 0 # NaN
reduction (characters) 0.7329390759026896 # 0.7329390759026896 # 1
reduction (normalized tokens) 0.720988345209971 # 0.720988345209971 # 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"social-science" Benchmark Suite

Benchmark suite Current: 73ad957 Previous: 243959c Ratio
Total per-file 5606.329659399999 ms (6258.591569511292) 5419.399718899999 ms (6111.491408384184) 1.03
Retrieve AST from R code 89.36035348 ms (81.22472916065955) 85.22318365999999 ms (79.41151212889127) 1.05
Normalize R AST 115.07335468000001 ms (71.11913153810005) 113.45254984 ms (69.72126242848063) 1.01
Produce dataflow information 170.07974118 ms (285.9734090034111) 164.38322226 ms (279.00889908327076) 1.03
Total per-slice 9.0320935229158 ms (14.814139202731969) 8.82827828085479 ms (14.575511768060265) 1.02
Static slicing 8.34484991848268 ms (14.71234271328453) 8.228727295296194 ms (14.45423896853327) 1.01
Reconstruct code 0.6765477354869578 ms (0.30766718466717596) 0.5898725311439794 ms (0.30780610835907124) 1.15
failed to reconstruct/re-parse 9 # 9 # 1
times hit threshold 967 # 967 # 1
reduction (characters) 0.898713819973478 # 0.8987761232201357 # 1.00
reduction (normalized tokens) 0.8579790415512589 # 0.8582032343145828 # 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.