Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lexer for CMHG files #1282

Merged
merged 6 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/rouge/demos/cmhg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; Header comments

#include "definitions.h"

command-keyword-table: command_handler
foo(min-args:0, max-args:0,; comment
international:,
invalid-syntax: "syntaxtoken" help-text: "helptoken")
34 changes: 34 additions & 0 deletions lib/rouge/lexers/cmhg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
module Lexers
class CMHG < RegexLexer
title "CMHG"
desc "RISC OS C module header generator source file"
tag 'cmhg'
filenames '*.cmhg'

def self.preproc_keyword
@preproc_keyword ||= %w(
define elif else endif error if ifdef ifndef include line pragma undef warning
)
end

state :root do
rule %r/;[^\n]*/, Comment
rule %r/^([ \t]*)(#[ \t]*(?:(?:#{CMHG.preproc_keyword.join('|')})(?:[ \t].*)?)?)(?=\n)/ do
groups Text, Comment::Preproc
end
rule %r/[-a-z]+:/, Keyword::Declaration
pyrmont marked this conversation as resolved.
Show resolved Hide resolved
rule %r/[a-z_]\w+/i, Name::Entity
rule %r/"[^"]*"/, Literal::String
rule %r/(?:&|0x)\h+/, Literal::Number::Hex
rule %r/\d+/, Literal::Number
rule %r/[,\/()]/, Punctuation
pyrmont marked this conversation as resolved.
Show resolved Hide resolved
rule %r/[ \t]+/, Text
rule %r/\n+/, Text
end
end
end
end
14 changes: 14 additions & 0 deletions spec/lexers/cmhg_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::CMHG do
let(:subject) { Rouge::Lexers::CMHG.new }

describe 'guessing' do
include Support::Guessing

it 'guesses by filename' do
assert_guess :filename => 'foo.cmhg'
end
end
end
60 changes: 60 additions & 0 deletions spec/visual/samples/cmhg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
;
; CDDL HEADER START
;
; The contents of this file are subject to the terms of the
; Common Development and Distribution License (the "Licence").
; You may not use this file except in compliance with the Licence.
;
; You can obtain a copy of the licence at
; cddl/RiscOS/Sources/HWSupport/SD/SDIODriver/LICENCE.
; See the Licence for the specific language governing permissions
; and limitations under the Licence.
;
; When distributing Covered Code, include this CDDL HEADER in each
; file and include the Licence file. If applicable, add the
; following below this CDDL HEADER, with the fields enclosed by
; brackets "[]" replaced with your own identifying information:
; Portions Copyright [yyyy] [name of copyright owner]
;
; CDDL HEADER END
;
; Copyright 2012 Ben Avison. All rights reserved.
; Portions Copyright 2013 Jeffrey Lee.
; Use is subject to license terms.
;

#include "Global/Services.h"
#ifndef Module_Date_CMHG
#include "VersionNum"
#endif

initialisation-code: module_initialise

finalisation-code: module_finalise

; Service_Hardware
service-call-handler: module_service Service_Hardware,
Service_ModulePostInit

title-string: SDIODriver

help-string: SDIODriver Module_MajorVersion_CMHG Module_MinorVersion_CMHG

command-keyword-table: module_command
SDIODevices(min-args:0, max-args:1, international:, invalid-syntax:"SSDIDEV", help-text:"HSDIDEV"),
SDIOSlots(min-args:0, max-args:255, international:, invalid-syntax:"SSDISLT", help-text:"HSDISLT")

swi-chunk-base-number: 0x59000
pyrmont marked this conversation as resolved.
Show resolved Hide resolved

swi-handler-code: module_swi

swi-decoding-table: SDIO, Initialise, Control, Enumerate, ControllerFeatures, ReadRegister, Op, ClaimDeviceVector, ReleaseDeviceVector

international-help-file:"Resources:$.Resources.SDIODriver.Messages"

date-string: Module_Date_CMHG

generic-veneers: module_irq_veneer/module_irq_handler,
module_card_insertion_veneer/module_card_insertion_handler

vector-handlers: module_tickerv_veneer/module_tickerv_handler