Browse Source

Add compound literals

pull/1/head
Max Brunsfeld 11 years ago
parent
commit
ebd581c2bd
3 changed files with 8384 additions and 5722 deletions
  1. +10
    -0
      grammar.coffee
  2. +23
    -0
      grammar_test/expressions.txt
  3. +8351
    -5722
      src/parser.c

+ 10
- 0
grammar.coffee View File

@ -191,6 +191,7 @@ module.exports = grammar
@function_call,
@field_access,
@deref_field_access,
@compound_literal,
@number,
@char,
@string)
@ -234,6 +235,15 @@ module.exports = grammar
"=",
@expression)
compound_literal: -> seq(
"(", @type, ")",
"{", commaSep(choice(@struct_literal_field, @expression)), optional(","), "}")
struct_literal_field: -> seq(
".", @identifier,
"=",
@expression)
number: -> /\d+(\.\d+)?/
char: -> token(seq(

+ 23
- 0
grammar_test/expressions.txt View File

@ -120,3 +120,26 @@ int main() {
(expression_statement (assignment (field_access (identifier) (identifier)) (number)))
(expression_statement (assignment (deref_field_access (identifier) (identifier)) (number)))))
============================================
Compound literals
============================================
int main() {
x = (SomeType) { .field1 = 5, .field2 = 6 };
y = (struct SomeStruct) { 7, 8 };
}
---
(function_declaration (identifier) (identifier) (formal_parameters)
(statement_block
(expression_statement (assignment
(identifier)
(compound_literal (identifier)
(struct_literal_field (identifier) (number))
(struct_literal_field (identifier) (number)))))
(expression_statement (assignment
(identifier)
(compound_literal (struct_type (identifier))
(number)
(number))))))

+ 8351
- 5722
src/parser.c
File diff suppressed because it is too large
View File


Loading…
Cancel
Save