summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndr?s Carrasco <andres.c.k@gmail.com>2018-04-17 19:11:12 +0200
committerAndr?s Carrasco <andres.c.k@gmail.com>2018-04-17 19:11:12 +0200
commite3872ea8f65ac2c3c40046a7a3acf4f0541f0e56 (patch)
treed348507792d7b92129378e6f6cb0b2cb66dbb5d7
parent0db8e281af377923115b894703b2b8beb8f1e9d5 (diff)
downloadpygments-e3872ea8f65ac2c3c40046a7a3acf4f0541f0e56.tar.gz
Add a lexer for the Boa Domain-Specific Langauge.
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/boa.py80
-rw-r--r--tests/examplefiles/example.boa18
3 files changed, 99 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index b48ee1d1..a176238e 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -59,6 +59,7 @@ LEXERS = {
'BlitzBasicLexer': ('pygments.lexers.basic', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)),
'BlitzMaxLexer': ('pygments.lexers.basic', 'BlitzMax', ('blitzmax', 'bmax'), ('*.bmx',), ('text/x-bmx',)),
'BnfLexer': ('pygments.lexers.grammar_notation', 'BNF', ('bnf',), ('*.bnf',), ('text/x-bnf',)),
+ 'BoaLexer': ('pygments.lexers.boa', 'Boa', ('boa',), ('*.boa',), ()),
'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)),
'BoogieLexer': ('pygments.lexers.verification', 'Boogie', ('boogie',), ('*.bpl',), ()),
'BrainfuckLexer': ('pygments.lexers.esoteric', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)),
diff --git a/pygments/lexers/boa.py b/pygments/lexers/boa.py
new file mode 100644
index 00000000..41398cd4
--- /dev/null
+++ b/pygments/lexers/boa.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+import re
+
+from pygments.lexer import RegexLexer, words
+from pygments.token import *
+
+__all__ = ['BoaLexer']
+
+line_re = re.compile('.*?\n')
+
+
+class BoaLexer(RegexLexer):
+ """
+ http://boa.cs.iastate.edu/docs/
+ """
+ name = 'Boa'
+ aliases = ['boa']
+ filenames = ['*.boa']
+
+ reserved = words(
+ ('input', 'output', 'of', 'weight', 'before', 'after', 'stop', 'ifall', 'foreach', 'exists', 'function',
+ 'break', 'switch', 'case', 'visitor', 'default', 'return', 'visit', 'while', 'if', 'else'),
+ suffix=r'\b', prefix=r'\b')
+ keywords = words(
+ ('bottom', 'collection', 'maximum', 'mean', 'minimum', 'set', 'sum', 'top', 'string', 'int', 'bool', 'float',
+ 'time', 'false', 'true', 'array', 'map', 'stack', 'enum', 'type'), suffix=r'\b', prefix=r'\b')
+ classes = words(
+ ('Project', 'ForgeKind', 'CodeRepository', 'Revision', 'RepositoryKind', 'ChangedFile', 'FileKind', 'ASTRoot',
+ 'Namespace', 'Declaration', 'Type', 'Method', 'Variable', 'Statement', 'Expression', 'Modifier',
+ 'StatementKind', 'ExpressionKind', 'ModifierKind', 'Visibility', 'TypeKind', 'Person', 'ChangeKind'),
+ suffix=r'\b', prefix=r'\b')
+ operators = ('->', ':=', ':', '=', '<<', '!', '++', '||', '&&', '+', '-', '*', ">", "<")
+ string_sep = ('`', '\"')
+ built_in_functions = words(
+ (
+ # Array functions
+ 'new', 'sort',
+ # Date & Time functions
+ 'yearof', 'dayofyear', 'hourof', 'minuteof', 'secondof', 'now', 'addday', 'addmonth', 'addweek', 'addyear',
+ 'dayofmonth', 'dayofweek', 'dayofyear', 'formattime', 'trunctoday', 'trunctohour', 'trunctominute',
+ 'trunctomonth', 'trunctosecond', 'trunctoyear',
+ # Map functions
+ 'clear', 'haskey', 'keys', 'lookup', 'remove', 'values',
+ # Math functions
+ 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'cos', 'cosh', 'exp', 'floor',
+ 'highbit', 'isfinite', 'isinf', 'isnan', 'isnormal', 'log', 'log10', 'max', 'min', 'nrand', 'pow', 'rand',
+ 'round', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc',
+ # Other functions
+ 'def', 'hash', 'len',
+ # Set functions
+ 'add', 'contains', 'remove',
+ # String functions
+ 'format', 'lowercase', 'match', 'matchposns', 'matchstrs', 'regex', 'split', 'splitall', 'splitn',
+ 'strfind', 'strreplace', 'strrfind', 'substring', 'trim', 'uppercase',
+ # Type Conversion functions
+ 'bool', 'float', 'int', 'string', 'time',
+ # Domain-Specific functions
+ 'getast', 'getsnapshot', 'hasfiletype', 'isfixingrevision', 'iskind', 'isliteral',
+ ),
+ prefix=r'\b',
+ suffix=r'\(')
+
+ tokens = {
+ 'root': [
+ (r'#.*?$', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (reserved, Keyword.Reserved),
+ (built_in_functions, Name.Function),
+ (keywords, Keyword.Type),
+ (classes, Name.Classes),
+ (words(operators), Operator),
+ (r'[][(),;{}\\.]', Punctuation),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r'`(\\\\|\\`|[^`])*`', String),
+ (words(string_sep), String.Delimeter),
+ (r'[a-zA-Z_]+', Name.Variable),
+ (r'[0-9]+', Number.Integer),
+ (r'\s+?', Text), # Whitespace
+ ]
+ }
diff --git a/tests/examplefiles/example.boa b/tests/examplefiles/example.boa
new file mode 100644
index 00000000..a18f1626
--- /dev/null
+++ b/tests/examplefiles/example.boa
@@ -0,0 +1,18 @@
+# Computes Number of Public Methods (NPM) for each project, per-type
+# Output is: NPM[ProjectID][TypeName] = NPM value
+p: Project = input;
+NPM: output sum[string][string] of int;
+
+visit(p, visitor {
+ # only look at the latest snapshot
+ before n: CodeRepository -> {
+ snapshot := getsnapshot(n);
+ foreach (i: int; def(snapshot[i]))
+ visit(snapshot[i]);
+ stop;
+ }
+ before node: Declaration ->
+ if (node.kind == TypeKind.CLASS)
+ foreach (i: int; has_modifier_public(node.methods[i]))
+ NPM[p.id][node.name] << 1;
+});