The name of a module, e.g. Foo.Abs, Foo.Print etc.
ModuleBNFC-2.9.5Haskell2010
BNFC.Utils
- 2 types
- 42 values
- PackageBNFC-2.9.5
- Exports44
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceUtils.hs
Generalization of when.
Generalization of unless.
Invoke continuation for non-empty list.
Invoke continuation for non-empty list.
when for the monoid of endofunctions 'a -> a'.
unless for the monoid of endofunctions 'a -> a'.
Non-monadic forM.
Generalization of forM to Monoid.
Rotation of maybe.
Diagrammatic composition.
Converts an uncurried function to a curried function.
Converts a curried function to a function on a triple.
Give a telling name to the electric monkey.
Get the first element of a list, fallback for empty list.
Apply a function to the head of a list.
spanEnd p l == reverse (span p (reverse l)).
Invariant: l == front ++ end where (end, front) = spanEnd p l
(From package ghc, module Util.)
Returns lists of elements whose normal form appears more than once.
duplicatesOn id [5,1,2,5,1][1 :| [1],5 :| [5]]duplicatesOn abs [5,-5,1][5 :| [-5]]
Group consecutive elements that have the same normalform.
Keep only the first of consecutive elements that have the same normalform.
Get a numeric suffix if it exists.
hasNumericSuffix "hello world"NothinghasNumericSuffix "a1b2"Just ("a1b",2)hasNumericSuffix "1234"Just ("",1234)
Concatenate strings by a space.
Concatenate strings by a newline.
Concatenate strings by an underscore.
Concatenate strings by a dot.
Wrap in parentheses if condition holds.
Pad a string on the right by spaces to reach the desired length.
Make a list of rows with left-aligned columns from a matrix.
Generate a name in the given case style taking into account the reserved word of the language. Note that despite the fact that those name are mainly to be used in code rendering (type Doc), we return a String here to allow further manipulation of the name (like disambiguation) which is not possible in the Doc type.
Examples:
mkName [] LowerCase "FooBAR""foobar"
mkName [] UpperCase "FooBAR""FOOBAR"
mkName [] SnakeCase "FooBAR""foo_bar"
mkName [] CamelCase "FooBAR""FooBAR"
mkName [] CamelCase "Foo_bar""FooBar"
mkName [] MixedCase "FooBAR""fooBAR"
mkName ["foobar"] LowerCase "FooBAR""foobar_"
mkName ["foobar", "foobar_"] LowerCase "FooBAR""foobar__"
Same as above but accept a list as argument and make sure that the names generated are uniques.
mkNames ["c"] LowerCase ["A", "b_", "a_", "c"]["a1","b","a2","c_"]
Different case style
Make first letter uppercase.
Ident to lower case.
>>> lowerCase MyIdent
myident
Ident to upper case.
>>> upperCase MyIdent
MYIDENT
To mixed case. >>> mixedCase "my_ident" myIdent
Ident to camel case. >>> camelCase "my_ident" MyIdent
To snake case.
>>> snakeCase MyIdent
my_ident
Replace all occurences of a value by another value
Write a file, after making a backup of an existing file with the same name. If an old version of the file exist and the new version is the same, keep the old file and don't create a .bak file. / New version by TH, 2010-09-23
A function that renders a c-like string with escaped characters. Note that although it's called cstring, this can be used with most (all) backend as they seem to mostly share escaping conventions. The c in the name is barely an homage for C being the oldest language in the lot.
cstring "foobar""foobar"
cstring "foobar\"""foobar\""
Print a symbol as typical token name, like "(" as LPAREN.