Skip to content

Commit

Permalink
Merge pull request #18 from savi-lang/update/latest-savi
Browse files Browse the repository at this point in the history
Update for latest Savi syntax.
  • Loading branch information
jemc authored Jun 21, 2023
2 parents 1632abe + 449540f commit 4b39a10
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion benchmark/JSON.Parser.Benchmark.savi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

json << "["
n.times -> (i |
if (i > 0) (json << ",")
if i > 0 json << ","
json << obj
)
json << "]"
Expand Down
4 changes: 2 additions & 2 deletions spec/JSON.Parser.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
try (
parser.parse!(source) -> (token | collector.collect(parser, token))
actual = Inspect[collector]
if (actual == expected) (
if actual == expected (
True
|
@env.err.print("\n")
Expand All @@ -240,7 +240,7 @@
False
|
actual = source.trim(0, parser.token_end)
if (valid_part == actual) (
if valid_part == actual (
True
|
@env.err.write("\nexpected the valid part of ")
Expand Down
20 changes: 10 additions & 10 deletions src/JSON.Parser.savi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

:fun _peek_softly U8: try (@source.byte_at!(@_offset) | ' ')

:fun ref _eat!(b U8): if (b != @source.byte_at!(@_offset)) error!, @_advance
:fun ref _eat!(b U8): if b != @source.byte_at!(@_offset) error!, @_advance

:fun ref _advance(n USize = 1): @_offset += n

Expand All @@ -48,7 +48,7 @@

:fun ref _skip_whitespace
keep_going = True
while (keep_going && @_has_next) (
while keep_going && @_has_next (
case @_peek_softly == (
| ' ' | @_advance
| '\r' | @_advance
Expand Down Expand Up @@ -102,7 +102,7 @@
yield JSON.Token.ArrayStart
@_skip_whitespace

if (@_peek! == ']') (
if @_peek! == ']' (
@_pre_token
@_advance
|
Expand All @@ -127,7 +127,7 @@
@_skip_whitespace
index = 0

if (@_peek! == ']') (
if @_peek! == ']' (
@_pre_token
@_advance
|
Expand All @@ -154,7 +154,7 @@
@_advance // past the opening bracket
yield JSON.Token.ObjectStart
@_skip_whitespace
if (@_peek! == '}') (
if @_peek! == '}' (
@_pre_token
@_advance
|
Expand Down Expand Up @@ -184,7 +184,7 @@
@_eat!('{')
@_skip_whitespace

if (@_peek! == '}') (
if @_peek! == '}' (
@_pre_token
@_advance
|
Expand Down Expand Up @@ -215,7 +215,7 @@
yield JSON.Token.Number

:fun ref _read_number! (I64 | F64)
sign I64 = if (@_peek_softly == '-') (@_advance, -1 | 1)
sign I64 = if @_peek_softly == '-' (@_advance, -1 | 1)

integer = @_read_number_digits!

Expand All @@ -241,7 +241,7 @@
if exp_negative (exp = exp.negate)
)

if (has_dot || has_exp) (
if has_dot || has_exp (
sign.f64 * (integer.f64 + dot) * F64[10].pow(exp.f64)
|
sign * integer
Expand Down Expand Up @@ -311,7 +311,7 @@
// We've already read the initial "\u" bytes, so start reading the digits.
value = @_read_unicode_value!

if ((value < 0xD800) || (value >= 0xE000)) (
if (value < 0xD800) || (value >= 0xE000) (
// If the value we read is a valid single UTF-16 value, return it now.
value
|
Expand All @@ -320,7 +320,7 @@
@_eat!('\\'), @_eat!('u')
value_2 = @_read_unicode_value!

if ((value < 0xDC00) && (value_2 >= 0xDC00) && (value_2 < 0xE000)) (
if (value < 0xDC00) && (value_2 >= 0xDC00) && (value_2 < 0xE000) (
// If the two values make a valid pair, return the combined value.
U32[0x10000]
+ value.bit_and(0x3FF).bit_shl(10)
Expand Down
10 changes: 5 additions & 5 deletions src/JSON.Writer.savi
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@
)

:fun ref _finish_collection None
if (@_should_newline && !@_is_first_in_collection) @_newline_and_indent
if @_should_newline && !@_is_first_in_collection @_newline_and_indent

:fun ref _key(name String)
@primitive_string(name)
@_stream.push(':')
if (@_should_newline || @_indent_spaces.is_nonzero) @_stream.push(' ')
if @_should_newline || @_indent_spaces.is_nonzero @_stream.push(' ')

:fun ref object(recurse_id USize) None
:yields None for None // TODO: add a "without interruption" enforcement to the yield signature to ensure that the yield block isn't allowed to jump away.
Expand Down Expand Up @@ -175,7 +175,7 @@
@_stream << b"null"

:fun ref primitive_bool(value Bool) None
@_stream << if value (b"true" | b"false")
@_stream << (if value (b"true" | b"false"))

:fun ref primitive_u64(value U64) None
@_stream << "\(value)".as_bytes // TODO: more efficient
Expand All @@ -202,10 +202,10 @@
@_stream << "\(value)".as_bytes // TODO: more efficient

:fun ref primitive_f64(value F64) None
@_stream << if value.is_finite ("\(value)".as_bytes | b"null") // TODO: more efficient
@_stream << (if value.is_finite ("\(value)".as_bytes | b"null")) // TODO: more efficient

:fun ref primitive_f32(value F32) None
@_stream << if value.is_finite ("\(value)".as_bytes | b"null") // TODO: more efficient
@_stream << (if value.is_finite ("\(value)".as_bytes | b"null")) // TODO: more efficient

:fun ref primitive_name(value String'box) None
@primitive_string(value)
Expand Down

0 comments on commit 4b39a10

Please sign in to comment.