Skip to content

Commit

Permalink
Emit single-quoted strings instead of double-quoted. Closes GH-5
Browse files Browse the repository at this point in the history
In C, single-quotes are for single character literals, double-quotes for
strings, but in JavaScript, both are for strings. Common style
convention for JavaScript uses single-quotes, so use them here too.
  • Loading branch information
deathcap committed May 5, 2016
1 parent bec31a0 commit ab7444a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main(int argc, char **argv) {
const double pi = 3.14159;
static char *s = "foo";

printf("Hello, world!\n");
printf("Hello, world's!\n");

if (a == 2) exit(1);

Expand Down
4 changes: 4 additions & 0 deletions js_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def generic_visit(self, node):
return ''.join(self.visit(c) for c_name, c in node.children())

def visit_Constant(self, n):
# JS: single-quoted strings by convention
if n.value.startswith('"') and n.value.endswith('"'):
return "'%s'" % (n.value[1:-1].replace("'", "\\'"))
return n.value

def visit_ID(self, n):
Expand Down Expand Up @@ -141,6 +144,7 @@ def visit_DeclList(self, n):
return s

def visit_Typedef(self, n):
# JS: no typedef
s = ''
#if n.storage: s += ' '.join(n.storage) + ' '
#s += self._generate_type(n.type)
Expand Down

0 comments on commit ab7444a

Please sign in to comment.