Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Syntactic Monoids
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cole Oie
Syntactic Monoids
Commits
4beb880f
Commit
4beb880f
authored
1 year ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Recorded work from Friday and code based on second design from Friday.
parent
4682311b
Branches
solution
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
syntactic-monoids/src/attributes.js
+47
-5
47 additions, 5 deletions
syntactic-monoids/src/attributes.js
syntactic-monoids/src/quotes.js
+58
-0
58 additions, 0 deletions
syntactic-monoids/src/quotes.js
with
105 additions
and
5 deletions
syntactic-monoids/src/attributes.js
+
47
−
5
View file @
4beb880f
// 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
)
{
...
...
This diff is collapsed.
Click to expand it.
syntactic-monoids/src/quotes.js
+
58
−
0
View file @
4beb880f
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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment