src/rules/style/numeral.bend checks
raw source on the hub · import bolt@1.65.0.0/src/rules/style/numeral.bend as Numeral
rule numeral: a Nat written as a conversion of a U32 literal. Among
the significant tokens (spaces, newlines and comments dropped): a dotted
U32.to_nat, (, a number written in decimal digits alone, and ),
right after one another. One finding, on the U32.to_nat token.
U32.to_nat(1024) is the Nat literal 1024n: the same value, in every
place a term may stand, for every number a U32 literal can hold (a
Nat literal runs to 4294967295n too). The literal says the number
once and is what the reader looks for; and where a law's statement
reaches the def, the checker keeps a literal as it is and has to run the
conversion (bend 2.0.40, one comparison of two such numbers: 0.43 s and
164 MB written as literals, 0.88 s and 225 MB as conversions).
Left alone: a conversion of anything but digits (U32.to_nat(n),
U32.to_nat(1 + 2), U32.to_nat(5n)), a qualified or aliased name, and
the shape written inside a string or a comment. A LAWS.bend or a
PROOF.bend is exempt, and so is a law and a def that is a proof
(def f(x):, or one that returns -> {..}) in any file, from its
keyword to the next def, type or import
(src/rules/suspicious/empty.bend's reading of one): a proof holds the
shape a lemma was stated in, U32.to_nat(0) where the lemma says
U32.to_nat(x).
9 imports
import Base import ../../src.bend as Src import ../../paths.bend as Paths import ../../role.bend as Role import ../../lazy/lazy.bend as Lazy import ../../finding.bend as F import ../../syntax/lex.bend as Lex import ../tokens.bend as T import ../suspicious/empty.bend as Empty
Definitions
def digits.all source · line 34 · raw
@cs:List<&2, Char> -> Bool
are the chars all decimal digits?
def digits source · line 42 · raw
@+t:String -> Bool
is the text one or more decimal digits and nothing else?
def literal source · line 47 · raw
@k:0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.TokKind -> @+t:String -> String
a number token written in digits alone: its text; "" for anything else
(5n, 1.5, a name)
def at.go source · line 55 · raw
@ok:Bool -> @ds:String -> String
the digits, when the brackets are where they belong; "" when not
def at source · line 64 · raw
@toks:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> String
the tokens after a U32.to_nat: (, a number in digits and )? Then
the digits, "" for any other shape
def named source · line 72 · raw
@k:0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.TokKind -> @t:String -> Bool
a dotted U32.to_nat?
def found.go source · line 80 · raw
@name:Bool -> @rest:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> String
the digits of the conversion a token opens, if it is U32.to_nat
def found source · line 89 · raw
@skip:Bool -> @k:0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.TokKind -> @t:String -> @rest:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> String
the digits of a token's conversion, outside a law and a def that is a proof
def say source · line 97 · raw
@+ds:String -> String
what a finding says: the conversion, and the literal for it
def cite source · line 101 · raw
@ds:String -> @path:String -> @l:U32 -> @c:U32 -> 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding
the finding on a U32.to_nat, over its ten chars
def hit.go source · line 105 · raw
@none:Bool -> @ds:String -> @path:String -> @l:U32 -> @c:U32 -> @more:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding> -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>
a finding when there are digits, before the rest
def hit source · line 113 · raw
@+ds:String -> @path:String -> @l:U32 -> @c:U32 -> @more:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding> -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>
the finding a conversion makes, if any, before the rest
def walk source · line 118 · raw
@toks:List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/syntax/lex.Tok> -> @+path:String -> @skip:Bool -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>
every such conversion among the tokens, in order; skip says whether the tokens so far sit in a law or a def that is a proof
def check source · line 127 · raw
@s:0xdaa3743e782ddca8ff3f355948b1d747/src/src.Src -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>
the rule
def check.role source · line 133 · raw
@r:0xdaa3743e782ddca8ff3f355948b1d747/src/role.Role -> @s:0xdaa3743e782ddca8ff3f355948b1d747/src/src.Src -> List<&2, 0xdaa3743e782ddca8ff3f355948b1d747/src/finding.Finding>
the rule, told the file's role (src/role.bend): a law or proof file is skipped