summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdoardo Tenani <edoardo.tenani@gmail.com>2015-01-28 11:38:20 +0100
committerEdoardo Tenani <edoardo.tenani@gmail.com>2015-01-28 11:38:20 +0100
commitd4fa5cfd65ff117593a60bff24a51560aa6c22d3 (patch)
tree72da600692cdae588d990b5e6144513d8bab2820
parentfe72d20b50c75089fa1262b9f03fcb29c9e49282 (diff)
downloadpygments-d4fa5cfd65ff117593a60bff24a51560aa6c22d3.tar.gz
Add arduino lexer and style
-rwxr-xr-xpygments/formatters/_mapping.py1
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/c_like.py56
-rw-r--r--pygments/styles/arduino.py97
-rw-r--r--tests/examplefiles/Blink.ino24
5 files changed, 177 insertions, 2 deletions
diff --git a/pygments/formatters/_mapping.py b/pygments/formatters/_mapping.py
index f01206e0..bfc82253 100755
--- a/pygments/formatters/_mapping.py
+++ b/pygments/formatters/_mapping.py
@@ -32,7 +32,6 @@ FORMATTERS = {
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
}
-
if __name__ == '__main__': # pragma: no cover
import sys
import os
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 6ed4b620..dcaefb48 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -35,6 +35,7 @@ LEXERS = {
'AntlrRubyLexer': ('pygments.lexers.parsers', 'ANTLR With Ruby Target', ('antlr-ruby', 'antlr-rb'), ('*.G', '*.g'), ()),
'ApacheConfLexer': ('pygments.lexers.configs', 'ApacheConf', ('apacheconf', 'aconf', 'apache'), ('.htaccess', 'apache.conf', 'apache2.conf'), ('text/x-apacheconf',)),
'AppleScriptLexer': ('pygments.lexers.scripting', 'AppleScript', ('applescript',), ('*.applescript',), ()),
+ 'ArduinoLexer': ('pygments.lexers.c_like', 'Arduino', ('arduino',), ('*.ino',), ('text/x-arduino',)),
'AspectJLexer': ('pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)),
'AsymptoteLexer': ('pygments.lexers.graphics', 'Asymptote', ('asy', 'asymptote'), ('*.asy',), ('text/x-asymptote',)),
'AutoItLexer': ('pygments.lexers.automation', 'AutoIt', ('autoit',), ('*.au3',), ('text/x-autoit',)),
diff --git a/pygments/lexers/c_like.py b/pygments/lexers/c_like.py
index e18ec1d5..dd1b0eff 100644
--- a/pygments/lexers/c_like.py
+++ b/pygments/lexers/c_like.py
@@ -20,7 +20,7 @@ from pygments.lexers.c_cpp import CLexer, CppLexer
from pygments.lexers import _mql_builtins
__all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer',
- 'CudaLexer', 'SwigLexer', 'MqlLexer']
+ 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer']
class PikeLexer(CppLexer):
@@ -411,3 +411,57 @@ class MqlLexer(CppLexer):
inherit,
],
}
+
+class ArduinoLexer(CppLexer):
+ """
+ For `Arduino® <https://arduino.cc/>`_ source.
+
+ This is an extension of the CppLexer, as the Arduino® Language is a superset
+ of C++
+ """
+
+ name = 'Arduino'
+ aliases = ['arduino']
+ filenames = ['*.ino']
+ mimetypes = ['text/x-arduino']
+
+ # Language constants
+ constants = [ 'DIGITAL_MESSAGE', 'FIRMATA_STRING', 'ANALOG_MESSAGE',
+ 'REPORT_DIGITAL', 'REPORT_ANALOG', 'INPUT_PULLUP',
+ 'SET_PIN_MODE', 'INTERNAL2V56', 'SYSTEM_RESET', 'LED_BUILTIN',
+ 'INTERNAL1V1', 'SYSEX_START', 'INTERNAL', 'EXTERNAL',
+ 'DEFAULT', 'OUTPUT', 'INPUT', 'HIGH', 'LOW' ]
+
+ # Language sketch main structure functions
+ structure = [ 'setup', 'loop' ]
+
+ # Language variable types
+ storage = [ 'boolean', 'const', 'byte', 'word', 'string', 'String', 'array' ]
+
+ # Language shipped functions and class ( )
+ functions = [ 'KeyboardController', 'MouseController', 'SoftwareSerial', 'EthernetServer', 'EthernetClient', 'LiquidCrystal', 'RobotControl', 'GSMVoiceCall', 'EthernetUDP', 'EsploraTFT', 'HttpClient', 'RobotMotor', 'WiFiClient', 'GSMScanner', 'FileSystem', 'Scheduler', 'GSMServer', 'YunClient', 'YunServer', 'IPAddress', 'GSMClient', 'GSMModem', 'Keyboard', 'Ethernet', 'Console', 'GSMBand', 'Esplora', 'Stepper', 'Process', 'WiFiUDP', 'GSM_SMS', 'Mailbox', 'USBHost', 'Firmata', 'PImage', 'Client', 'Server', 'GSMPIN', 'FileIO', 'Bridge', 'Serial', 'EEPROM', 'Stream', 'Mouse', 'Audio', 'Servo', 'File', 'Task', 'GPRS', 'WiFi', 'Wire', 'TFT', 'GSM', 'SPI', 'SD)', '(runShellCommandAsynchronously', 'analogWriteResolution', 'retrieveCallingNumber', 'printFirmwareVersion', 'analogReadResolution', 'sendDigitalPortPair', 'noListenOnLocalhost', 'readJoystickButton', 'setFirmwareVersion', 'readJoystickSwitch', 'scrollDisplayRight', 'getVoiceCallStatus', 'scrollDisplayLeft', 'writeMicroseconds', 'delayMicroseconds', 'beginTransmission', 'getSignalStrength', 'runAsynchronously', 'getAsynchronously', 'listenOnLocalhost', 'getCurrentCarrier', 'readAccelerometer', 'messageAvailable', 'sendDigitalPorts', 'lineFollowConfig', 'countryNameWrite', 'runShellCommand', 'readStringUntil', 'rewindDirectory', 'readTemperature', 'setClockDivider', 'readLightSensor', 'endTransmission', 'analogReference', 'detachInterrupt', 'countryNameRead', 'attachInterrupt', 'encryptionType', 'readBytesUntil', 'robotNameWrite', 'readMicrophone', 'robotNameRead', 'cityNameWrite', 'userNameWrite', 'readJoystickY', 'readJoystickX', 'mouseReleased', 'openNextFile', 'scanNetworks', 'noInterrupts', 'digitalWrite', 'beginSpeaker', 'mousePressed', 'isActionDone', 'mouseDragged', 'displayLogos', 'noAutoscroll', 'addParameter', 'remoteNumber', 'getModifiers', 'keyboardRead', 'userNameRead', 'waitContinue', 'processInput', 'parseCommand', 'printVersion', 'readNetworks', 'writeMessage', 'blinkVersion', 'cityNameRead', 'readMessage', 'setDataMode', 'parsePacket', 'isListening', 'setBitOrder', 'beginPacket', 'isDirectory', 'motorsWrite', 'drawCompass', 'digitalRead', 'clearScreen', 'serialEvent', 'rightToLeft', 'setTextSize', 'leftToRight', 'requestFrom', 'keyReleased', 'compassRead', 'analogWrite', 'interrupts', 'WiFiServer', 'disconnect', 'playMelody', 'parseFloat', 'autoscroll', 'getPINUsed', 'setPINUsed', 'setTimeout', 'sendAnalog', 'readSlider', 'analogRead', 'beginWrite', 'createChar', 'motorsStop', 'keyPressed', 'tempoWrite', 'readButton', 'subnetMask', 'debugPrint', 'macAddress', 'writeGreen', 'randomSeed', 'attachGPRS', 'readString', 'sendString', 'remotePort', 'releaseAll', 'mouseMoved', 'background', 'getXChange', 'getYChange', 'answerCall', 'getResult', 'voiceCall', 'endPacket', 'constrain', 'getSocket', 'writeJSON', 'getButton', 'available', 'connected', 'findUntil', 'readBytes', 'exitValue', 'readGreen', 'writeBlue', 'startLoop', 'IPAddress', 'isPressed', 'sendSysex', 'pauseMode', 'gatewayIP', 'setCursor', 'getOemKey', 'tuneWrite', 'noDisplay', 'loadImage', 'switchPIN', 'onRequest', 'onReceive', 'changePIN', 'playFile', 'noBuffer', 'parseInt', 'overflow', 'checkPIN', 'knobRead', 'beginTFT', 'bitClear', 'updateIR', 'bitWrite', 'position', 'writeRGB', 'highByte', 'writeRed', 'setSpeed', 'readBlue', 'noStroke', 'remoteIP', 'transfer', 'shutdown', 'hangCall', 'beginSMS', 'endWrite', 'attached', 'maintain', 'noCursor', 'checkReg', 'checkPUK', 'shiftOut', 'isValid', 'shiftIn', 'pulseIn', 'connect', 'println', 'localIP', 'pinMode', 'getIMEI', 'display', 'noBlink', 'process', 'getBand', 'running', 'beginSD', 'drawBMP', 'lowByte', 'setBand', 'release', 'bitRead', 'prepare', 'pointTo', 'readRed', 'setMode', 'noFill', 'remove', 'listen', 'stroke', 'detach', 'attach', 'noTone', 'exists', 'buffer', 'height', 'bitSet', 'circle', 'config', 'cursor', 'random', 'IRread', 'sizeof', 'setDNS', 'endSMS', 'getKey', 'micros', 'millis', 'begin', 'print', 'write', 'ready', 'flush', 'width', 'isPIN', 'blink', 'clear', 'press', 'mkdir', 'rmdir', 'close', 'point', 'yield', 'image', 'float', 'BSSID', 'click', 'delay', 'read', 'text', 'move', 'peek', 'beep', 'rect', 'line', 'open', 'seek', 'fill', 'size', 'turn', 'stop', 'home', 'find', 'char', 'byte', 'step', 'word', 'long', 'tone', 'sqrt', 'RSSI', 'SSID', 'end', 'bit', 'tan', 'cos', 'sin', 'pow', 'map', 'abs', 'max', 'min', 'int', 'get', 'run', 'put' ]
+
+
+ def get_tokens_unprocessed(self, text):
+ for index, token, value in CppLexer.get_tokens_unprocessed(self, text):
+ if token is Name:
+ if value in self.constants:
+ yield index, Keyword.Constant, value
+ elif value in self.functions:
+ yield index, Name.Function, value
+ elif value in self.storage:
+ yield index, Keyword.Type, value
+ else:
+ yield index, token, value
+ elif token is Name.Function:
+ if value in self.structure:
+ yield index, Name.Other, value
+ else:
+ yield index, token, value
+ elif token is Keyword:
+ if value in self.storage:
+ yield index, Keyword.Type, value
+ else:
+ yield index, token, value
+ else:
+ yield index, token, value
diff --git a/pygments/styles/arduino.py b/pygments/styles/arduino.py
new file mode 100644
index 00000000..f6bcd1cd
--- /dev/null
+++ b/pygments/styles/arduino.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.styles.arduino
+ ~~~~~~~~~~~~~~~~~~~~~~~
+
+ Arduino® Syntax highlighting style.
+
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from pygments.style import Style
+from pygments.token import Keyword, Name, Comment, String, Error, \
+ Number, Operator, Generic, Whitespace
+
+
+class ArduinoStyle(Style):
+ """
+ The Arduino® language style. This style is designed to highlight the Arduino source code, so exepect the best results with it.
+ """
+
+ background_color = "#ffffff"
+ default_style = ""
+
+ styles = {
+ Whitespace: "", # class: 'w'
+ Error: "#a61717", # class: 'err'
+
+ Comment: "#95a5a6", # class: 'c'
+ Comment.Multiline: "", # class: 'cm'
+ Comment.Preproc: "#434f54", # class: 'cp'
+ Comment.Single: "", # class: 'c1'
+ Comment.Special: "", # class: 'cs'
+
+ Keyword: "#728E00", # class: 'k'
+ Keyword.Constant: "#00979D", # class: 'kc'
+ Keyword.Declaration: "", # class: 'kd'
+ Keyword.Namespace: "", # class: 'kn'
+ Keyword.Pseudo: "#00979D", # class: 'kp'
+ Keyword.Reserved: "", # class: 'kr'
+ Keyword.Type: "#00979D", # class: 'kt'
+
+ Operator: "#434f54", # class: 'o'
+ Operator.Word: "", # class: 'ow'
+
+ Name: "#434f54", # class: 'n'
+ Name.Attribute: "", # class: 'na'
+ Name.Builtin: "", # class: 'nb'
+ Name.Builtin.Pseudo: "", # class: 'bp'
+ Name.Class: "", # class: 'nc'
+ Name.Constant: "", # class: 'no'
+ Name.Decorator: "", # class: 'nd'
+ Name.Entity: "", # class: 'ni'
+ Name.Exception: "", # class: 'ne'
+ Name.Function: "#D35400", # class: 'nf'
+ Name.Property: "", # class: 'py'
+ Name.Label: "", # class: 'nl'
+ Name.Namespace: "", # class: 'nn'
+ Name.Other: "#728E00", # class: 'nx'
+ Name.Tag: "", # class: 'nt'
+ Name.Variable: "", # class: 'nv'
+ Name.Variable.Class: "", # class: 'vc'
+ Name.Variable.Global: "", # class: 'vg'
+ Name.Variable.Instance: "", # class: 'vi'
+
+ Number: "#434f54", # class: 'm'
+ Number.Float: "", # class: 'mf'
+ Number.Hex: "", # class: 'mh'
+ Number.Integer: "", # class: 'mi'
+ Number.Integer.Long: "", # class: 'il'
+ Number.Oct: "", # class: 'mo'
+
+ String: "#7F8C8D", # class: 's'
+ String.Backtick: "", # class: 'sb'
+ String.Char: "", # class: 'sc'
+ String.Doc: "", # class: 'sd'
+ String.Double: "", # class: 's2'
+ String.Escape: "", # class: 'se'
+ String.Heredoc: "", # class: 'sh'
+ String.Interpol: "", # class: 'si'
+ String.Other: "", # class: 'sx'
+ String.Regex: "", # class: 'sr'
+ String.Single: "", # class: 's1'
+ String.Symbol: "", # class: 'ss'
+
+ Generic: "", # class: 'g'
+ Generic.Deleted: "", # class: 'gd',
+ Generic.Emph: "", # class: 'ge'
+ Generic.Error: "", # class: 'gr'
+ Generic.Heading: "", # class: 'gh'
+ Generic.Inserted: "", # class: 'gi'
+ Generic.Output: "", # class: 'go'
+ Generic.Prompt: "", # class: 'gp'
+ Generic.Strong: "", # class: 'gs'
+ Generic.Subheading: "", # class: 'gu'
+ Generic.Traceback: "", # class: 'gt'
+ }
diff --git a/tests/examplefiles/Blink.ino b/tests/examplefiles/Blink.ino
new file mode 100644
index 00000000..993bd743
--- /dev/null
+++ b/tests/examplefiles/Blink.ino
@@ -0,0 +1,24 @@
+/*
+ Blink
+ Turns on an LED on for one second, then off for one second, repeatedly.
+
+ This example code is in the public domain.
+ */
+
+// Pin 13 has an LED connected on most Arduino boards.
+// give it a name:
+int led = 13;
+
+// the setup routine runs once when you press reset:
+void setup() {
+ // initialize the digital pin as an output.
+ pinMode(led, OUTPUT);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+ digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
+ delay(1000); // wait for a second
+ digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
+ delay(1000); // wait for a second
+}