<commit_before>implementation module Builtin.Syntax

import StdArray
import StdList
import StdString

import Data.Error
from Data.Func import $
import Data.Maybe
import Text

import Regex
exact s = regex ("^" +++ s +++ "$")

import Cloogle.API
import Cloogle.DB

import Builtin.Predef

builtin_syntax :: [SyntaxEntry]
builtin_syntax =
	[ bs_basicvalues
	, bs_case
	, bs_class
	, bs_code
	, bs_comments
	, bs_context
	, bs_define_constant
	, bs_define_graph
	, bs_dotdot
	, bs_exists
	, bs_extensible_adt
	, bs_forall
	, bs_foreign
	, bs_funcdep
	, bs_function_definition
	, bs_guard
	, bs_generic
	, bs_hierarchical_modules
	, bs_import
	, bs_infix
	, bs_instance
	, bs_lambda
	, bs_layout_rule
	, bs_let
	, bs_let_before
	, bs_list_expressions
	, bs_macro
	, bs_module
	, bs_newtype
	, bs_overloaded_type_variable
	, bs_pattern_named
	, bs_pattern_predicate
	, bs_qualified_identifier
	, bs_record_disambiguation
	, bs_selection_array
	, bs_selection_array_unique
	, bs_selection_record
	, bs_selection_record_unique
	, bs_strict
	, bs_synonym
	, bs_synonym_abstract
	, bs_type_definition
	, bs_type_specification
	, bs_unique
	, bs_update_array
	, bs_update_record
	, bs_where_class
	, bs_where_instance
	, bs_where_local
	, bs_with
	, bs_zf
	]

EX :: !String -> SyntaxExample 
EX c = {example=c, cleanjs_start=Nothing}
EXs :: !String !String -> SyntaxExample
EXs s c = {example=c, cleanjs_start=Just s}

bs_basicvalues =
	{ syntax_title         = "basicvalues"
	, syntax_patterns      = map exact ["'.'", "[+-]?\\d+", "[+-]?0[0-7]+", "[-+]?0x[0-9a-fA-F]+", "'.'", "True", "False", "E"]
	, syntax_code          = ["0x...", "0...", "True", "False", "'...'", "...E..."]
	, syntax_description   =
		"Constant basic values can be of type Int, Char, Real and Bool.\n\n" +
		"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\n\n" +
		"Characters can either be printable characters (except `'`) or an escape sequence.\n\n" +
		"Reals can be suffixed by a power of ten in the scientific notation.\n\n" +
		"Boolean values by their only inhabitants {{True}} and {{False}}.\n\n" +
		"Basic values can also be pattern matched with these notations."
	, syntax_doc_locations = [CLR 4 "1.1" "_Toc311798017"]
	, syntax_examples      = map EX
		[ "(42, -42, +42)          // Tuple with 42, -42 and 42 in decimal"
		, "(052, -052, +052)       // Tuple with 42, -42 and 42 in octal"
		, "(0x2a, -0x2a, +0x2A)    // Tuple with 42, -42 and 42 in hexadecimal"
		, "('a', '\\x2a', '\\052') // Tuple with a normal character, a literal quote and twice the character with ordinal 42"
		, "['\\n', '\\r', '\\f', '\\b', '\\t', '\\', '\'']\n" +
		  "                        //All character escapes"
		, "(True, False)           // All booleans in a tuple"
		, "(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\n" +
		  "                        //Several reals"
		]
	}


bs_case =
	{ syntax_title         = "case expression"
	, syntax_patterns      = map exact ["case", "of", "case of", "->", "="]
	, syntax_code          = ["case ... of ..."]
	, syntax_description   = join " "
		[ "Pattern match on an expression and do something depending on the alternative of the matching pattern."
		, "Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed."
		]
	, syntax_doc_locations = [CLR 5 "3.4.2" "_Toc311798001"]
	, syntax_examples      =
		[ EXs "macro" "isJust m = case m of\n\tJust _ -> True\n\t_      -> False"
		]
	}

bs_class =
	{ syntax_title         = "class"
	, syntax_patterns      = map exact ["class"]
	, syntax_code          =
		[ "class ... ... :: ..."
		, "class ... ... where ..."<commit_msg>fix brackets, title and document location<commit_after>implementation module Builtin.Syntax

import StdArray
import StdList
import StdString

import Data.Error
from Data.Func import $
import Data.Maybe
import Text

import Regex
exact s = regex ("^" +++ s +++ "$")

import Cloogle.API
import Cloogle.DB

import Builtin.Predef

builtin_syntax :: [SyntaxEntry]
builtin_syntax =
	[ bs_basicvalues
	, bs_case
	, bs_class
	, bs_code
	, bs_comments
	, bs_context
	, bs_define_constant
	, bs_define_graph
	, bs_dotdot
	, bs_exists
	, bs_extensible_adt
	, bs_forall
	, bs_foreign
	, bs_funcdep
	, bs_function_definition
	, bs_guard
	, bs_generic
	, bs_hierarchical_modules
	, bs_import
	, bs_infix
	, bs_instance
	, bs_lambda
	, bs_layout_rule
	, bs_let
	, bs_let_before
	, bs_list_expressions
	, bs_macro
	, bs_module
	, bs_newtype
	, bs_overloaded_type_variable
	, bs_pattern_named
	, bs_pattern_predicate
	, bs_qualified_identifier
	, bs_record_disambiguation
	, bs_selection_array
	, bs_selection_array_unique
	, bs_selection_record
	, bs_selection_record_unique
	, bs_strict
	, bs_synonym
	, bs_synonym_abstract
	, bs_type_definition
	, bs_type_specification
	, bs_unique
	, bs_update_array
	, bs_update_record
	, bs_where_class
	, bs_where_instance
	, bs_where_local
	, bs_with
	, bs_zf
	]

EX :: !String -> SyntaxExample 
EX c = {example=c, cleanjs_start=Nothing}
EXs :: !String !String -> SyntaxExample
EXs s c = {example=c, cleanjs_start=Just s}

bs_basicvalues =
	{ syntax_title         = "basic values"
	, syntax_patterns      = map exact ["'.'", "[+-]?\\d+", "[+-]?0[0-7]+", "[-+]?0x[0-9a-fA-F]+", "'.'", "True", "False", "E"]
	, syntax_code          = ["0x...", "0...", "True", "False", "'...'", "...E..."]
	, syntax_description   =
		"Constant basic values can be of type Int, Char, Real and Bool.\n\n" +
		"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\n\n" +
		"Characters can either be printable characters (except `'`) or an escape sequence.\n\n" +
		"Reals can be suffixed by a power of ten in the scientific notation.\n\n" +
		"Boolean values by their only inhabitants {{`True`}} and {{`False`}}.\n\n" +
		"Basic values can also be pattern matched with these notations."
	, syntax_doc_locations = [CLR 4 "4.1.1" "_Toc311798017"]
	, syntax_examples      = map EX
		[ "(42, -42, +42)          // Tuple with 42, -42 and 42 in decimal"
		, "(052, -052, +052)       // Tuple with 42, -42 and 42 in octal"
		, "(0x2a, -0x2a, +0x2A)    // Tuple with 42, -42 and 42 in hexadecimal"
		, "('a', '\\x2a', '\\052')  // Tuple with a normal character, a literal quote and twice the character with ordinal 42"
		, "['\\n', '\\r', '\\f', '\\b', '\\t', '\\', '\'']\n" +
		  "                        // All character escapes"
		, "(True, False)           // All booleans in a tuple"
		, "(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\n" +
		  "                        // Several reals"
		]
	}


bs_case =
	{ syntax_title         = "case expression"
	, syntax_patterns      = map exact ["case", "of", "case of", "->", "="]
	, syntax_code          = ["case ... of ..."]
	, syntax_description   = join " "
		[ "Pattern match on an expression and do something depending on the alternative of the matching pattern."
		, "Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed."
		]
	, syntax_doc_locations = [CLR 5 "3.4.2" "_Toc311798001"]
	, syntax_examples      =
		[ EXs "macro" "isJust m = case m of\n\tJust _ -> True\n\t_      -> False"
		]
	}

bs_class =
	{ syntax_title         = "class"
	, syntax_patterns      = map exact ["class"]
	, syntax_code          =
		[ "class ... ... :: ..."
		, "class ... ... where ..."
{'fraction_non_alphanumeric': 0.14909189482244511, 'fraction_numerical': 0.027243155326646788, 'mean_word_length': 2.9778975741239893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '742582', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2705, 'n_words': 698}