Skip to content

Commit

Permalink
Fix comment character in Prolog lexer (#830)
Browse files Browse the repository at this point in the history
It's more common to use the `%` character to denote a comment. This
commit updates the lexer accordingly.
  • Loading branch information
dariusf authored and pyrmont committed Jun 18, 2019
1 parent f1dc595 commit 88de367
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
10 changes: 8 additions & 2 deletions lib/rouge/lexers/prolog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ class Prolog < RegexLexer
filenames '*.pro', '*.P', '*.prolog', '*.pl'
mimetypes 'text/x-prolog'

start { push :bol }

state :bol do
rule %r/#.*/, Comment::Single
rule(//) { pop! }
end

state :basic do
rule %r/\s+/, Text
rule %r/^#.*/, Comment::Single
rule %r/%.*/, Comment::Single
rule %r(/\*), Comment::Multiline, :nested_comment
rule %r/\/\*/, Comment::Multiline, :nested_comment

rule %r/[\[\](){}|.,;!]/, Punctuation
rule %r/:-|-->/, Punctuation
Expand Down
26 changes: 14 additions & 12 deletions spec/visual/samples/prolog
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
# Atoms
#!/bin/prolog

% Atoms

x
blue
'Burrito'
'some atom'
camelCaseAtom

# Numbers
% Numbers

1
123123123123
12312.1231
0.1

# Variables
% Variables

Hello
How_are_you_doing
_amazing
Wow123

# Compound terms
% Compound terms

truck_year('Mazda', 1986)
'Person_Friends'(zelda,[tom,jim])

# List
% List

[]
[1,2,3]
[red,green,blue]

# Strings
% Strings

"to be, or not to be"
"東京都"

# This example was taken from
# http://en.wikipedia.org/wiki/Prolog#Turing_completeness
% This example was taken from
% http://en.wikipedia.org/wiki/Prolog#Turing_completeness
turing(Tape0, Tape) :-
perform(q0, [], Ls, Tape0, Rs),
reverse(Ls, Ls1),
append(Ls1, Rs, Tape).

/*
*
*
* This is a multiline comment.
*/
*/

% This is a single-line comment

Expand All @@ -69,7 +71,7 @@ action(right, Ls0, [Sym|Ls0], [Sym|Rs], Rs).
left([], [], Rs0, [b|Rs0]).
left([L|Ls], Ls, Rs, [L|Rs]).

## Example from pygments
%% Example from pygments

partition([], _, [], []).
partition([X|Xs], Pivot, Smalls, Bigs) :-
Expand All @@ -81,6 +83,6 @@ partition([X|Xs], Pivot, Smalls, Bigs) :-
).

quicksort([]) --> [].
quicksort([X|Xs]) -->
quicksort([X|Xs]) -->
{ partition(Xs, X, Smaller, Bigger) },
quicksort(Smaller), [X], quicksort(Bigger).

0 comments on commit 88de367

Please sign in to comment.