Skip to content

Commit

Permalink
Conform lexer rules to specification
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrmont committed Sep 4, 2019
1 parent faacf42 commit 690cad6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
38 changes: 19 additions & 19 deletions lib/rouge/lexers/csvs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ class CSVS < RegexLexer

state :root do
rule %r/\s+/m, Text
rule %r(//.*), Comment::Single
rule %r(#.*), Comment::Single
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
rule %r(/[+]), Comment::Multiline, :nested_comment

rule %r/"[^"]*"/, Str::Double
rule %r/'[^\r\n\f']'/, Str::Char

rule %r(:?:=), Keyword
rule %r/[()]/, Punctuation
rule %r(//[\S\t ]*), Comment::Single
rule %r(/\*[^*]*\*/)m, Comment::Multiline

rule %r([-=;,*+><!/|^.%&\[\]{}]), Operator
rule %r/(version)( )(\d+\.\d+)/ do
groups Keyword, Text::Whitespace, Num::Float
end

rule %r/[A-Z]\w*/, Name::Class

rule %r/[a-z_]\w*/, Name
rule %r/T?\d{2}:\d{2}:\d{2}(\.\d{5})?(Z|(?:[-+]\d{2}:\d{2}))?/, Literal::Date
rule %r/\d{4}-\d{2}-\d{2}/, Literal::Date
rule %r/\d{2}\/\d{2}\/\d{4}/, Literal::Date

rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
rule %r/\d+/, Num::Integer

rule %r/@@?|\'|\:/, Keyword
end
rule %r/@\w+/, Keyword::Pseudo

rule %r/[-.\w]+:/, Name::Variable
rule %r/^"[^"]+"/, Name::Variable
rule %r/\$([-.\w]+|("[^"]+"))\/?/, Name::Variable

rule %r/[A-Z]+/i, Keyword

rule %r/"[^"]*"/, Str::Double
rule %r/'[^\r\n\f']'/, Str::Char

state :nested_comment do
rule %r([^/+]+)m, Comment::Multiline
rule %r(/[+]), Comment::Multiline, :nested_comment
rule %r([+]/), Comment::Multiline, :pop!
rule %r/[,()*]/, Punctuation
end
end
end
Expand Down
54 changes: 32 additions & 22 deletions spec/visual/samples/csvs
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
version 1.0
@totalColumns 19
@separator ','
Customer_Name: notEmpty
Customer_Date_of_Birth: xDate
Customer_Place_of_Birth: notEmpty
Customer_Address: notEmpty
Customer_Account_number: notEmpty
Customer_Legal_Entity_Type: notEmpty
Customer_Industry: notEmpty
Adverse_Information_Search: xDate
Customer_Product_Usage: notEmpty
Customer_Net_Worth: notEmpty
Customer_Cash_Balance: notEmpty
Account_Open_Date: notEmpty
CDD_Completion_Date: notEmpty
System_Customer_Risk_Rating: notEmpty
PEP_Status: any("yes","no")
Associated_PEP: any("yes","no")
EDD_Triggered: any("yes","no")
Last_CDD_Renewal_Date: xDate
Relationship_Manager_Employee_ID: notEmpty
version 1.2
@totalColumns 3
name: notEmpty
age: range(0, 120)
gender: is("m") or is("f") or is("t") or is("n")

@separator TAB
@quoted
@totalColumns 21
@permitEmpty
@ignoreColumnNameCase

//This Comment is a Single Line Comment it terminates at this line break
a_column:

/*This Comment is a Multi Line Comment:
it can go on for as many lines as you like, until you type*/
a_column:

a_column: is("some string") and $b_column/starts("some string") //here two tests are combined on a single line, the second test here looks to the second column
b_column: //to check it's value starts with "some string"

a_column: is("some string") //the contents of a_column must be the string "some string"
a_column: is($a_column) //the contents of a_column must be the value held in a_column, treated as a string

a_column: range(*, 10)

a_column: xDateTime(2014-10-04T00:00:01Z,2015-12-03T23:59:59) //the value of a_column must be a valid xDateTime and between the two xDateTimes shown (inclusive)
a_column: xDateTime(2014-10-04T00:00:01+02:00,2015-12-03T23:59:59+02:00) //the value of a_column must be a valid xDateTime and between the two xDateTimes shown (inclusive)
a_column: xDateTime(2014-10-04,2015-12-03) //the value of a_column must be a valid xDate and between the two xDates shown (inclusive)
a_column: xTime(00:00:01+02:00,2015-12-03T23:59:59+02:00) //the value of a_column must be a valid xTime and between the two xTimes shown (inclusive)
a_column: ukDate(04/10/2014,03/12/2015) //the value of a_column must be a valid ukDate and between the two ukDates shown (inclusive)

0 comments on commit 690cad6

Please sign in to comment.