Skip to content

Commit

Permalink
Cleanup and Polish
Browse files Browse the repository at this point in the history
All tests passing
  • Loading branch information
peey committed Nov 5, 2024
1 parent 8da1603 commit dd005fb
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions source/parser.hera
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,7 @@ BracedObjectLiteral
BracedObjectLiteralContent
# Allow unnested comma-separated properties on first line, optionally
# followed by nested comma-separated properties on further lines
( ObjectPropLine )*:line NestedPropertyDefinitions?:nested ->
( PropertyDefinition ObjectPropertyDelimiter )*:line NestedPropertyDefinitions?:nested ->
line = line.flatMap(([prop, delim]) => {
// Allow each prop to be a single Property object or an array of such
prop = Array.isArray(prop) ? prop : [prop]
Expand All @@ -3315,7 +3315,7 @@ BracedObjectLiteralContent
})
return line.concat(nested || [])
# As a backup, allow for arbitrary untracked indentation
( __ ObjectPropLine )+ ->
( __ PropertyDefinition ObjectPropertyDelimiter )+ ->
return $0.flatMap(([ws, prop, delim]) => {
// Allow each prop to be a single Property object or an array of such
prop = Array.isArray(prop) ? prop : [prop]
Expand All @@ -3330,14 +3330,6 @@ BracedObjectLiteralContent
return [...prop.slice(0, prop.length-1), last]
})


ObjectPropLine
PropertyDefinition ObjectPropertyDelimiter

InsertSpread
"" ->
return { $loc, token: "..." }

# NOTE: Nested implicit object literal starts with an indentation.
# All properties can be spaced out and must have a colon.
NestedImplicitObjectLiteral
Expand Down Expand Up @@ -3371,7 +3363,7 @@ NestedPropertyDefinitions

NestedPropertyDefinition
# TODO: This may be a little weird/ambiguous with single identifier shorthand
Nested:ws ( ObjectPropLine )+:inlineProps ->
Nested:ws ( PropertyDefinition ObjectPropertyDelimiter )+:inlineProps ->
return inlineProps.flatMap( ([prop, delim], i) => {
// Allow each prop to be a single Property object or an array of such
if (!Array.isArray(prop)) prop = [prop]
Expand Down Expand Up @@ -3547,7 +3539,7 @@ PropertyDefinition
# NOTE: basic identifiers are now part of the rule above
#_?:ws IdentifierReference:id ->
# return prepend(ws, id)
InsertSpread:dots IterationExpression:exp ->
InsertDotDotDot:dots IterationExpression:exp ->
exp.statement.object = true
return {
type: "SpreadProperty",
Expand Down Expand Up @@ -6470,6 +6462,10 @@ DotDotDot
"…" ->
return { $loc, token: "..." }

InsertDotDotDot
"" ->
return { $loc, token: "..." }

DoubleColon
"::" ->
return { $loc, token: $1 }
Expand Down

0 comments on commit dd005fb

Please sign in to comment.