support for epoch and features, lexicon support still buggy
This commit is contained in:
parent
20bede405f
commit
c653653ba1
5 changed files with 56 additions and 23 deletions
|
@ -13,13 +13,13 @@ import Latl from './components/Latl';
|
|||
import LatlOutput from './components/LatlOutput';
|
||||
|
||||
import { stateReducer } from './reducers/reducer';
|
||||
import { initState } from './reducers/reducer.init';
|
||||
import { clearState } from './reducers/reducer.init';
|
||||
|
||||
const PhonoChangeApplier = () => {
|
||||
const [ state, dispatch ] = useReducer(
|
||||
stateReducer,
|
||||
{},
|
||||
initState
|
||||
clearState
|
||||
)
|
||||
const { lexicon, phones, phonemes, epochs, options, features, results, errors, latl, parseResults } = state;
|
||||
|
||||
|
|
|
@ -10,6 +10,17 @@ const ProtoLang = ({ lexicon, dispatch }) => {
|
|||
return lexicon.map(getProperty('lexeme')).join('\n');
|
||||
}
|
||||
|
||||
const handleChange = e => {
|
||||
const value = e.target.value.split(/\n/).map(line => {
|
||||
const lexeme = line.split('#')[0].trim();
|
||||
const epoch = line.split('#')[1] || '';
|
||||
return { lexeme, epoch }
|
||||
})
|
||||
dispatch({
|
||||
type: 'SET_LEXICON',
|
||||
value
|
||||
})
|
||||
}
|
||||
return (
|
||||
<div className="ProtoLang" data-testid="ProtoLang">
|
||||
<h3>Proto Language Lexicon</h3>
|
||||
|
@ -21,22 +32,8 @@ const ProtoLang = ({ lexicon, dispatch }) => {
|
|||
rows="10"
|
||||
data-testid="ProtoLang-Lexicon__textarea"
|
||||
value={renderLexicon()}
|
||||
onChange={e=> {
|
||||
console.log(e.target.value.split(/\n/).map(line => {
|
||||
const lexeme = line.split('#')[0].trim();
|
||||
const epoch = line.split('#')[1] || '';
|
||||
return { lexeme, epoch }
|
||||
}))
|
||||
dispatch({
|
||||
type: 'SET_LEXICON',
|
||||
value: e.target.value.split(/\n/).map(line => {
|
||||
const lexeme = line.split('#')[0].trim();
|
||||
const epoch = line.split('#')[1] || '';
|
||||
return { lexeme, epoch }
|
||||
})
|
||||
})
|
||||
}
|
||||
}>
|
||||
onChange={e => handleChange(e)}
|
||||
>
|
||||
</textarea>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,20 @@ export type initAction = {
|
|||
type: "INIT"
|
||||
}
|
||||
|
||||
export const clearState = () => {
|
||||
return {
|
||||
epochs: [],
|
||||
phones: {},
|
||||
options: { output: 'default', save: false },
|
||||
results: [],
|
||||
errors: {},
|
||||
features: {},
|
||||
lexicon: [],
|
||||
latl: '',
|
||||
parseResults: ''
|
||||
}
|
||||
}
|
||||
|
||||
export const initState = (changesArgument: number): stateType => {
|
||||
const state = {
|
||||
epochs: [
|
||||
|
|
|
@ -314,7 +314,9 @@ const parseSlash = (tree, token, index, tokens) => {
|
|||
case 'feature--minus':
|
||||
return tree;
|
||||
case 'lexicon':
|
||||
return [...tree, { }]
|
||||
return [...tree, { }];
|
||||
case 'main':
|
||||
return [...tree, { type: 'lexicon', value: []}]
|
||||
default:
|
||||
return [...tree, 'unexpected slash']
|
||||
}
|
||||
|
@ -405,7 +407,6 @@ const generateNode = (tree, token, index, tokens) => {
|
|||
const addToken = (tree, token, index, tokens) => generateNode(tree, token, index, tokens);
|
||||
|
||||
const connectNodes = (tree, node, index, nodes) => {
|
||||
console.log(tree, node)
|
||||
switch (node.type) {
|
||||
case 'epoch':
|
||||
delete node.type;
|
||||
|
@ -463,7 +464,6 @@ export const generateAST = latl => {
|
|||
const tokens = tokenize(latl.trim());
|
||||
// build tree
|
||||
const tree = buildTree(tokens);
|
||||
console.log(tree)
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
@ -472,7 +472,6 @@ export const parseLatl = (state, action) => {
|
|||
const latl = state.latl;
|
||||
const AST = generateAST(latl);
|
||||
const features = AST.features;
|
||||
console.log(AST)
|
||||
if (features) {
|
||||
if (state.features) {
|
||||
state = Object.keys(state.features).reduce((state, feature) => {
|
||||
|
@ -517,7 +516,7 @@ const tokenTypes = [
|
|||
['slash', `\/`],
|
||||
['dot', `\\.`],
|
||||
['underscore', `\\_`],
|
||||
[`referent`, `[A-Za-z]+[\\w\\-\\_]*`],
|
||||
[`referent`, `[A-Za-z]+[\u0100-\u03FFA-Za-z0-9\\-\\_]*`],
|
||||
[`phone`, `[\u0100-\u03FFA-Za-z0]+`],
|
||||
['equal', `=`],
|
||||
[`lineBreak`, `\\n`],
|
||||
|
|
|
@ -88,6 +88,17 @@ describe('LATL', () => {
|
|||
|
||||
})
|
||||
|
||||
it('returns state from well formed latl', () => {
|
||||
const state = initState();
|
||||
const setAction = {
|
||||
type: 'SET_LATL',
|
||||
value: totalLatl
|
||||
}
|
||||
const latlState = stateReducer(state, setAction);
|
||||
const parseState = parseLatl(latlState, {});
|
||||
expect(parseState).toStrictEqual(totalLatlState)
|
||||
})
|
||||
|
||||
})
|
||||
const epochDefinitionLatl = `
|
||||
; comment
|
||||
|
@ -495,3 +506,15 @@ const lexiconState = {
|
|||
],
|
||||
parseResults: 'latl parsed successfully'
|
||||
}
|
||||
|
||||
const totalLatl = `${epochDefinitionLatl}\n\n${featureDefinitionLatl}\n\n${lexiconDefinitionLatl}`
|
||||
|
||||
const totalLatlState = {
|
||||
...initState(),
|
||||
latl: totalLatl,
|
||||
phonemes: {},
|
||||
features: featureState.features,
|
||||
epochs: treeEpoch.epochs,
|
||||
lexicon: lexiconState.lexicon,
|
||||
parseResults: 'latl parsed successfully'
|
||||
}
|
Loading…
Reference in a new issue