forked from naraen/sudokusolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl_language.ne
74 lines (57 loc) · 1.58 KB
/
repl_language.ne
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@{%
const moo= require('moo');
const keywords = {
'command': ['show', 'unshow', 'use', 'init', 'reset', 'set', 'remove', 'is', 'rewind'],
'object': ['grid', 'hint', 'value', 'it', 'unsolved', 'debug', 'input', 'color'],
'qualifier' : ['solved', 'stuck', 'correct', 'history', 'count', 'on', 'off'],
'strategy_word' : ['brute', 'force', 'only', 'choice']
}
const lexer = moo.compile({
word: {match: /[a-zA-Z]+/, type: moo.keywords(keywords)},
ws : /[ \t]/,
eq : '=',
number : /[0-9]+/,
newline : {match :'\n', lineBreaks:true}
})
%}
@lexer lexer
start -> commands {% id %}
commands -> command {% (t) => [t[0]] %}
| command %newline:+ commands
{% (t) => [t[0], ... t[2]]%}
command -> %command __ %object _
{% (t) => ({
verb: t[0].value,
object: t[2].value
}) %}
| %command __ %object __ %number _ %eq _ %number _
{% (t) => ({
verb: t[0].value,
object: t[2].value,
cellIdx: Number(t[4].value),
operator: t[6].value,
value: Number(t[8].value)
}) %}
| %command __ %object __ numbers _
{% (t) => ({
verb: t[0].value,
object : t[2].value,
numbers : t[4]
}) %}
| %command __ %object __ %qualifier _
{% (t) => ({
verb : t[0].value,
object : t[2].value,
qualifier : t[4].value
}) %}
| %command __ strategy _
{% (t) => ({
verb : t[0].value,
strategy : t[2]
}) %}
numbers -> %number {% id %}
| %number _ numbers {% (t) => t.join('') %}
strategy -> %strategy_word {% id %}
| %strategy_word __ strategy {% (t) => t.join("") %}
__ -> %ws:+
_ -> %ws:*