stub AST parser
This commit is contained in:
parent
686a1b1ffc
commit
64b2b5d332
2 changed files with 31 additions and 1 deletions
|
@ -38,12 +38,23 @@ export const tokenize = latl => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addToken = (tree, token, index, tokens) => {
|
||||||
|
console.log(tokens[index - 1], token)
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildTree = tokens => {
|
||||||
|
return tokens.reduce(addToken, {})
|
||||||
|
}
|
||||||
|
|
||||||
export const generateAST = latl => {
|
export const generateAST = latl => {
|
||||||
// tokenize
|
// tokenize
|
||||||
const tokens = tokenize(latl);
|
const tokens = tokenize(latl);
|
||||||
|
|
||||||
// build tree
|
// build tree
|
||||||
|
const tree = buildTree(tokens);
|
||||||
|
|
||||||
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenTypes = [
|
const tokenTypes = [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { stateReducer } from './reducer';
|
import { stateReducer } from './reducer';
|
||||||
import { initState } from './reducer.init';
|
import { initState } from './reducer.init';
|
||||||
import { tokenize } from './reducer.latl';
|
import { tokenize, buildTree } from './reducer.latl';
|
||||||
|
|
||||||
describe('LATL', () => {
|
describe('LATL', () => {
|
||||||
it('returns state unaltered with no action body', () => {
|
it('returns state unaltered with no action body', () => {
|
||||||
|
@ -35,6 +35,11 @@ describe('LATL', () => {
|
||||||
expect(tokens).toStrictEqual(tokenizedLatl);
|
expect(tokens).toStrictEqual(tokenizedLatl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns AST from well-formed epoch tokens', () => {
|
||||||
|
const tree = buildTree(tokenizedEpoch);
|
||||||
|
expect(tree).toStrictEqual(treeEpoch);
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
const epochDefinitionLatl = `
|
const epochDefinitionLatl = `
|
||||||
*PROTO
|
*PROTO
|
||||||
|
@ -56,6 +61,20 @@ const tokenizedEpoch = [
|
||||||
{ type: "pipe", value: "|" }, { type: "variable", value: "CHILD" }
|
{ type: "pipe", value: "|" }, { type: "variable", value: "CHILD" }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const treeEpoch = {
|
||||||
|
epochs: [
|
||||||
|
{
|
||||||
|
parent: 'PROTO',
|
||||||
|
name: 'CHILD',
|
||||||
|
index: 0,
|
||||||
|
changes: [
|
||||||
|
'[+ FEATURE]>[- FEATURE]/._.',
|
||||||
|
'n>m/#_.'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
const featureDefinitionLatl = `
|
const featureDefinitionLatl = `
|
||||||
[+ PLOSIVE] = kp / p / b / d / t / g / k
|
[+ PLOSIVE] = kp / p / b / d / t / g / k
|
||||||
[- PLOSIVE] = m / n / s / z
|
[- PLOSIVE] = m / n / s / z
|
||||||
|
|
Loading…
Reference in a new issue