summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChee Sing Lee <cheesinglee@gmail.com>2016-02-05 17:42:17 -0800
committerChee Sing Lee <cheesinglee@gmail.com>2016-02-05 17:42:17 -0800
commit0331bdc908b1b3529c5603b739744e65eaf8a9df (patch)
tree03fafed962906797b8e9d2e1bc6d2ffcbe0130fd
parent0c812483363f57bc812f979d70d6b6773da6135f (diff)
downloadpygments-0331bdc908b1b3529c5603b739744e65eaf8a9df.tar.gz
Add Flatline lexer
-rw-r--r--AUTHORS1
-rw-r--r--pygments/lexers/_mapping.py3
-rw-r--r--pygments/lexers/dsls.py78
-rw-r--r--tests/examplefiles/flatline_example186
4 files changed, 265 insertions, 3 deletions
diff --git a/AUTHORS b/AUTHORS
index 5108c2ab..aeb63ea1 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -111,6 +111,7 @@ Other contributors, listed alphabetically, are:
* Olov Lassus -- Dart lexer
* Matt Layman -- TAP lexer
* Sylvestre Ledru -- Scilab lexer
+* Chee Sing Lee -- Flatline lexer
* Mark Lee -- Vala lexer
* Valentin Lorentz -- C++ lexer improvements
* Ben Mabey -- Gherkin lexer
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 0a6b4965..debb7de5 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -9,7 +9,7 @@
Do not alter the LEXERS dictionary by hand.
- :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2014, 2016 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -145,6 +145,7 @@ LEXERS = {
'FantomLexer': ('pygments.lexers.fantom', 'Fantom', ('fan',), ('*.fan',), ('application/x-fantom',)),
'FelixLexer': ('pygments.lexers.felix', 'Felix', ('felix', 'flx'), ('*.flx', '*.flxh'), ('text/x-felix',)),
'FishShellLexer': ('pygments.lexers.shell', 'Fish', ('fish', 'fishshell'), ('*.fish', '*.load'), ('application/x-fish',)),
+ 'FlatlineLexer': ('pygments.lexers.dsls', 'Flatline', ('flatline',), (), ()),
'FortranFixedLexer': ('pygments.lexers.fortran', 'FortranFixed', ('fortranfixed',), ('*.f', '*.F'), ()),
'FortranLexer': ('pygments.lexers.fortran', 'Fortran', ('fortran',), ('*.f03', '*.f90', '*.F03', '*.F90'), ('text/x-fortran',)),
'FoxProLexer': ('pygments.lexers.foxpro', 'FoxPro', ('foxpro', 'vfp', 'clipper', 'xbase'), ('*.PRG', '*.prg'), ()),
diff --git a/pygments/lexers/dsls.py b/pygments/lexers/dsls.py
index 24fda2a2..0d55af09 100644
--- a/pygments/lexers/dsls.py
+++ b/pygments/lexers/dsls.py
@@ -5,7 +5,7 @@
Lexers for various domain-specific languages.
- :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -18,7 +18,7 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
__all__ = ['ProtoBufLexer', 'BroLexer', 'PuppetLexer', 'RslLexer',
'MscgenLexer', 'VGLLexer', 'AlloyLexer', 'PanLexer',
- 'CrmshLexer', 'ThriftLexer']
+ 'CrmshLexer', 'ThriftLexer', 'FlatlineLexer']
class ProtoBufLexer(RegexLexer):
@@ -692,3 +692,77 @@ class CrmshLexer(RegexLexer):
(r'\s+|\n', Whitespace),
],
}
+
+class FlatlineLexer(RegexLexer):
+ """
+ Lexer for `Flatline <https://github.com/bigmlcom/flatline>`_ expressions
+
+ .. versionadded::2.2
+ """
+ name = 'Flatline'
+ aliases = ['flatline']
+ filenames = []
+ mimetypes = ['text/plain']
+
+ special_forms = ('let')
+
+ builtins = (
+ "!=","*","+","-","<","<=","=",">",">=","abs","acos","all","all-but",
+ "all-with-defaults","all-with-numeric-default","and","asin","atan",
+ "avg","avg-window","bin-center","bin-count","call","category-count",
+ "ceil","cond","cond-window","cons","cos","cosh","count","diff-window",
+ "div","ensure-value","ensure-weighted-value","epoch","epoch-day",
+ "epoch-fields","epoch-hour","epoch-millisecond","epoch-minute",
+ "epoch-month","epoch-second","epoch-weekday","epoch-year","exp","f",
+ "field","field-prop","fields","filter","first","floor","head","if",
+ "in","integer","language","length","levenshtein","linear-regression",
+ "list","ln","log","log10","map","matches","matches?","max","maximum",
+ "md5","mean","median","min","minimum","missing","missing-count",
+ "missing?","missing_count","mod","mode","normalize","not","nth",
+ "occurrences","or","percentile","percentile-label","population",
+ "population-fraction","pow","preferred","preferred?","quantile-label",
+ "rand","rand-int","random-value","re-quote","real","replace",
+ "replace-first","rest","round","row-number","segment-label","sha1",
+ "sha256","sin","sinh","sqrt","square","standard-deviation",
+ "standard_deviation","str","subs","sum","sum-squares","sum-window",
+ "sum_squares","summary","summary-no","summary-str","tail","tan",
+ "tanh","to-degrees","to-radians","variance","vectorize",
+ "weighted-random-value","window","winnow","within-percentiles?",
+ "z-score"
+ )
+
+ valid_name = r'(?!#)[\w!$%*+<=>?/.#-]+'
+
+ tokens = {
+ 'root': [
+ # whitespaces - usually not relevant
+ (r'[,\s]+', Text),
+
+ # numbers
+ (r'-?\d+\.\d+', Number.Float),
+ (r'-?\d+', Number.Integer),
+ (r'0x-?[abcdef\d]+', Number.Hex),
+
+ # strings, symbols and characters
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r"\\(.|[a-z]+)", String.Char),
+
+ # expression template placeholder
+ (r'_', String.Symbol),
+
+ # highlight the special forms
+ (words(special_forms, suffix=' '), Keyword),
+
+ # highlight the builtins
+ (words(builtins, suffix=' '), Name.Builtin),
+
+ # the remaining functions
+ (r'(?<=\()' + valid_name, Name.Function),
+
+ # find the remaining variables
+ (valid_name, Name.Variable),
+
+ # parentheses
+ (r'(\(|\))', Punctuation),
+ ],
+ } \ No newline at end of file
diff --git a/tests/examplefiles/flatline_example b/tests/examplefiles/flatline_example
new file mode 100644
index 00000000..5ea73408
--- /dev/null
+++ b/tests/examplefiles/flatline_example
@@ -0,0 +1,186 @@
+(field "another field" 2)
+(f "000001" -2)
+
+(missing? "a field" 23)
+
+(random-value "age")
+(weighted-random-value "000001")
+
+(if (missing? "00000") (random-value "000000") (f "000000"))
+
+(ensure-value "000000")
+(ensure-weighted-value "000000")
+
+(normalize "000001")
+(normalize "length" 8 23)
+
+(z-score "a numeric field")
+(z-score 23)
+
+(field-prop string "00023" name)
+(field-prop numeric "00023" summary missing_count)
+
+(category-count "species" "Iris-versicolor")
+(category-count "species" (f "000004"))
+(bin-count "age" (f "bin-selector"))
+(bin-center "000003" 3)
+(bin-center (field "field-selector") 4)
+
+(let (v (f "age"))
+ (cond (< v 2) "baby"
+ (< v 10) "child"
+ (< v 20) "teenager"
+ "adult"))
+
+(segment-label "000000" "baby" 2 "child" 10 "teenager" 20 "adult")
+(segment-label 0 "1st fourth" "2nd fourth" "3rd fourth" "4th fourth")
+
+(let (max (maximum 0)
+ min (minimum 0)
+ step (/ (- max min) 4))
+ (segment-label 0 "1st fourth" (+ min step)
+ "2nd fourth" (+ min step step)
+ "3rd fourth" (+ min step step step)
+ "4th fourth"))
+
+(contains-items? "000000" "blue" "green" "darkblue")
+
+(<= (percentile "age" 0.5) (f "age") (percentile "age" 0.95))
+
+(within-percentiles? "age" 0.5 0.95)
+
+(percentile-label "000023" "1st" "2nd" "3rd" "4th")
+
+(cond (within-percentiles? "000023" 0 0.25) "1st"
+ (within-percentiles? "000023" 0.25 0.5) "2nd"
+ (within-percentiles? "000023" 0.5 0.75) "3rd"
+ "4th")
+
+(str 1 "hello " (field "a"))
+(str "value_" (+ 3 4) "/" (name "000001"))
+
+(length "abc")
+(length "")
+
+(levenshtein (f 0) "a random string")
+(if (< (levenshtein (f 0) "bluething") 5) "bluething" (f 0))
+
+(occurrences "howdy woman, howdy" "howdy")
+(occurrences "howdy woman" "Man" true)
+(occurrences "howdy man" "Man" true)
+(occurrences "hola, Holas" "hola" true "es")
+
+(md5 "a text")
+(sha1 "a text")
+(sha256 "")
+
+(matches? (field "name") ".*\\sHal\\s.*")
+(matches? (field "name") "(?i).*\\shal\\s.*")
+
+(if (matches? (f "result") (re-quote (f "target"))) "GOOD" "MISS")
+(matches? (f "name") (str "^" (re-quote (f "salutation")) "\\s *$"))
+
+(replace "Almost Pig Latin" "\\b(\\w)(\\w+)\\b" "$2$1ay")
+(replace-first "swap first two words" "(\\w+)(\\s+)(\\w+)" "$3$2$1")
+
+(language "this is an English phrase")
+
+(< (field 0) (field 1))
+(<= (field 0 -1) (field 0) (field 0 1))
+(> (field "date") "07-14-1969")
+(>= 23 (f "000004" -2))
+
+(= "Dante" (field "Author"))
+(= 1300 (field "Year"))
+(= (field "Year" -2) (field "Year" -1) (field "Year"))
+(!= (field "00033" -1) (field "00033" 1))
+
+(and (= 3 (field 1)) (= "meh" (f "a")) (< (f "pregnancies") 5))
+(not true)
+
+(linear-regression 1 1 2 2 3 3 4 4)
+(linear-regression 2.0 3.1 2.3 3.3 24.3 45.2)
+
+(epoch-fields (f "milliseconds"))
+(epoch-year (* 1000 (f "seconds")))
+
+(/ (f "a-datetime-string") 1000)
+(/ (epoch (f "a-datetime-string")) 1000)
+
+(epoch-fields (epoch "1969-14-07T06:00:12"))
+(epoch-hour (epoch "11~22~30" "hh~mm~ss"))
+
+(let (x (+ (window "a" -10 10))
+ a (/ (* x 3) 4.34)
+ y (if (< a 10) "Good" "Bad"))
+ (list x (str (f 10) "-" y) a y))
+
+(list (let (z (f 0)) (* 2 (* z z) (log z)))
+ (let (pi 3.141592653589793 r (f "radius")) (* 4 pi r r)))
+
+(if (< (field "age") 18) "non-adult" "adult")
+
+(if (= "oh" (field "000000")) "OH")
+
+(if (> (field "000001") (mean "000001"))
+ "above average"
+ (if (< (field "000001") (mean "000001"))
+ "below average"
+ "mediocre"))
+
+(cond (> (f "000001") (mean "000001")) "above average"
+ (= (f "000001") (mean "000001")) "below average"
+ "mediocre")
+
+(cond (or (= "a" (f 0)) (= "a+" (f 0))) 1
+ (or (= "b" (f 0)) (= "b+" (f 0))) 0
+ (or (= "c" (f 0)) (= "c+" (f 0))) -1)
+
+(cond (< (f "age") 2) "baby"
+ (and (<= 2 (f "age") 10) (= "F" (f "sex"))) "girl"
+ (and (<= 2 (f "age") 10) (= "M" (f "sex"))) "boy"
+ (< 10 (f "age") 20) "teenager"
+ "adult")
+
+(list (field "age")
+ (field "weight" -1)
+ (population "age"))
+
+(list 1.23
+ (if (< (field "age") 10) "child" "adult")
+ (field 3))
+
+(head (cons x lst))
+(tail (cons x lst))
+
+(count (list (f 1) (f 2)))
+(mode (list a b b c b a c c c))
+(max (list -1 2 -2 0.38))
+(min (list -1.3 2 1))
+(avg (list -1 -2 1 2 0.8 -0.8))
+
+(in 3 (1 2 3 2))
+(in "abc" (1 2 3))
+(in (f "size") ("X" "XXL"))
+
+(< _ 3)
+(+ (f "000001" _) 3)
+(< -18 _ (f 3))
+
+(map (* 2 _) (list (f 0 -1) (f 0) (f 0 1)))
+
+(all-but "id" "000023")
+(fields "000003" 3 "a field" "another" "0002a3b-3")
+
+(all-with-defaults "species" "Iris-versicolor"
+ "petal-width" 2.8
+ "000002" 0)
+
+(all-with-numeric-default "median")
+(all-with-numeric-default 0)
+
+(window "000001" -1 2)
+(filter (< _ 99.9) (map (+ 32 (* 1.8 _)) (window "Temp" -2 0)))
+
+(let (now (f "epoch"))
+ (avg (cond-window "temperature" (< (- (f "epoch") now) 240))))