Navigation Menu

Skip to content

Commit

Permalink
Add char literals
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Oct 28, 2014
1 parent 11ce0da commit 5c22801
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions grammar.coffee
Expand Up @@ -183,6 +183,7 @@ module.exports = grammar
@field_access,
@deref_field_access,
@number,
@char,
@string)

field_access: -> seq(
Expand Down Expand Up @@ -226,6 +227,13 @@ module.exports = grammar

number: -> /\d+(\.\d+)?/

char: -> token(seq(
"'",
choice(
seq(optional("\\"), /[^']/),
seq("\\", "'")),
"'"))

string: -> token(seq(
'"', repeat(choice(/[^"]/, '\\"')), '"'))

Expand Down
20 changes: 20 additions & 0 deletions grammar_test/expressions.txt
Expand Up @@ -12,6 +12,26 @@ int main() {
(statement_block
(expression_statement (function_call (identifier) (string) (identifier)))))

============================================
Character literals
============================================

int main() {
'a';
'\0';
'\t';
'\'';
}

---

(function_declaration (identifier) (identifier) (formal_parameters)
(statement_block
(expression_statement (char))
(expression_statement (char))
(expression_statement (char))
(expression_statement (char))))

============================================
Field access
============================================
Expand Down

0 comments on commit 5c22801

Please sign in to comment.