Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
- data UnquotedString
- unquotedString'try :: Text -> Maybe UnquotedString
- unquotedString'orThrow :: Text -> UnquotedString
- unquotedString'text :: UnquotedString -> Text
- text'canBeUnquoted :: Text -> Bool
- char'canBeUnquoted :: Char -> Bool
Type
data UnquotedString Source #
A string that can be rendered unquoted. Unquoted strings are restricted to
a conservative set of characters; see text'canBeUnquoted
for the full rules.
This type does not represent a particular part of Bricks syntax, but it is a
wrapper for Text
that enforces the limitations of strings at various places in
the Bricks syntax.
Construction
Deconstruction
See also
Construction
unquotedString'try :: Text -> Maybe UnquotedString Source #
Properties
A text value may be used to construct an
UnquotedString
iff it satisfiestext'canBeUnquoted
.text'canBeUnquoted
x =isJust
(unquotedString'try
x)
unquotedString'orThrow :: Text -> UnquotedString Source #
Throws an exception if the string cannot render unquoted.
Deconstruction
Predicates
text'canBeUnquoted :: Text -> Bool Source #
Whether a string having this name can be rendered without quoting it.
Requirements for unquoted strings
We allow a string to render unquoted if all these conditions are met:
- The string is nonempty
- All characters satify
char'canBeUnquoted
- The string is not a keyword
Properties
A text value may be used to construct an
UnquotedString
iff it satisfiestext'canBeUnquoted
.text'canBeUnquoted
x =isJust
(unquotedString'try
x)
Examples
>>>
text'canBeUnquoted "-ab_c"
True
>>>
text'canBeUnquoted ""
False
>>>
text'canBeUnquoted "a\"b"
False
>>>
text'canBeUnquoted "let"
False
char'canBeUnquoted :: Char -> Bool Source #
Whether the character is allowed to be included in an UnquotedString
.
Such characters are letters, +
, -
, *
, /
, and _
.
This is used in the implementation of text'canBeUnquoted
.