1//===-- lib/Parser/misc-parsers.h -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// Parser templates and constexpr parsers shared by multiple
10// per-type parser implementation source files.
11
12#ifndef FORTRAN_PARSER_MISC_PARSERS_H_
13#define FORTRAN_PARSER_MISC_PARSERS_H_
14
15#include "basic-parsers.h"
16#include "token-parsers.h"
17#include "type-parsers.h"
18#include "flang/Parser/message.h"
19#include "flang/Parser/parse-tree.h"
20
21namespace Fortran::parser {
22
23// R401 xzy-list -> xzy [, xzy]...
24template <typename PA> inline constexpr auto nonemptyList(const PA &p) {
25 return nonemptySeparated(p, ","_tok); // p-list
26}
27
28template <typename PA>
29inline constexpr auto nonemptyList(MessageFixedText error, const PA &p) {
30 return withMessage(error, nonemptySeparated(p, ","_tok)); // p-list
31}
32
33template <typename PA> inline constexpr auto optionalList(const PA &p) {
34 return defaulted(nonemptySeparated(p, ","_tok)); // [p-list]
35}
36
37// R402 xzy-name -> name
38
39// R516 keyword -> name
40constexpr auto keyword{construct<Keyword>(name)};
41
42// R1101 block -> [execution-part-construct]...
43constexpr auto block{many(executionPartConstruct)};
44
45constexpr auto listOfNames{nonemptyList("expected names"_err_en_US, name)};
46
47constexpr auto star{construct<Star>("*"_tok)};
48constexpr auto allocatable{construct<Allocatable>("ALLOCATABLE"_tok)};
49constexpr auto contiguous{construct<Contiguous>("CONTIGUOUS"_tok)};
50constexpr auto optional{construct<Optional>("OPTIONAL"_tok)};
51constexpr auto pointer{construct<Pointer>("POINTER"_tok)};
52constexpr auto protectedAttr{construct<Protected>("PROTECTED"_tok)};
53constexpr auto save{construct<Save>("SAVE"_tok)};
54
55template <typename A> common::IfNoLvalue<std::list<A>, A> singletonList(A &&x) {
56 std::list<A> result;
57 result.emplace_back(std::move(x));
58 return result;
59}
60
61template <typename A>
62common::IfNoLvalue<std::optional<A>, A> presentOptional(A &&x) {
63 return std::make_optional(std::move(x));
64}
65} // namespace Fortran::parser
66#endif
67

source code of flang/lib/Parser/misc-parsers.h