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

Normalize V2: Adapt remaining access tests #598

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
15 changes: 8 additions & 7 deletions src/r-bridge/lang-4.x/ast/parser/xml/v2/internal/access.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { XmlBasedJson, XmlParseError } from '../../common/input-format'
import { getTokenType, retrieveMetaStructure } from '../../common/meta'
import { RType, RNode, RArgument, RawRType, RFunctionCall } from '../../../../model'
import { RType, RNode, RawRType, RFunctionCall } from '../../../../model'
import { guard } from '../../../../../../../util/assert'
import { splitArrayOn } from '../../../../../../../util/arrays'
import { NormalizeConfiguration } from '../data'
import { normalizeSingleToken } from './single-element'
import { tryToNormalizeArgument } from './functions/argument'
import {InternalScope} from './internal'

/**
* Normalize the given data as access (e.g., indexing).
Expand Down Expand Up @@ -53,8 +54,7 @@ export function normalizeAccess(configuration: NormalizeConfiguration, tokens: r
flavor: 'named',
functionName: {
type: RType.Symbol,
// TODO: just lock "internal" here
namespace: undefined,
namespace: InternalScope,
lexeme: content,
info: {},
content,
Expand All @@ -70,7 +70,9 @@ export function normalizeAccess(configuration: NormalizeConfiguration, tokens: r
// otherwise we have to process
const remaining: readonly XmlBasedJson[] = tokens.slice(2, tokens.length - closingLength)

const splitAccessOnComma = splitArrayOn(remaining, elem => elem.name === RawRType.Comma)
const splitAccessOnComma = splitArrayOn(remaining, elem =>
getTokenType(configuration.tokenMap, elem) === RawRType.Comma
)

const parsedAccess: (RNode | undefined)[] = splitAccessOnComma.map((elems: readonly XmlBasedJson[]) =>
elems.length === 0 ? undefined : normalizeAccessArgument(configuration, elems)
Expand All @@ -84,8 +86,7 @@ export function normalizeAccess(configuration: NormalizeConfiguration, tokens: r
flavor: 'named',
functionName: {
type: RType.Symbol,
// TODO: just lock "internal" here
namespace: undefined,
namespace: InternalScope,
lexeme: content,
info: {},
content,
Expand All @@ -100,7 +101,7 @@ export function normalizeAccess(configuration: NormalizeConfiguration, tokens: r
}


function normalizeAccessArgument(config: NormalizeConfiguration, elements: readonly XmlBasedJson[]): RArgument {
function normalizeAccessArgument(config: NormalizeConfiguration, elements: readonly XmlBasedJson[]): RNode {
const res = tryToNormalizeArgument(config, elements)
guard(res !== undefined, () => `expected one access result in access as argument, yet received ${JSON.stringify(res)} for ${JSON.stringify(elements)}`)
return res
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { XmlBasedJson, XmlParseError } from '../../../common/input-format'
import { getTokenType, retrieveMetaStructure } from '../../../common/meta'
import { RNode, RType, RSymbol, RArgument, RawRType } from '../../../../../model'
import { RNode, RType, RSymbol, RawRType } from '../../../../../model'
import { NormalizeConfiguration } from '../../data'
import { log } from '../../../../../../../../util/log'
import { guard } from '../../../../../../../../util/assert'
Expand All @@ -16,7 +16,7 @@
*
* @returns The parsed argument or `undefined` if the given object is not an argument.
*/
export function tryToNormalizeArgument(configuration: NormalizeConfiguration, objs: readonly XmlBasedJson[]): RArgument | undefined {
export function tryToNormalizeArgument(configuration: NormalizeConfiguration, objs: readonly XmlBasedJson[]): RNode | undefined {
if(objs.length < 1 || objs.length > 3) {
log.warn(`Either [expr|value], [SYMBOL_SUB, EQ_SUB], or [SYMBOL_SUB, EQ_SUB, expr], but got: ${objs.map(o => JSON.stringify(o)).join(', ')}`)
return undefined
Expand Down Expand Up @@ -51,16 +51,20 @@

guard(parsedValue !== undefined && parsedValue?.type !== RType.Delimiter, () => `[argument] parsed value must not be undefined, yet: ${JSON.stringify(objs)}`)

return {
type: RType.Argument,
location,
lexeme: content,
name,
value: parsedValue ?? undefined,
info: {
fullRange: location,
fullLexeme: content,
additionalTokens: []
if(name === undefined) {
return parsedValue ?? undefined
} else {
return {

Check warning on line 57 in src/r-bridge/lang-4.x/ast/parser/xml/v2/internal/functions/argument.ts

View check run for this annotation

Codecov / codecov/patch

src/r-bridge/lang-4.x/ast/parser/xml/v2/internal/functions/argument.ts#L57

Added line #L57 was not covered by tests
type: RType.Argument,
location,
lexeme: content,
name,
value: parsedValue ?? undefined,
info: {
fullRange: location,
fullLexeme: content,
additionalTokens: []
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const InternalScope = '.$internal'
Loading