A start on rudimentary indexing

This commit is contained in:
Ben Edgington
2021-11-20 22:28:46 +00:00
parent 713141d996
commit 317e7e2a01
2 changed files with 285 additions and 0 deletions

78
bin/index.awk Executable file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/gawk -f
# Builds a JSON index from a file of keywords
#
# ./index.awk words.txt ../src/book.md
#
# Should probably escape quotation marks in page_name and heading
BEGIN {
ORS=""
}
# First pass: build list of things to index
FNR == NR {
refs[$0] = ""
next
}
# Record the current page
/(^# |^## |^### ).* <!-- .* -->$/ {
page_name = gensub(/^#+ (.*) <!-- .* -->$/, "\\1", "1")
page_path = gensub(/^#+ .* <!-- ([^*]+).? -->$/, "\\1", "1")
}
# Record the most recent anchor heading
/^#/ {
heading = ""
if ($0 ~ / <!-- .* -->$/) {
heading = gensub(/^#+ (.*) <!-- .* -->$/, "\\1", "1")
} else {
heading = gensub(/^#+ (.*)$/, "\\1", "1")
}
gsub(/`/, "", heading)
anchor = tolower(heading)
gsub(/ /, "-", anchor)
gsub(/[^a-z0-9_-]/, "", anchor)
for (word in refs) {
done[word] = 0
}
}
# Skipping empty lines gives a nice speed-up
length {
for (word in refs) {
if (!done[word] && match($0, word)) {
refs[word] = refs[word] "\"" page_path "#" anchor "\","
heads[page_path "#" anchor] = "[\"" page_name "\",\"" heading "\"]"
done[word] = 1
}
}
}
END {
print "{\"refs\":{"
count = length(refs)
for (word in refs) {
count--
references = refs[word]
if (references) {
#remove trailing commas
sub(/,$/, "", references)
print "\"" word "\":[" references "]"
if (count) print ","
}
}
print "},\"heads\":{"
count = length(heads)
for (anchor in heads) {
count--
headings = heads[anchor]
if (headings) {
print "\"" anchor "\":" headings
if (count) print ","
}
}
print "}}"
}

207
bin/words.txt Normal file
View File

@@ -0,0 +1,207 @@
`Slot`
`Epoch`
`CommitteeIndex`
`ValidatorIndex`
`Gwei`
`Root`
`Hash32`
`Version`
`DomainType`
`ForkDigest`
`Domain`
`BLSPubkey`
`BLSSignature`
`ParticipationFlags`
`Fork`
`ForkData`
`Checkpoint`
`Validator`
`AttestationData`
`IndexedAttestation`
`PendingAttestation`
`Eth1Data`
`HistoricalBatch`
`DepositMessage`
`DepositData`
`BeaconBlockHeader`
`SigningData`
`ProposerSlashing`
`AttesterSlashing`
`Attestation`
`Deposit`
`VoluntaryExit`
`BeaconBlockBody`
`BeaconBlock`
`BeaconState`
`SignedVoluntaryExit`
`SignedBeaconBlock`
`SignedBeaconBlockHeader`
`SyncAggregate`
`SyncCommittee`
`GENESIS_SLOT`
`GENESIS_EPOCH`
`FAR_FUTURE_EPOCH`
`DEPOSIT_CONTRACT_TREE_DEPTH`
`JUSTIFICATION_BITS_LENGTH`
`PARTICIPATION_FLAG_WEIGHTS`
`ENDIANNESS`
`TIMELY_SOURCE_FLAG_INDEX`
`TIMELY_TARGET_FLAG_INDEX`
`TIMELY_HEAD_FLAG_INDEX`
`TIMELY_SOURCE_WEIGHT`
`TIMELY_TARGET_WEIGHT`
`TIMELY_HEAD_WEIGHT`
`SYNC_REWARD_WEIGHT`
`PROPOSER_WEIGHT`
`WEIGHT_DENOMINATOR`
`BLS_WITHDRAWAL_PREFIX`
`ETH1_ADDRESS_WITHDRAWAL_PREFIX`
`DOMAIN_BEACON_PROPOSER`
`DOMAIN_BEACON_ATTESTER`
`DOMAIN_RANDAO`
`DOMAIN_DEPOSIT`
`DOMAIN_VOLUNTARY_EXIT`
`DOMAIN_SELECTION_PROOF`
`DOMAIN_AGGREGATE_AND_PROOF`
`DOMAIN_SYNC_COMMITTEE`
`DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF`
`DOMAIN_CONTRIBUTION_AND_PROOF`
`G2_POINT_AT_INFINITY`
`MAX_COMMITTEES_PER_SLOT`
`TARGET_COMMITTEE_SIZE`
`MAX_VALIDATORS_PER_COMMITTEE`
`SHUFFLE_ROUND_COUNT`
`HYSTERESIS_QUOTIENT`
`HYSTERESIS_DOWNWARD_MULTIPLIER`
`HYSTERESIS_UPWARD_MULTIPLIER`
`MIN_DEPOSIT_AMOUNT`
`MAX_EFFECTIVE_BALANCE`
`EFFECTIVE_BALANCE_INCREMENT`
`MIN_ATTESTATION_INCLUSION_DELAY`
`SLOTS_PER_EPOCH`
`MIN_SEED_LOOKAHEAD`
`MAX_SEED_LOOKAHEAD`
`MIN_EPOCHS_TO_INACTIVITY_PENALTY`
`EPOCHS_PER_ETH1_VOTING_PERIOD`
`SLOTS_PER_HISTORICAL_ROOT`
`EPOCHS_PER_HISTORICAL_VECTOR`
`EPOCHS_PER_SLASHINGS_VECTOR`
`HISTORICAL_ROOTS_LIMIT`
`VALIDATOR_REGISTRY_LIMIT`
`BASE_REWARD_FACTOR`
`WHISTLEBLOWER_REWARD_QUOTIENT`
`PROPOSER_REWARD_QUOTIENT`
`INACTIVITY_PENALTY_QUOTIENT`
`MIN_SLASHING_PENALTY_QUOTIENT`
`PROPORTIONAL_SLASHING_MULTIPLIER`
`INACTIVITY_PENALTY_QUOTIENT_ALTAIR`
`MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR`
`PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR`
`MAX_PROPOSER_SLASHINGS`
`MAX_ATTESTER_SLASHINGS`
`MAX_ATTESTATIONS`
`MAX_DEPOSITS`
`MAX_VOLUNTARY_EXITS`
`SYNC_COMMITTEE_SIZE`
`EPOCHS_PER_SYNC_COMMITTEE_PERIOD`
`GENESIS_FORK_VERSION`
`GENESIS_DELAY`
`SECONDS_PER_SLOT`
`SECONDS_PER_ETH1_BLOCK`
`MIN_VALIDATOR_WITHDRAWABILITY_DELAY`
`SHARD_COMMITTEE_PERIOD`
`ETH1_FOLLOW_DISTANCE`
`EJECTION_BALANCE`
`MIN_PER_EPOCH_CHURN_LIMIT`
`CHURN_LIMIT_QUOTIENT`
`INACTIVITY_SCORE_BIAS`
`INACTIVITY_SCORE_RECOVERY_RATE`
`integer_squareroot`
`xor`
`bytes_to_uint64`
`eth_aggregate_pubkeys`
`eth_fast_aggregate_verify`
`is_active_validator`
`is_eligible_for_activation_queue`
`is_eligible_for_activation`
`is_slashable_validator`
`is_slashable_attestation_data`
`is_valid_indexed_attestation`
`is_valid_merkle_branch`
`compute_shuffled_index`
`compute_proposer_index`
`compute_committee`
`compute_epoch_at_slot`
`compute_start_slot_at_epoch`
`compute_activation_exit_epoch`
`compute_fork_data_root`
`compute_fork_digest`
`compute_domain`
`compute_signing_root`
`add_flag`
`has_flag`
`get_current_epoch`
`get_previous_epoch`
`get_block_root`
`get_block_root_at_slot`
`get_randao_mix`
`get_active_validator_indices`
`get_validator_churn_limit`
`get_seed`
`get_committee_count_per_slot`
`get_beacon_committee`
`get_beacon_proposer_index`
`get_total_balance`
`get_total_active_balance`
`get_domain`
`get_indexed_attestation`
`get_attesting_indices`
`get_next_sync_committee_indices`
`get_next_sync_committee`
`get_unslashed_participating_indices`
`get_attestation_participation_flag_indices`
`get_flag_index_deltas`
`increase_balance`
`decrease_balance`
`initiate_validator_exit`
`slash_validator`
`state_transition`
`verify_block_signature`
`process_slots`
`process_slot`
`process_epoch`
`process_justification_and_finalization`
`weigh_justification_and_finalization`
`process_inactivity_updates`
`get_base_reward_per_increment`
`get_base_reward`
`get_finality_delay`
`is_in_inactivity_leak`
`get_eligible_validator_indices`
`get_inactivity_penalty_deltas`
`process_rewards_and_penalties`
`process_registry_updates`
`process_slashings`
`process_eth1_data_reset`
`process_effective_balance_updates`
`process_slashings_reset`
`process_randao_mixes_reset`
`process_historical_roots_update`
`process_participation_flag_updates`
`process_sync_committee_updates`
`process_block`
`process_block_header`
`process_randao`
`process_eth1_data`
`process_operations`
`process_proposer_slashing`
`process_attester_slashing`
`process_attestation`
`get_validator_from_deposit`
`process_deposit`
`process_voluntary_exit`
`process_sync_aggregate`
`initialize_beacon_state_from_eth1`
`is_valid_genesis_state`
`translate_participation`
`upgrade_to_altair`