Skip to content

Fix a couple AST mistakes caught while porting the parser to Rust #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fluent-syntax/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getErrorMessage(code, args) {
}
case 'E0005': {
const [id] = args;
return `Expected entry "${id}" to have a value, attributes or tags`;
return `Expected entry "${id}" to have a value or attributes`;
}
case 'E0006': {
const [field] = args;
Expand Down
8 changes: 2 additions & 6 deletions fluent-syntax/src/ftlstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class FTLParserStream extends ParserStream {
this.next();
return ret;
}
throw new ParseError('E0004', 'a-zA-Z');
throw new ParseError('E0004', 'a-zA-Z_');
}

takeIDChar() {
Expand All @@ -243,15 +243,11 @@ export class FTLParserStream extends ParserStream {

takeSymbChar() {
const closure = ch => {
if (ch === undefined) {
return false;
}

const cc = ch.charCodeAt(0);
return ((cc >= 97 && cc <= 122) || // a-z
(cc >= 65 && cc <= 90) || // A-Z
(cc >= 48 && cc <= 57) || // 0-9
cc === 95 || cc === 45 || cc === 32); // _-
cc === 95 || cc === 45 || cc === 32); // _-<space>
};

return this.takeChar(closure);
Expand Down
13 changes: 10 additions & 3 deletions fluent-syntax/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class FluentParser {

ps.next();

if (ps.current() === '/') {
if (ps.currentIs('/')) {
content += '\n';
ps.next();
ps.expectChar('/');
Expand Down Expand Up @@ -212,7 +212,7 @@ export default class FluentParser {
tags = this.getTags(ps);
}

if (pattern === undefined && attrs === undefined && tags === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing the tags check here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding was that we don't accept messages with just tags (they have to have attrs or value). Am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right! That's a good point. The EBNF confirms this: https://github.com/projectfluent/fluent/blob/master/spec/fluent.ebnf#L43. Thanks for correcting me.

if (pattern === undefined && attrs === undefined) {
throw new ParseError('E0005', id.name);
}

Expand Down Expand Up @@ -566,7 +566,14 @@ export default class FluentParser {

ps.expectChar(')');

return new AST.CallExpression(literal.id, args);
if (!/^[A-Z_-]+$/.test(literal.id.name)) {
throw new ParseError('E0008');
}

return new AST.CallExpression(
new AST.Function(literal.id.name),
args
);
}

return literal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
key = { foo.23 }

//~ ERROR E0004, pos 12, args "a-zA-Z"
//~ ERROR E0004, pos 12, args "a-zA-Z_"

key = { foo. }

//~ ERROR E0004, pos 31, args "a-zA-Z"
//~ ERROR E0004, pos 31, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
key = { no-caps-name() }

//~ ERROR E0008, pos 22
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
key = Value
.2 = Foo
//~ ERROR E0004, pos 17, args "a-zA-Z"
//~ ERROR E0004, pos 17, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bar = Bar {
//~ ERROR E0004, pos 11, args "a-zA-Z"
//~ ERROR E0004, pos 11, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
key = { $foo ->
*[
//~ ERROR E0004, pos 22, args "a-zA-Z"
//~ ERROR E0004, pos 22, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
key = { foo[] }
//~ ERROR E0004, pos 12, args "a-zA-Z"
//~ ERROR E0004, pos 12, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
key = {
*[one] Value
}
//~ ERROR E0004, pos 7, args "a-zA-Z"
//~ ERROR E0004, pos 7, args "a-zA-Z_"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
key = {
*[ one] Foo
}
//~ ERROR E0004, pos 18, args "a-zA-Z"
//~ ERROR E0004, pos 18, args "a-zA-Z_"