ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.P96

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P96.

Synopsis

Documentation

isIdentifier :: String -> Bool Source #

Identifiers in the Ada programming language have the syntax described by the diagram below.

Write a function which checks whether a given string is a legal identifier.

Examples

>>> isIdentifier "this_is_a_long_identifier"
True
>>> isIdentifier "This_ends_in_an_underscore_"
False
>>> isIdentifier "This__has__two__consecutive__underscores"
False
>>> isIdentifier "1234"
False
>>> isIdentifier "_legal_in_many_other_languages"
False
>>> isIdentifier "Fibonacci_sequence_is_1_1_2_3_5_8_13_21_ad_infinitum"
True

Hint

Expand

Translate the syntax diagram into a recursive grammar.