Skip to content

Commit e803617

Browse files
committed
meta: Fix unexpected EOF error message
1 parent 762d0d0 commit e803617

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

grammar/meta.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function parse(buffer) {
8989
}
9090

9191
function node(type, start, attrs) {
92-
const end = tok ? Pos.before(tok) : new Pos(lexer.line, lexer.col, lexer.index)
92+
const end = tok != null ? Pos.before(tok) : new Pos(lexer.line, lexer.col, lexer.index)
9393
const region = new Region(start, end, buffer)
9494
return new Node(type, region, attrs)
9595
}
@@ -101,6 +101,9 @@ function parse(buffer) {
101101
}
102102

103103
function parseValue() {
104+
if (tok == null) {
105+
expectError("value")
106+
}
104107
const start = Pos.before(tok)
105108
const name = tok.value
106109

@@ -125,6 +128,9 @@ function parse(buffer) {
125128

126129
function parseKey(start, key) {
127130
expect(":")
131+
if (tok == null) {
132+
expect("value")
133+
}
128134
const atomStart = Pos.before(tok)
129135
const value = parseValue()
130136
const match = parseModifier(value, atomStart)
@@ -144,6 +150,9 @@ function parse(buffer) {
144150
}
145151

146152
function parseAtom() {
153+
if (tok == null) {
154+
expectError("value")
155+
}
147156
const start = Pos.before(tok)
148157
switch (tok.type) {
149158
case "string":
@@ -180,6 +189,9 @@ function parse(buffer) {
180189
}
181190

182191
function parseNodeType() {
192+
if (tok == null) {
193+
expectError("node type")
194+
}
183195
const start = Pos.before(tok)
184196
const value = tok.value
185197
switch (tok && tok.type) {

test/meta-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test("disallows multiple modifiers", t => {
117117
t.throws(t => parseRule(t, `foo -> bar*?`), /^Expected space \(found \?\)/)
118118
})
119119

120-
test.failing("handles EOF", t => {
120+
test("handles EOF", t => {
121121
parseGrammar(`foo -> bar`)
122122
parseGrammar(`foo -> "quxx"`)
123123
parseGrammar(`foo ->`)

0 commit comments

Comments
 (0)