Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Merge features from my augeas lexer #1

Merged
merged 1 commit into from

2 participants

Raphaël Pinson Tim Sharpe
Raphaël Pinson

About a year ago (I guess about the same time as you), I wrote a Pygments lexer for Augeas for the Augeas book.

I just saw you made one, too, so I've thought it better to send you my code and merge the two projects.

This PR adds a few lexers:

  • AugtoolShellLexer parses augtool shell output;
  • AugtoolLexer parses augtool code (without a shell prompt and shell output);
  • PuppetAugeasLexer parses puppet code using the augeas provider;

Real life example: http://r.pinson.free.fr/augeas/augeas-book_colored.pdf

Raphaël Pinson

Hello,

Did you get the occasion to review this PR?

Raphaël Pinson

Hello,

Any news on this?

Tim Sharpe
Owner

Oh man, sorry @raphink, this completely slipped my mind!

Tim Sharpe rodjek merged commit 786e246 into from
Tim Sharpe
Owner

I'll try to get this out live on github.com in the next few days

Raphaël Pinson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 1, 2012
  1. Raphaël Pinson
This page is out of date. Refresh to see the latest.
Showing with 96 additions and 2 deletions.
  1. +88 −1 augeas_lexer/__init__.py
  2. +8 −1 setup.py
89 augeas_lexer/__init__.py
View
@@ -2,8 +2,12 @@
from pygments.token import *
class AugeasLexer(RegexLexer):
+ """
+ Lexer for Augeas modules
+ """
+
name = 'Augeas'
- aliases = ['augeas']
+ aliases = ['augeas', 'aug']
filenames = ['*.aug']
tokens = {
@@ -38,3 +42,86 @@ class AugeasLexer(RegexLexer):
(r'[\*\)]', Comment.Multiline)
],
}
+
+class AugtoolShellLexer(RegexLexer):
+ """
+ Lexer for Augtool shell sessions.
+ """
+
+ name = 'AugtoolShell'
+ aliases = ['augtool-shell']
+ filenames = ['*.augtoolshell']
+
+ tokens = {
+ 'root': [
+ (r'^\s+$', Text), # empty line
+ (r'^[;#].*?$', Comment), # comment
+ (r'^(rm\s+:.*)', Text), # removed nodes
+ (r'^(Saved.*)', Text), # saved
+ (r'^(augtool\>)(\s+)(\S+)(?:(\s+)(.*))?$', # augtool prompt
+ bygroups(Generic.Prompt, Whitespace, Keyword, Whitespace, String)),
+ (r'^([^=]+)(?:(\s+)(=)(\s+)(.*))?$', # ls/get/print
+ bygroups(String, Whitespace, Operator, Whitespace, String)),
+ (r'^(\S+)(\s+)(label)(=)(\S+)(\s+)(value)(=)(\S+)(\s+)(span)(=)(\S+)$', # span output
+ bygroups(String, Whitespace, Keyword, Operator, String, Whitespace,
+ Keyword, Operator, String, Whitespace,
+ Keyword, Operator, String)),
+ ]
+ }
+
+
+class AugtoolLexer(RegexLexer):
+ """
+ Lexer for Augtool commands
+ """
+
+ name = 'Augtool'
+ aliases = ['augtool']
+ filenames = ['*.augtool']
+
+ tokens = {
+ 'root': [
+ (r'^\s+$', Text), # empty line
+ (r'[;#].*?$', Comment), # comment
+ (r'^(\S+)(?:(\s+)(.*))?$', # augtool command
+ bygroups(Keyword, Whitespace, String)),
+ ]
+ }
+
+
+class PuppetAugeasLexer(RegexLexer):
+ """
+ Lexer for the Puppet Augeas type
+ """
+
+ name = 'PuppetAugeas'
+ aliases = ['puppet-augeas']
+ filenames = ['*.pp-aug']
+
+ tokens = {
+ 'root': [
+ (r'^\s+$', Text), # empty line
+ (r'[;#].*?$', Comment),
+ (r'[\[\]{}]', Operator),
+ (r'=>', Operator),
+ (r',', Text),
+ (r'(\w+)(\s+)({)(\s+)(".*")(:)',
+ bygroups(Keyword, Whitespace, Operator,
+ Whitespace, Name.Namespace, Text)),
+ (r'(\s*)(context)(\s+)(=>)(\s+)(".*")(,)?',
+ bygroups(Whitespace, Keyword, Whitespace, Operator,
+ Whitespace, String, Text)),
+ (r'(\s*)(changes)(\s+)(=>)(\s+)(\[)',
+ bygroups(Whitespace, Keyword, Whitespace, Operator,
+ Whitespace, Operator)),
+ (r'(\s*)(onlyif)(\s+)(=>)(\s+)(".*")(,)?',
+ bygroups(Whitespace, Keyword, Whitespace, Operator,
+ Whitespace, String, Text)),
+ (r'(\s*)(".*")(,)?',
+ bygroups(Whitespace, String, Text)),
+ (r'(\s*)(\])(,)?',
+ bygroups(Whitespace, Operator, Text)),
+ ]
+ }
+
+
9 setup.py
View
@@ -1,3 +1,7 @@
+"""
+Augeas syntax highlighting for Pygments.
+"""
+
from setuptools import setup
__author__ = 'tim@sharpe.id.au'
@@ -9,6 +13,9 @@
author=__author__,
packages=['augeas_lexer'],
entry_points='''[pygments.lexers]
-augeaslexer = augeas_lexer:AugeasLexer
+augeas = augeas_lexer:AugeasLexer
+augtool-shell = augeas_lexer:AugtoolShellLexer
+augtool = augeas_lexer:AugtoolLexer
+puppet-augeas = augeas_lexer:PuppetAugeasLexer
'''
)
Something went wrong with that request. Please try again.