Jeffrey Arnold avatar Jeffrey Arnold committed 8d1430b Draft

BugsLexer, JagsLexer, StanLexer: fixed filenames, added analyse_text functions

Comments (0)

Files changed (4)

pygments/lexers/_mapping.py

     'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)),
     'BrainfuckLexer': ('pygments.lexers.other', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)),
     'BroLexer': ('pygments.lexers.other', 'Bro', ('bro',), ('*.bro',), ()),
-    'BugsLexer': ('pygments.lexers.math', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bugs',), ()),
+    'BugsLexer': ('pygments.lexers.math', 'BUGS', ('bugs', 'winbugs', 'openbugs'), ('*.bug',), ()),
     'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h', '*.idc'), ('text/x-chdr', 'text/x-csrc')),
     'CMakeLexer': ('pygments.lexers.text', 'CMake', ('cmake',), ('*.cmake', 'CMakeLists.txt'), ('text/x-cmake',)),
     'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)),
     'IokeLexer': ('pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)),
     'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)),
     'JadeLexer': ('pygments.lexers.web', 'Jade', ('jade', 'JADE'), ('*.jade',), ('text/x-jade',)),
-    'JagsLexer': ('pygments.lexers.math', 'JAGS', ('jags',), ('*.jags',), ()),
+    'JagsLexer': ('pygments.lexers.math', 'JAGS', ('jags',), ('*.bug', '*.jags'), ()),
     'JavaLexer': ('pygments.lexers.jvm', 'Java', ('java',), ('*.java',), ('text/x-java',)),
     'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), (), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')),
     'JavascriptErbLexer': ('pygments.lexers.templates', 'JavaScript+Ruby', ('js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'), (), ('application/x-javascript+ruby', 'text/x-javascript+ruby', 'text/javascript+ruby')),
     'RubyConsoleLexer': ('pygments.lexers.agile', 'Ruby irb session', ('rbcon', 'irb'), (), ('text/x-ruby-shellsession',)),
     'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby', 'duby'), ('*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'), ('text/x-ruby', 'application/x-ruby')),
     'RustLexer': ('pygments.lexers.compiled', 'Rust', ('rust',), ('*.rs', '*.rc'), ('text/x-rustsrc',)),
-    'SLexer': ('pygments.lexers.math', 'S', ('splus', 's', 'r'), ('*.S', '*.R'), ('text/S-plus', 'text/S', 'text/R')),
+    'SLexer': ('pygments.lexers.math', 'S', ('splus', 's', 'r'), ('*.S', '*.R', '.Rhistory', '.Rprofile'), ('text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r', 'text/x-R', 'text/x-r-history', 'text/x-r-profile')),
     'SMLLexer': ('pygments.lexers.functional', 'Standard ML', ('sml',), ('*.sml', '*.sig', '*.fun'), ('text/x-standardml', 'application/x-standardml')),
     'SassLexer': ('pygments.lexers.web', 'Sass', ('sass', 'SASS'), ('*.sass',), ('text/x-sass',)),
     'ScalaLexer': ('pygments.lexers.jvm', 'Scala', ('scala',), ('*.scala',), ('text/x-scala',)),

pygments/lexers/math.py

 
     name = 'BUGS'
     aliases = ['bugs', 'winbugs', 'openbugs']
-    filenames = ['*.bugs']
+    filenames = ['*.bug']
 
     _FUNCTIONS = [
         # Scalar functions
             ]
         }
 
+    def analyse_text(text):
+        if re.match(r"^\s*model\s*{", text):
+            return 0.7
+        else:
+            return 0
 
 class JagsLexer(RegexLexer):
     """
 
     name = 'JAGS'
     aliases = ['jags']
-    filenames = ['*.jags']
+    filenames = ['*.bug', '*.jags']
 
     ## JAGS
     _FUNCTIONS = [
             ]
         }
 
+    def analyse_text(text):
+        if re.search(r'^\s*model\s*\{', text, re.M):
+            if re.search(r'^\s*data\s*\{', text, re.M):
+                return 0.9
+            elif re.search(r'^\s*var', text, re.M):
+                return 0.9
+            else:
+                return 0.3
+        else:
+            return 0
 
 class StanLexer(RegexLexer):
     """
             (r'}', Punctuation, '#pop'),
             ]
         }
+
+    def analyse_text(text):
+        return re.match('^\s*\\parameters\s*\{', text)

tests/examplefiles/example.bug

+# Alligators: multinomial - logistic regression 
+#  http://www.openbugs.info/Examples/Aligators.html
+model {
+	   
+   # PRIORS	
+   alpha[1] <- 0; # zero contrast for baseline food
+   for (k in 2 : K) { 
+       alpha[k] ~ dnorm(0, 0.00001) # vague priors
+   } 
+   # Loop around lakes:
+   for (k in 1 : K){ 
+        beta[1, k] <- 0 
+   } # corner-point contrast with first lake 
+   for (i in 2 : I) { 
+	beta[i, 1] <- 0 ; # zero contrast for baseline food
+	for (k in 2 : K){ 
+	    beta[i, k] ~ dnorm(0, 0.00001) # vague priors
+	} 
+   }
+   # Loop around sizes:
+   for (k in 1 : K){ 
+       gamma[1, k] <- 0 # corner-point contrast with first size 
+   } 
+   for (j in 2 : J) { 
+       gamma[j, 1] <- 0 ; # zero contrast for baseline food
+       for ( k in 2 : K){ 
+	    gamma[j, k] ~ dnorm(0, 0.00001) # vague priors
+       } 
+   }
+
+   # LIKELIHOOD   
+   for (i in 1 : I) { # loop around lakes
+       for (j in 1 : J) { # loop around sizes
+
+           # Fit standard Poisson regressions relative to baseline
+       	   lambda[i, j] ~ dflat()   # vague priors 
+       	   for (k in 1 : K) { # loop around foods
+	       X[i, j, k] ~ dpois(mu[i, j, k])
+	       log(mu[i, j, k]) <- lambda[i, j] + alpha[k] + beta[i, k] + gamma[j, k]
+	       culmative.X[i, j, k] <- culmative(X[i, j, k], X[i, j, k])
+	   }
+       } 
+   }
+
+   # TRANSFORM OUTPUT TO ENABLE COMPARISON 
+   # WITH AGRESTI'S RESULTS
+   for (k in 1 : K) { # loop around foods
+       for (i in 1 : I) { # loop around lakes
+	    b[i, k] <- beta[i, k] - mean(beta[, k]); # sum to zero constraint
+       }
+       for (j in 1 : J) { # loop around sizes
+	    g[j, k] <- gamma[j, k] - mean(gamma[, k]); # sum to zero constraint
+       }
+   }
+} 

tests/examplefiles/example.bugs

-# Alligators: multinomial - logistic regression 
-#  http://www.openbugs.info/Examples/Aligators.html
-model {
-	   
-   # PRIORS	
-   alpha[1] <- 0; # zero contrast for baseline food
-   for (k in 2 : K) { 
-       alpha[k] ~ dnorm(0, 0.00001) # vague priors
-   } 
-   # Loop around lakes:
-   for (k in 1 : K){ 
-        beta[1, k] <- 0 
-   } # corner-point contrast with first lake 
-   for (i in 2 : I) { 
-	beta[i, 1] <- 0 ; # zero contrast for baseline food
-	for (k in 2 : K){ 
-	    beta[i, k] ~ dnorm(0, 0.00001) # vague priors
-	} 
-   }
-   # Loop around sizes:
-   for (k in 1 : K){ 
-       gamma[1, k] <- 0 # corner-point contrast with first size 
-   } 
-   for (j in 2 : J) { 
-       gamma[j, 1] <- 0 ; # zero contrast for baseline food
-       for ( k in 2 : K){ 
-	    gamma[j, k] ~ dnorm(0, 0.00001) # vague priors
-       } 
-   }
-
-   # LIKELIHOOD   
-   for (i in 1 : I) { # loop around lakes
-       for (j in 1 : J) { # loop around sizes
-
-           # Fit standard Poisson regressions relative to baseline
-       	   lambda[i, j] ~ dflat()   # vague priors 
-       	   for (k in 1 : K) { # loop around foods
-	       X[i, j, k] ~ dpois(mu[i, j, k])
-	       log(mu[i, j, k]) <- lambda[i, j] + alpha[k] + beta[i, k] + gamma[j, k]
-	       culmative.X[i, j, k] <- culmative(X[i, j, k], X[i, j, k])
-	   }
-       } 
-   }
-
-   # TRANSFORM OUTPUT TO ENABLE COMPARISON 
-   # WITH AGRESTI'S RESULTS
-   for (k in 1 : K) { # loop around foods
-       for (i in 1 : I) { # loop around lakes
-	    b[i, k] <- beta[i, k] - mean(beta[, k]); # sum to zero constraint
-       }
-       for (j in 1 : J) { # loop around sizes
-	    g[j, k] <- gamma[j, k] - mean(gamma[, k]); # sum to zero constraint
-       }
-   }
-} 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.