fix parsing of RecordExpressions
This commit is contained in:
parent
2f77b3fb5a
commit
5e9a34e642
@ -10,9 +10,13 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
|
"nodemon": "^3.1.0",
|
||||||
"peggy": "^4.0.0",
|
"peggy": "^4.0.0",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"prettier-plugin-pegjs": "^2.0.2",
|
"prettier-plugin-pegjs": "^2.0.2",
|
||||||
"ts-pegjs": "^4.2.1"
|
"ts-pegjs": "^4.2.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"watch-test": "nodemon -e ts,cps --exec 'bun test'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,13 +172,13 @@ PrimitiveOperationExpression
|
|||||||
RecordExpressionTuple
|
RecordExpressionTuple
|
||||||
= LPAREN
|
= LPAREN
|
||||||
_?
|
_?
|
||||||
variable:VarStatement
|
value:Value
|
||||||
_?
|
_?
|
||||||
COMMA
|
COMMA
|
||||||
_?
|
_?
|
||||||
offset:OffsetStatement
|
offset:OffsetStatement
|
||||||
_?
|
_?
|
||||||
RPAREN { return { variable, offset }; }
|
RPAREN { return { value, offset }; }
|
||||||
|
|
||||||
RecordExpressionTupleList
|
RecordExpressionTupleList
|
||||||
= LBRACKET
|
= LBRACKET
|
||||||
@ -202,7 +202,7 @@ RecordExpression
|
|||||||
_?
|
_?
|
||||||
COMMA
|
COMMA
|
||||||
_?
|
_?
|
||||||
address:Literal
|
address:Identifier
|
||||||
_?
|
_?
|
||||||
COMMA
|
COMMA
|
||||||
_?
|
_?
|
||||||
|
@ -2,5 +2,6 @@ export * from './generate';
|
|||||||
export * from './parser';
|
export * from './parser';
|
||||||
import * as peggy from './parser';
|
import * as peggy from './parser';
|
||||||
|
|
||||||
export const peggyParse = (source: string): peggy.ContinuationExpression[] =>
|
export const peggyParse = (source: string): peggy.ContinuationExpression[] => {
|
||||||
peggy.parse(source);
|
return peggy.parse(source);
|
||||||
|
};
|
||||||
|
@ -473,8 +473,8 @@ function peg$parse(input, options) {
|
|||||||
};
|
};
|
||||||
};// @ts-ignore
|
};// @ts-ignore
|
||||||
|
|
||||||
var peg$f11 = function(variable, offset) {// @ts-ignore
|
var peg$f11 = function(value, offset) {// @ts-ignore
|
||||||
return { variable, offset }; };// @ts-ignore
|
return { value, offset }; };// @ts-ignore
|
||||||
|
|
||||||
var peg$f12 = function(records, lastRecord) {
|
var peg$f12 = function(records, lastRecord) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -2588,7 +2588,7 @@ peg$parseRecordExpressionTuple() {
|
|||||||
s2 = null;
|
s2 = null;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
s3 = peg$parseVarStatement();
|
s3 = peg$parseValue();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (s3 !== peg$FAILED) {
|
if (s3 !== peg$FAILED) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -2879,7 +2879,7 @@ peg$parseRecordExpression() {
|
|||||||
s8 = null;
|
s8 = null;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
s9 = peg$parseLiteral();
|
s9 = peg$parseIdentifier();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (s9 !== peg$FAILED) {
|
if (s9 !== peg$FAILED) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -5372,15 +5372,12 @@ export type PrimitiveOperationExpression = {
|
|||||||
continuations: ContinuationList;
|
continuations: ContinuationList;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export type RecordExpressionTuple = {
|
export type RecordExpressionTuple = { value: Value; offset: OffsetStatement };
|
||||||
variable: VarStatement;
|
|
||||||
offset: OffsetStatement;
|
|
||||||
};
|
|
||||||
export type RecordExpressionTupleList = any[];
|
export type RecordExpressionTupleList = any[];
|
||||||
export type RecordExpression = {
|
export type RecordExpression = {
|
||||||
record: {
|
record: {
|
||||||
records: RecordExpressionTupleList;
|
records: RecordExpressionTupleList;
|
||||||
address: Literal;
|
address: Identifier;
|
||||||
body: ContinuationExpression;
|
body: ContinuationExpression;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -45,3 +45,10 @@ test('Application of identity function', async () => {
|
|||||||
const result = await evaluate(ast, testingLogger);
|
const result = await evaluate(ast, testingLogger);
|
||||||
expect(result).toEqual({ type: 'int', value: 3 });
|
expect(result).toEqual({ type: 'int', value: 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Record construction', async () => {
|
||||||
|
const ast = peggyParse(await TestPrograms.RecordConstruction);
|
||||||
|
|
||||||
|
const result = await evaluate(ast, testingLogger);
|
||||||
|
expect(result).toEqual({ type: 'int', value: 3 });
|
||||||
|
});
|
||||||
|
@ -19,4 +19,7 @@ export namespace TestPrograms {
|
|||||||
export const Application = Bun.file(
|
export const Application = Bun.file(
|
||||||
join(import.meta.dir, 'application.cps'),
|
join(import.meta.dir, 'application.cps'),
|
||||||
).text();
|
).text();
|
||||||
|
export const RecordConstruction = Bun.file(
|
||||||
|
join(import.meta.dir, 'record.cps'),
|
||||||
|
).text();
|
||||||
}
|
}
|
||||||
|
7
test/programs/record.cps
Normal file
7
test/programs/record.cps
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
RECORD([(INT 1, OFFp 0), (INT 2, OFFp 0)], record,
|
||||||
|
SELECT(0, VAR one, record,
|
||||||
|
SELECT(1, VAR two, record,
|
||||||
|
PRIMOP(+, [VAR one, VAR two], [result], [])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user