Skip to content
This repository
Browse code

added if statement to demos, updated syntax highlighter

  • Loading branch information...
commit dd4630915d45f7582dd510667a129df5e9bb6f56 1 parent 5cbd245
Mariano Guerra authored

Showing 3 changed files with 109 additions and 16 deletions. Show diff stats Hide diff stats

  1. +21 4 examples/demo.fn
  2. +21 4 examples/demo.ifn
  3. +67 8 extras/pygments.py
25 examples/demo.fn
... ... @@ -1,5 +1,18 @@
  1 +# if statement
  2 +compare_if = fn (A, B) {
  3 + if A < B {
  4 + lt
  5 + }
  6 + else if A > B {
  7 + gt
  8 + }
  9 + else {
  10 + eq
  11 + }
  12 +}
  13 +
1 14 # when statement
2   -compare = fn (A, B) {
  15 +compare_when = fn (A, B) {
3 16 when A < B {
4 17 lt
5 18 }
@@ -83,9 +96,13 @@ run = fn () {
83 96 # lambda functions
84 97 Print = fn (Expr) { io.format("~p~n", [Expr]) }
85 98
86   - Print(compare(1, 2))
87   - Print(compare(2, 1))
88   - Print(compare(2, 2))
  99 + Print(compare_when(1, 2))
  100 + Print(compare_when(2, 1))
  101 + Print(compare_when(2, 2))
  102 +
  103 + Print(compare_if(1, 2))
  104 + Print(compare_if(2, 1))
  105 + Print(compare_if(2, 2))
89 106
90 107 Print(compare_to_string(lt))
91 108 Print(compare_to_string(gt))
25 examples/demo.ifn
... ... @@ -1,11 +1,24 @@
1 1 # a demo that shows different expressions
2 2
  3 +# if statement
  4 +compare_if = fn (A, B)
  5 + if A < B
  6 + lt
  7 +
  8 + else if A > B
  9 + gt
  10 +
  11 + else
  12 + eq
  13 +
3 14 # when statement
4   -compare = fn (A, B)
  15 +compare_when = fn (A, B)
5 16 when A < B
6 17 lt
  18 +
7 19 else when A > B
8 20 gt
  21 +
9 22 else
10 23 eq
11 24
@@ -62,9 +75,13 @@ run = fn ()
62 75 # lambda functions
63 76 Print = fn (Expr) { io.format("~p~n", [Expr]) }
64 77
65   - Print(compare(1, 2))
66   - Print(compare(2, 1))
67   - Print(compare(2, 2))
  78 + Print(compare_when(1, 2))
  79 + Print(compare_when(2, 1))
  80 + Print(compare_when(2, 2))
  81 +
  82 + Print(compare_if(1, 2))
  83 + Print(compare_if(2, 1))
  84 + Print(compare_if(2, 2))
68 85
69 86 Print(compare_to_string(lt))
70 87 Print(compare_to_string(gt))
75 extras/pygments.py
... ... @@ -1,4 +1,3 @@
1   -
2 1 class EfeneLexer(RegexLexer):
3 2 """
4 3 For efene source code.
@@ -10,17 +9,77 @@ class EfeneLexer(RegexLexer):
10 9 mimetypes = ['application/x-efene', 'text/x-efene', 'text/efene']
11 10
12 11 flags = re.DOTALL
  12 + keywords = [
  13 + 'after', 'switch', 'case', 'catch', 'else', 'fn', 'object', 'if',
  14 + 'record', 'for', 'in', 'receive', 'try', 'when',
  15 + ]
  16 +
  17 + builtins = [ # See erlang(3) man page
  18 + 'abs', 'append_element', 'apply', 'atom_to_list', 'binary_to_list',
  19 + 'bitstring_to_list', 'binary_to_term', 'bit_size', 'bump_reductions',
  20 + 'byte_size', 'cancel_timer', 'check_process_code', 'delete_module',
  21 + 'demonitor', 'disconnect_node', 'display', 'element', 'erase', 'exit',
  22 + 'float', 'float_to_list', 'fun_info', 'fun_to_list',
  23 + 'function_exported', 'garbage_collect', 'get', 'get_keys',
  24 + 'group_leader', 'hash', 'hd', 'integer_to_list', 'iolist_to_binary',
  25 + 'iolist_size', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean',
  26 + 'is_builtin', 'is_float', 'is_function', 'is_integer', 'is_list',
  27 + 'is_number', 'is_pid', 'is_port', 'is_process_alive', 'is_record',
  28 + 'is_reference', 'is_tuple', 'length', 'link', 'list_to_atom',
  29 + 'list_to_binary', 'list_to_bitstring', 'list_to_existing_atom',
  30 + 'list_to_float', 'list_to_integer', 'list_to_pid', 'list_to_tuple',
  31 + 'load_module', 'localtime_to_universaltime', 'make_tuple', 'md5',
  32 + 'md5_final', 'md5_update', 'memory', 'module_loaded', 'monitor',
  33 + 'monitor_node', 'node', 'nodes', 'open_port', 'phash', 'phash2',
  34 + 'pid_to_list', 'port_close', 'port_command', 'port_connect',
  35 + 'port_control', 'port_call', 'port_info', 'port_to_list',
  36 + 'process_display', 'process_flag', 'process_info', 'purge_module',
  37 + 'put', 'read_timer', 'ref_to_list', 'register', 'resume_process',
  38 + 'round', 'send', 'send_after', 'send_nosuspend', 'set_cookie',
  39 + 'setelement', 'size', 'spawn', 'spawn_link', 'spawn_monitor',
  40 + 'spawn_opt', 'split_binary', 'start_timer', 'statistics',
  41 + 'suspend_process', 'system_flag', 'system_info', 'system_monitor',
  42 + 'system_profile', 'term_to_binary', 'tl', 'trace', 'trace_delivered',
  43 + 'trace_info', 'trace_pattern', 'trunc', 'tuple_size', 'tuple_to_list',
  44 + 'universaltime_to_localtime', 'unlink', 'unregister', 'whereis'
  45 + ]
  46 +
  47 + operators = r'(\+|-|\*|/|%|<|>|=|==|!=|===|!==|<=|>=|\+\+|--|->|!|\^|\|\&|~|<<|>>)'
  48 + word_operators = [
  49 + 'and', 'andd', 'not', 'or', 'xor', 'orr'
  50 + ]
  51 +
  52 + atom_re = r"(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')"
  53 +
  54 + variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
  55 +
  56 + escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
  57 +
  58 + base_re = r'(?:[2-9]|[12][0-9]|3[0-6])'
  59 +
13 60 tokens = {
14 61 'root': [
15 62 (r'\s+', Text),
16 63 (r'#.*?\n', Comment),
17   - (r'[~\^\*!%&<>\|+=:;,/?\\-@]+', Operator),
18   - (r'[{}\[\]();.,]+', Punctuation),
19   - (r'(for|in|if|else|try|catch|receive|after|fn|when|and|andd|or|orr|xor|not|switch|case|public)\b', Keyword),
  64 + (r'[{}\[\]():;.,@]+', Punctuation),
20 65 (r'(true|false)\b', Keyword.Constant),
21   - (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
22   - (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
23   - (r'[0-9]+', Number.Integer),
24 66 (r'"(\\\\|\\"|[^"])*"', String.Double),
25   - ]
  67 + ('(' + '|'.join(keywords) + r')\b', Keyword),
  68 + ('(' + '|'.join(builtins) + r')\b', Name.Builtin),
  69 + ('(' + '|'.join(word_operators) + r')\b', Operator.Word),
  70 + (operators, Operator),
  71 + (variable_re, Name.Variable),
  72 + (atom_re, Name),
  73 + (r'('+atom_re+')(\.)', bygroups(Name.Namespace, Punctuation)),
  74 + (r'^('+atom_re+r')\s*(=)\s*(fn)\s*(\()', bygroups(Name.Function, Operator, Keyword, Punctuation)),
  75 + (r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char),
  76 + (r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label),
  77 + ],
  78 + 'numbers': [
  79 + (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
  80 + (r'0\d+', Number.Oct),
  81 + (r'0[xX][a-fA-F0-9]+', Number.Hex),
  82 + (r'\d+', Number.Integer)
  83 + ],
26 84 }
  85 +

0 comments on commit dd46309

Please sign in to comment.
Something went wrong with that request. Please try again.