~ehmry/dhall-nim

c1e354241370c16732f9fd230b46e9048426e132 — Emery Hemingway 1 year, 27 days ago 457043f
Parser: allow trailing delimiters
1 files changed, 6 insertions(+), 12 deletions(-)

M src/dhall/parse.nim
M src/dhall/parse.nim => src/dhall/parse.nim +6 -12
@@ 623,7 623,7 @@ let parser = peg("final_expression", stack: seq[Term]):
    for i in 1..<capture.len:
      push Term(kind: tField, fieldRecord: stack.pop(), fieldName: move capture[i].s)

  labels <- '{' * whsp * ?( any_label_or_some * whsp * *(',' * whsp * any_label_or_some * whsp) ) * '}'
  labels <- '{' * whsp * ?( ',' * whsp ) * ?( any_label_or_some * whsp * *(',' * whsp * any_label_or_some * whsp) ) * ?( ',' * whsp ) * '}'

  fields_selector <- labels:
    var t = Term(kind: tProject,


@@ 642,15 642,13 @@ let parser = peg("final_expression", stack: seq[Term]):

  record_literal <- '{' * whsp * ?( ',' * whsp ) * (non_empty_record_literal | empty_record_literal) * whsp * '}'

  empty_record_literal <- '=':
  empty_record_literal <- '=' * ?( whsp * ',' ):
    push Term(kind: tRecordLiteral, recordLiteral: initTable[string, Term](2))

  empty_record_type <- 0:
    push Term(kind: tRecordType, recordType: initTable[string, Term](2))

  non_empty_record_type <- record_type_entry * *(whsp * >',' * whsp * record_type_entry):
    # capture the commas as a hack to figure
    # the number of record entries on the stack
  non_empty_record_type <- record_type_entry * *(whsp * >',' * whsp * record_type_entry) * ?( whsp * ',' ):
    let n = capture.len
    var t = Term(kind: tRecordType,
        recordType: initTable[string, Term](nextPowerOfTwo n))


@@ 668,9 666,7 @@ let parser = peg("final_expression", stack: seq[Term]):
  record_type_entry <- any_label_or_some * whsp * ':' * whsp1 * expression:
    push Term(kind: tEntry, entryKey: move($1), entryVal: stack.pop())

  non_empty_record_literal <- record_literal_entry * *(whsp * >',' * whsp * record_literal_entry):
    # capture the commas as a hack to figure
    # the number of record entries on the stack
  non_empty_record_literal <- record_literal_entry * *(whsp * >',' * whsp * record_literal_entry) * ?( whsp * ',' ):
    let n = capture.len
    var t = Term(kind: tRecordLiteral,
        recordLiteral: initTable[string, Term](nextPowerOfTwo n))


@@ 703,9 699,7 @@ let parser = peg("final_expression", stack: seq[Term]):
  empty_union_type <- 0:
    push Term(kind: tUnionType, union: initTable[string, Term](2))

  non_empty_union_type <- union_type_entry * *(whsp * >'|' * whsp * union_type_entry):
    # capture the bars as a hack to figure
    # the number of union entries on the stack
  non_empty_union_type <- union_type_entry * *(whsp * >'|' * whsp * union_type_entry) * ?( whsp * '|' ):
    let n = capture.len
    var t = Term(kind: tUnionType,
        union: initTable[string, Term](nextPowerOfTwo n))


@@ 723,7 717,7 @@ let parser = peg("final_expression", stack: seq[Term]):
            of 3: stack.pop()
            else: fail())

  non_empty_list_literal <- '[' * whsp * ?( ',' * whsp ) * expression * whsp * *(>',' * whsp * expression * whsp) * ']':
  non_empty_list_literal <- '[' * whsp * ?( ',' * whsp ) * expression * whsp * *(>',' * whsp * expression * whsp) * ?( ',' * whsp ) * ']':
    let
      n = capture.len
      off = stack.len-n