-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathLanguage.cs
69 lines (65 loc) · 2.67 KB
/
Language.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using static LanguageExt.Prelude;
using static LanguageExt.Parsec.Prim;
using static LanguageExt.Parsec.Char;
using static LanguageExt.Parsec.Expr;
using static LanguageExt.Parsec.Token;
namespace LanguageExt.Parsec
{
public static class Language
{
/// <summary>
/// This is a minimal token definition for Haskell style languages. It
/// defines the style of comments, valid identifiers and case
/// sensitivity. It does not define any reserved words or operators.
/// </summary>
public readonly static GenLanguageDef HaskellStyle =
GenLanguageDef.Empty.With(
CommentStart: "{-",
CommentEnd: "-}",
CommentLine: "--",
NestedComments: true,
IdentStart: letter,
IdentLetter: either(alphaNum, oneOf("_'")),
OpStart: oneOf(":!#$%&*+./<=>?@\\^|-~"),
OpLetter: oneOf(":!#$%&*+./<=>?@\\^|-~"),
ReservedOpNames: List<string>(),
ReservedNames: List<string>(),
CaseSensitive: true
);
/// <summary>
/// This is a minimal token definition for Java style languages. It
/// defines the style of comments, valid identifiers and case
/// sensitivity. It does not define any reserved words.
/// </summary>
public readonly static GenLanguageDef JavaStyle =
GenLanguageDef.Empty.With(
CommentStart: "/*",
CommentEnd: "*/",
CommentLine: "//",
NestedComments: true,
IdentStart: letter,
IdentLetter: either(alphaNum, oneOf("_'")),
OpStart: oneOf(@"!%&*+.<=>?@\^|-~"),
OpLetter: oneOf(@"!%&*+.<=>?@\^|-~"),
ReservedOpNames: List<string>(),
ReservedNames: List<string>(),
CaseSensitive: true
);
/// <summary>
/// The language definition for the language Haskell98.
/// </summary>
public readonly static GenLanguageDef Haskell98Def =
HaskellStyle.With(
ReservedOpNames: List.create("::", "..", "=", "\\", "|", "<-", "->", "@", "~", "=>"),
ReservedNames: List.create(
"let", "in", "case", "of", "if", "then", "else",
"data", "type",
"class", "default", "deriving", "do", "import",
"infix", "infixl", "infixr", "instance", "module",
"newtype", "where",
"primitive"));
}
}