Commit graph

5 commits

Author SHA1 Message Date
86f905ba1d Parser
This commit adds a parser, complete with tests. The parser implements
an iterator which returns Datum. It wraps around a Lexer and uses the
Lexer's iterator interfact to consume lexemes. It may return an error
which may wrap around a LexError or a fully lexed lexeme.

In the implementation of the Parser bugs were found in the lexer
package. This resulted in the lexing tests being extended as well as
several small logic updates.

The number package has had slight tweaks to make number representations
less cumbersome.

Finally, the Datum display logic in the sexpr package has also been updated.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2025-05-19 14:38:11 -07:00
a48fc52fab Number: fix frac.pow(frac) issue and better make_inexact() for sci
This commit fixes a bad procedure used to raise a fraction to the
power of another fraction, and adds additional test cases for this.

It also fixes a todo in the number package for implementing
make_inexact on ScientificNotation numbers such that they can handle
negative exponents.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2025-05-16 15:04:53 -07:00
3174494001 Lexer supports hexadecimal escaping and number literals
This commit updates the Lexer to fully support character and string
escaping as well as hexadecimal in number literals. Updates to lexing
were performed according to the R7RS small specification. Test cases
were extended to cover new support, as well as more number cases
mirrored in the parsing logic of the number package.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2025-05-15 19:30:18 -07:00
41216d3526 Number library and integrations
This commit adds a number library which handles fractions, floats,
whole numbers, scientific notation, and special symbolic numbers
all according to the R7RS small specification.

Numeric trait is used to abstract operations across all number types
and a Number enum is used to offer a non-opaque type that stores any
kind of number.

Upon the Number enum is implemented the following traits:
- Add, Div, Sub, Mul
- Pow
- PartialEq
- PartialOrd

Which then offer the following operators to use on the Number enum
instances themselves: + - / * == != < > <= >= and of course x.pow(y).

Additionally, the number package contains parsing logic for each type
of number. FromStr is implemented as part of the Numeric trait, and
then in turn implemented on Number. Additionally Into<String> is
implemented for the Numeric trait and then on the Number enum type
as well.

Test cases have been added for basic cases, but could be expanded.

Additional modifications:
- LexError has a custom display implementation that properly outputs
  formatted errors.
- Sexpr package updated to use new number package

Signed-off-by: Ava Affine <ava@sunnypup.io>
2025-05-15 12:59:00 -07:00
6554a0639a Lexer and S-Expression data types
The lexer is complete with tests. It fully encapsulates the logic
of splitting an input document into a stream of tokens. It can be
instantiated from an Rc<str>, meaning no lifetimes need be managed
references to the original document (like a stringview) can be
passed around carelessly. The Lexer implements the iterator
method which should help elegantly design repls / compilers, etc.

The S-Expression data type represents the parsed AST. The actual
parsing logic is yet to be added. It is intended that the AST be
the last step before compiling to bytecode. The data representation
here is cons cells of datum. Formatting is implemented.

Signed-off-by: Ava Affine <ava@sunnypup.io>
2025-05-07 09:19:33 -07:00