Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added if statement to demos, updated syntax highlighter

  • Loading branch information...
commit dd4630915d45f7582dd510667a129df5e9bb6f56 1 parent 5cbd245
Mariano Guerra authored
Showing with 109 additions and 16 deletions.
  1. +21 −4 examples/demo.fn
  2. +21 −4 examples/demo.ifn
  3. +67 −8 extras/pygments.py
25 examples/demo.fn
View
@@ -1,5 +1,18 @@
+# if statement
+compare_if = fn (A, B) {
+ if A < B {
+ lt
+ }
+ else if A > B {
+ gt
+ }
+ else {
+ eq
+ }
+}
+
# when statement
-compare = fn (A, B) {
+compare_when = fn (A, B) {
when A < B {
lt
}
@@ -83,9 +96,13 @@ run = fn () {
# lambda functions
Print = fn (Expr) { io.format("~p~n", [Expr]) }
- Print(compare(1, 2))
- Print(compare(2, 1))
- Print(compare(2, 2))
+ Print(compare_when(1, 2))
+ Print(compare_when(2, 1))
+ Print(compare_when(2, 2))
+
+ Print(compare_if(1, 2))
+ Print(compare_if(2, 1))
+ Print(compare_if(2, 2))
Print(compare_to_string(lt))
Print(compare_to_string(gt))
25 examples/demo.ifn
View
@@ -1,11 +1,24 @@
# a demo that shows different expressions
+# if statement
+compare_if = fn (A, B)
+ if A < B
+ lt
+
+ else if A > B
+ gt
+
+ else
+ eq
+
# when statement
-compare = fn (A, B)
+compare_when = fn (A, B)
when A < B
lt
+
else when A > B
gt
+
else
eq
@@ -62,9 +75,13 @@ run = fn ()
# lambda functions
Print = fn (Expr) { io.format("~p~n", [Expr]) }
- Print(compare(1, 2))
- Print(compare(2, 1))
- Print(compare(2, 2))
+ Print(compare_when(1, 2))
+ Print(compare_when(2, 1))
+ Print(compare_when(2, 2))
+
+ Print(compare_if(1, 2))
+ Print(compare_if(2, 1))
+ Print(compare_if(2, 2))
Print(compare_to_string(lt))
Print(compare_to_string(gt))
75 extras/pygments.py
View
@@ -1,4 +1,3 @@
-
class EfeneLexer(RegexLexer):
"""
For efene source code.
@@ -10,17 +9,77 @@ class EfeneLexer(RegexLexer):
mimetypes = ['application/x-efene', 'text/x-efene', 'text/efene']
flags = re.DOTALL
+ keywords = [
+ 'after', 'switch', 'case', 'catch', 'else', 'fn', 'object', 'if',
+ 'record', 'for', 'in', 'receive', 'try', 'when',
+ ]
+
+ builtins = [ # See erlang(3) man page
+ 'abs', 'append_element', 'apply', 'atom_to_list', 'binary_to_list',
+ 'bitstring_to_list', 'binary_to_term', 'bit_size', 'bump_reductions',
+ 'byte_size', 'cancel_timer', 'check_process_code', 'delete_module',
+ 'demonitor', 'disconnect_node', 'display', 'element', 'erase', 'exit',
+ 'float', 'float_to_list', 'fun_info', 'fun_to_list',
+ 'function_exported', 'garbage_collect', 'get', 'get_keys',
+ 'group_leader', 'hash', 'hd', 'integer_to_list', 'iolist_to_binary',
+ 'iolist_size', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean',
+ 'is_builtin', 'is_float', 'is_function', 'is_integer', 'is_list',
+ 'is_number', 'is_pid', 'is_port', 'is_process_alive', 'is_record',
+ 'is_reference', 'is_tuple', 'length', 'link', 'list_to_atom',
+ 'list_to_binary', 'list_to_bitstring', 'list_to_existing_atom',
+ 'list_to_float', 'list_to_integer', 'list_to_pid', 'list_to_tuple',
+ 'load_module', 'localtime_to_universaltime', 'make_tuple', 'md5',
+ 'md5_final', 'md5_update', 'memory', 'module_loaded', 'monitor',
+ 'monitor_node', 'node', 'nodes', 'open_port', 'phash', 'phash2',
+ 'pid_to_list', 'port_close', 'port_command', 'port_connect',
+ 'port_control', 'port_call', 'port_info', 'port_to_list',
+ 'process_display', 'process_flag', 'process_info', 'purge_module',
+ 'put', 'read_timer', 'ref_to_list', 'register', 'resume_process',
+ 'round', 'send', 'send_after', 'send_nosuspend', 'set_cookie',
+ 'setelement', 'size', 'spawn', 'spawn_link', 'spawn_monitor',
+ 'spawn_opt', 'split_binary', 'start_timer', 'statistics',
+ 'suspend_process', 'system_flag', 'system_info', 'system_monitor',
+ 'system_profile', 'term_to_binary', 'tl', 'trace', 'trace_delivered',
+ 'trace_info', 'trace_pattern', 'trunc', 'tuple_size', 'tuple_to_list',
+ 'universaltime_to_localtime', 'unlink', 'unregister', 'whereis'
+ ]
+
+ operators = r'(\+|-|\*|/|%|<|>|=|==|!=|===|!==|<=|>=|\+\+|--|->|!|\^|\|\&|~|<<|>>)'
+ word_operators = [
+ 'and', 'andd', 'not', 'or', 'xor', 'orr'
+ ]
+
+ atom_re = r"(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')"
+
+ variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
+
+ escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
+
+ base_re = r'(?:[2-9]|[12][0-9]|3[0-6])'
+
tokens = {
'root': [
(r'\s+', Text),
(r'#.*?\n', Comment),
- (r'[~\^\*!%&<>\|+=:;,/?\\-@]+', Operator),
- (r'[{}\[\]();.,]+', Punctuation),
- (r'(for|in|if|else|try|catch|receive|after|fn|when|and|andd|or|orr|xor|not|switch|case|public)\b', Keyword),
+ (r'[{}\[\]():;.,@]+', Punctuation),
(r'(true|false)\b', Keyword.Constant),
- (r'[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other),
- (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
- (r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
- ]
+ ('(' + '|'.join(keywords) + r')\b', Keyword),
+ ('(' + '|'.join(builtins) + r')\b', Name.Builtin),
+ ('(' + '|'.join(word_operators) + r')\b', Operator.Word),
+ (operators, Operator),
+ (variable_re, Name.Variable),
+ (atom_re, Name),
+ (r'('+atom_re+')(\.)', bygroups(Name.Namespace, Punctuation)),
+ (r'^('+atom_re+r')\s*(=)\s*(fn)\s*(\()', bygroups(Name.Function, Operator, Keyword, Punctuation)),
+ (r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char),
+ (r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label),
+ ],
+ 'numbers': [
+ (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
+ (r'0\d+', Number.Oct),
+ (r'0[xX][a-fA-F0-9]+', Number.Hex),
+ (r'\d+', Number.Integer)
+ ],
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.