// Copyright (c) 2015-2021 Martin Hensel// Copyright (c) 2026 luo-studio// Copyright (c) 2026 erweixin (upstream RaTeX)// SPDX-License-Identifier: Apache-2.0 AND MIT//// Go translation and modification of mhchemparser 4.1.1 and upstream RaTeX// table-loading behavior; see PROVENANCE.md for the pinned sources.package mhchemimport (_)// machinesJSON and patternsJSON are generated from the private transition and// pattern tables in mhchemparser 4.1.1's dist/mhchemParser.js. Keeping the// tables as data preserves JavaScript property insertion order in the expanded// transition arrays while the Go engine implements the behavior natively.////go:embed data/machines.jsonvar machinesJSON []byte//go:embed data/patterns.jsonvar patternsJSON []bytetypeMachinesmap[string]MachineDeftypeMachineDefstruct { Transitions map[string][]Transition`json:"transitions"` HasLocalActions bool`json:"hasLocalActions"`}typeTransitionstruct { Pattern string`json:"pattern"` Task Task`json:"task"`}typeTaskstruct { NextState *string`json:"nextState,omitempty"` Revisit bool`json:"revisit,omitempty"` ToContinue bool`json:"toContinue,omitempty"` Action []ActionSpec`json:"action_,omitempty"`}typeActionSpecstruct { Type string`json:"type_"` Option json.RawMessage`json:"option,omitempty"`}typeDatastruct { Machines Machines Regexes map[string]*jsRegexp}var ( loadedData *Data loadedDataOnce sync.Once loadedDataErr error)func () (*Data, error) {loadedDataOnce.Do(func() {loadedData, loadedDataErr = loadDataImpl() })returnloadedData, loadedDataErr}func loadDataImpl() (*Data, error) { := Machines{}if := json.Unmarshal(machinesJSON, &); != nil {returnnil, fmt.Errorf("mhchem: parse machine table: %w", ) }varstruct {map[string]string`json:"regex"` }if := json.Unmarshal(patternsJSON, &); != nil {returnnil, fmt.Errorf("mhchem: parse pattern table: %w", ) } := make(map[string]*jsRegexp, len(.))for , := range . { , := compileJSRegexp()if != nil {returnnil, fmt.Errorf("mhchem: compile pattern %q (%q): %w", , , ) } [] = }return &Data{Machines: , Regexes: }, nil}func () *Data { , := LoadData()if != nil {panic() }return}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.