[ORC] Merge ostream operators for SymbolStringPtrs into SymbolStringPool.h. NFC.
[llvm-project.git] / flang / lib / Parser / misc-parsers.h
blob4a318e05bb4b8ccfa7e41440a52a8e3f68ae6de4
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 //===----------------------------------------------------------------------===//
9 // Parser templates and constexpr parsers shared by multiple
10 // per-type parser implementation source files.
12 #ifndef FORTRAN_PARSER_MISC_PARSERS_H_
13 #define FORTRAN_PARSER_MISC_PARSERS_H_
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"
21 namespace Fortran::parser {
23 // R401 xzy-list -> xzy [, xzy]...
24 template <typename PA> inline constexpr auto nonemptyList(const PA &p) {
25 return nonemptySeparated(p, ","_tok); // p-list
28 template <typename PA>
29 inline constexpr auto nonemptyList(MessageFixedText error, const PA &p) {
30 return withMessage(error, nonemptySeparated(p, ","_tok)); // p-list
33 template <typename PA> inline constexpr auto optionalList(const PA &p) {
34 return defaulted(nonemptySeparated(p, ","_tok)); // [p-list]
37 // R402 xzy-name -> name
39 // R516 keyword -> name
40 constexpr auto keyword{construct<Keyword>(name)};
42 // R1101 block -> [execution-part-construct]...
43 constexpr auto block{many(executionPartConstruct)};
45 constexpr auto listOfNames{nonemptyList("expected names"_err_en_US, name)};
47 constexpr auto star{construct<Star>("*"_tok)};
48 constexpr auto allocatable{construct<Allocatable>("ALLOCATABLE"_tok)};
49 constexpr auto contiguous{construct<Contiguous>("CONTIGUOUS"_tok)};
50 constexpr auto optional{construct<Optional>("OPTIONAL"_tok)};
51 constexpr auto pointer{construct<Pointer>("POINTER"_tok)};
52 constexpr auto protectedAttr{construct<Protected>("PROTECTED"_tok)};
53 constexpr auto save{construct<Save>("SAVE"_tok)};
55 template <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;
61 template <typename A>
62 common::IfNoLvalue<std::optional<A>, A> presentOptional(A &&x) {
63 return std::make_optional(std::move(x));
65 } // namespace Fortran::parser
66 #endif