Skip to content
Snippets Groups Projects
Commit a98333f4 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Recorded work for Thursday.

parent 66adf7af
No related branches found
No related tags found
No related merge requests found
// TODO: placeholder
const READY = 0;
const KEY = 1;
const AFTER_EQUALS = 2;
const VALUE = 3;
const INVALID = 4;
const STATE_COUNT = 0;
const STATE_COUNT = 5;
class MonoidElement {
constructor(states) {
......@@ -8,14 +12,52 @@ class MonoidElement {
}
get valid() {
return false; // TODO: stub
const finalState = this.states[READY];
return finalState === READY || finalState === VALUE;
}
}
export const IDENTITY_ELEMENT = new MonoidElement([]); // TODO: placeholder
export const IDENTITY_ELEMENT = new MonoidElement([
READY,
KEY,
AFTER_EQUALS,
VALUE,
INVALID,
]);
const SPACE = new MonoidElement([
READY,
INVALID,
INVALID,
READY,
INVALID,
]);
const EQUALS = new MonoidElement([
INVALID,
AFTER_EQUALS,
INVALID,
INVALID,
INVALID,
]);
const OTHER = new MonoidElement([
KEY,
KEY,
VALUE,
VALUE,
INVALID,
]);
export function encodeAsMonoidElement(character) {
return IDENTITY_ELEMENT; // TODO: stub
switch (character) {
case ' ':
return SPACE;
case '=':
return EQUALS;
default:
return OTHER;
}
}
export function combineMonoidElements(left, right) {
......
const UNQUOTED = 0;
const QUOTED = 1;
const ESCAPED = 2;
const STATE_COUNT = 3;
class MonoidElement {
constructor(states) {
this.states = states;
}
get valid() {
return this.states[UNQUOTED] === UNQUOTED;
}
}
export const IDENTITY_ELEMENT = new MonoidElement([
UNQUOTED,
QUOTED,
ESCAPED,
]);
const QUOTE = new MonoidElement([
QUOTED,
UNQUOTED,
QUOTED,
]);
const BACKSLASH = new MonoidElement([
UNQUOTED,
ESCAPED,
QUOTED,
]);
const OTHER = new MonoidElement([
UNQUOTED,
QUOTED,
QUOTED,
]);
export function encodeAsMonoidElement(character) {
switch (character) {
case '"':
return QUOTE;
case '\\':
return BACKSLASH;
default:
return OTHER;
}
}
export function combineMonoidElements(left, right) {
const states = [];
for (let i = 0; i < STATE_COUNT; ++i) {
states.push(right.states[left.states[i]]);
}
return new MonoidElement(states);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment