Skip to content

Commit

Permalink
wip on rain string
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Oct 30, 2024
1 parent 77ffee4 commit 724d893
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/lib/parse/LibParse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
COMMENT_END_SEQUENCE,
CMASK_IDENTIFIER_HEAD
} from "rain.string/lib/parse/LibParseCMask.sol";
import {LibParseChars} from "rain.string/lib/parse/LibParseChars.sol";
import {LibParseChar} from "rain.string/lib/parse/LibParseChar.sol";
import {LibCtPop} from "rain.math.binary/lib/LibCtPop.sol";
import {LibParseMeta} from "rain.interpreter.interface/lib/parse/LibParseMeta.sol";
import {LibParseLiteral} from "./literal/LibParseLiteral.sol";
Expand Down Expand Up @@ -151,7 +151,7 @@ library LibParse {
}
// Anon stack item.
else {
cursor = skipMask(cursor + 1, end, CMASK_LHS_STACK_TAIL);
cursor = LibParseChar.skipMask(cursor + 1, end, CMASK_LHS_STACK_TAIL);
}
// Bump the index regardless of whether the stack
// item is named or not.
Expand All @@ -161,7 +161,7 @@ library LibParse {
// Set yang as we are now building a stack item.
state.fsm |= FSM_YANG_MASK | FSM_ACTIVE_SOURCE_MASK;
} else if (char & CMASK_WHITESPACE != 0) {
cursor = skipMask(cursor + 1, end, CMASK_WHITESPACE);
cursor = LibParseChar.skipMask(cursor + 1, end, CMASK_WHITESPACE);
// Set ying as we now open to possibilities.
state.fsm &= ~FSM_YANG_MASK;
} else if (char & CMASK_LHS_RHS_DELIMITER != 0) {
Expand Down Expand Up @@ -356,7 +356,7 @@ library LibParse {
state.highwater();
cursor++;
} else if (char & CMASK_WHITESPACE > 0) {
cursor = skipMask(cursor + 1, end, CMASK_WHITESPACE);
cursor = LibParseChar.skipMask(cursor + 1, end, CMASK_WHITESPACE);
// Set yin as we now open to possibilities.
state.fsm &= ~FSM_YANG_MASK;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/parse/LibParseInterstitial.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {ParserOutOfBounds, MalformedCommentStart, UnclosedComment} from "../../error/ErrParse.sol";
import {LibParseError} from "./LibParseError.sol";
import {LibParse} from "./LibParse.sol";
import {LibParseChar} from "rain.string/lib/parse/LibParseChar.sol";

library LibParseInterstitial {
using LibParse for ParseState;
Expand Down Expand Up @@ -90,7 +91,7 @@ library LibParseInterstitial {
unchecked {
// Set ying as we now open to possibilities.
state.fsm &= ~FSM_YANG_MASK;
return LibParse.skipMask(cursor, end, CMASK_WHITESPACE);
return LibParseChar.skipMask(cursor, end, CMASK_WHITESPACE);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/lib/parse/literal/LibParseLiteralDecimal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
CMASK_NEGATIVE_SIGN,
CMASK_ZERO
} from "rain.string/lib/parse/LibParseCMask.sol";
import {LibParseChar} from "rain.string/lib/parse/LibParseChar.sol";
import {LibParseError} from "../LibParseError.sol";
import {LibParse} from "../LibParse.sol";
import {LibDecimalFloatImplementation, LibDecimalFloat} from "rain.math.float/lib/LibDecimalFloat.sol";
Expand Down Expand Up @@ -97,7 +98,7 @@ library LibParseLiteralDecimal {
function unsafeStrToSignedInt(ParseState memory state, uint256 start, uint256 end) internal pure returns (int256) {
unchecked {
uint256 cursor = start;
uint256 isNeg = LibParse.isMask(cursor, end, CMASK_NEGATIVE_SIGN);
uint256 isNeg = LibParseChar.isMask(cursor, end, CMASK_NEGATIVE_SIGN);
cursor += isNeg;

uint256 value = state.unsafeStrToInt(cursor, end);
Expand Down Expand Up @@ -149,28 +150,28 @@ library LibParseLiteralDecimal {
{
unchecked {
cursor = start;
cursor = LibParse.skipMask(cursor, end, CMASK_NEGATIVE_SIGN);
cursor = LibParseChar.skipMask(cursor, end, CMASK_NEGATIVE_SIGN);
{
uint256 intStart = cursor;
cursor = LibParse.skipMask(cursor, end, CMASK_NUMERIC_0_9);
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == intStart) {
revert ZeroLengthDecimal(state.parseErrorOffset(start));
}
}
signedCoefficient = state.unsafeStrToSignedInt(start, cursor);

int256 fracValue = int256(LibParse.isMask(cursor, end, CMASK_DECIMAL_POINT));
int256 fracValue = int256(LibParseChar.isMask(cursor, end, CMASK_DECIMAL_POINT));
if (fracValue != 0) {
cursor++;
uint256 fracStart = cursor;
cursor = LibParse.skipMask(cursor, end, CMASK_NUMERIC_0_9);
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == fracStart) {
revert MalformedDecimalPoint(state.parseErrorOffset(fracStart));
}
// Trailing zeros are allowed in fractional literals but should
// not be counted in the precision.
uint256 nonZeroCursor = cursor;
while (LibParse.isMask(nonZeroCursor - 1, end, CMASK_ZERO) == 1) {
while (LibParseChar.isMask(nonZeroCursor - 1, end, CMASK_ZERO) == 1) {
nonZeroCursor--;
}

Expand Down Expand Up @@ -198,14 +199,14 @@ library LibParseLiteralDecimal {
signedCoefficient = rescaledIntValue + fracValue;
}

int256 eValue = int256(LibParse.isMask(cursor, end, CMASK_E_NOTATION));
int256 eValue = int256(LibParseChar.isMask(cursor, end, CMASK_E_NOTATION));
if (eValue != 0) {
cursor++;
uint256 eStart = cursor;
cursor = LibParse.skipMask(cursor, end, CMASK_NEGATIVE_SIGN);
cursor = LibParseChar.skipMask(cursor, end, CMASK_NEGATIVE_SIGN);
{
uint256 digitsStart = cursor;
cursor = LibParse.skipMask(cursor, end, CMASK_NUMERIC_0_9);
cursor = LibParseChar.skipMask(cursor, end, CMASK_NUMERIC_0_9);
if (cursor == digitsStart) {
revert MalformedExponentDigits(state.parseErrorOffset(digitsStart));
}
Expand Down
7 changes: 6 additions & 1 deletion src/lib/parse/literal/LibParseLiteralHex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
ZeroLengthHexLiteral,
HexLiteralOverflow
} from "../../../error/ErrParse.sol";
import {CMASK_UPPER_ALPHA_A_F, CMASK_LOWER_ALPHA_A_F, CMASK_NUMERIC_0_9, CMASK_HEX} from "rain.string/lib/parse/LibParseCMask.sol";
import {
CMASK_UPPER_ALPHA_A_F,
CMASK_LOWER_ALPHA_A_F,
CMASK_NUMERIC_0_9,
CMASK_HEX
} from "rain.string/lib/parse/LibParseCMask.sol";
import {LibParseError} from "../LibParseError.sol";

library LibParseLiteralHex {
Expand Down
9 changes: 6 additions & 3 deletions src/lib/parse/literal/LibParseLiteralSubParseable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {ParseState} from "../LibParseState.sol";
import {LibParse} from "../LibParse.sol";
import {UnclosedSubParseableLiteral, SubParseableMissingDispatch} from "../../../error/ErrParse.sol";
import {
CMASK_WHITESPACE, CMASK_SUB_PARSEABLE_LITERAL_HEAD, CMASK_SUB_PARSEABLE_LITERAL_END
CMASK_WHITESPACE,
CMASK_SUB_PARSEABLE_LITERAL_HEAD,
CMASK_SUB_PARSEABLE_LITERAL_END
} from "rain.string/lib/parse/LibParseCMask.sol";
import {LibParseInterstitial} from "../LibParseInterstitial.sol";
import {LibParseError} from "../LibParseError.sol";
import {LibSubParse} from "../LibSubParse.sol";
import {LibParseChar} from "rain.string/lib/parse/LibParseChar.sol";

library LibParseLiteralSubParseable {
using LibParse for ParseState;
Expand Down Expand Up @@ -41,7 +44,7 @@ library LibParseLiteralSubParseable {
uint256 dispatchStart = cursor;

// Skip all non-whitespace and non-bracket characters.
cursor = LibParse.skipMask(cursor, end, ~(CMASK_WHITESPACE | CMASK_SUB_PARSEABLE_LITERAL_END));
cursor = LibParseChar.skipMask(cursor, end, ~(CMASK_WHITESPACE | CMASK_SUB_PARSEABLE_LITERAL_END));
uint256 dispatchEnd = cursor;

if (dispatchEnd == dispatchStart) {
Expand All @@ -57,7 +60,7 @@ library LibParseLiteralSubParseable {
// Note that as multibyte is not supported, and the mask is 128 bits,
// non-ascii chars MAY either fail to be skipped or will be treated
// as a closing bracket.
cursor = LibParse.skipMask(cursor, end, ~CMASK_SUB_PARSEABLE_LITERAL_END);
cursor = LibParseChar.skipMask(cursor, end, ~CMASK_SUB_PARSEABLE_LITERAL_END);
uint256 bodyEnd = cursor;

{
Expand Down
1 change: 1 addition & 0 deletions test/src/concrete/RainterpreterStoreNPE2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ contract RainterpreterStoreNPE2Test is Test {
/// is that the fuzzer will generate some dupes just randomly, so there's
/// no special logic to make that happen.
/// forge-config: default.fuzz.runs = 100

function testRainterpreterStoreNPE2SetGetDupes(Set11[] memory sets) external {
vm.assume(sets.length < 20);

Expand Down
34 changes: 0 additions & 34 deletions test/src/lib/parse/LibParse.isMask.t.sol

This file was deleted.

0 comments on commit 724d893

Please sign in to comment.