diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-10-16 12:36:47 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-11-08 13:35:36 +0100 |
| commit | 039042f2e323c1f982f1de61b702c88fb33d6ccb (patch) | |
| tree | 67dea69de9462e0c27ea2a743b4c5d1798eaa057 /lexers/vcard.lua | |
| parent | b1ec60061623601ca6185a16d77c6c6c62135e95 (diff) | |
| download | vis-039042f2e323c1f982f1de61b702c88fb33d6ccb.tar.gz vis-039042f2e323c1f982f1de61b702c88fb33d6ccb.tar.xz | |
Import LPeg based lexers from Scintillua 3.6.1-1
These are Copyright (c) 2007-2015 Mitchell and released under the
MIT license.
Diffstat (limited to 'lexers/vcard.lua')
| -rw-r--r-- | lexers/vcard.lua | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/lexers/vcard.lua b/lexers/vcard.lua new file mode 100644 index 0000000..2057451 --- /dev/null +++ b/lexers/vcard.lua @@ -0,0 +1,97 @@ +-- Copyright (c) 2015 Piotr Orzechowski [drzewo.org]. See LICENSE. +-- vCard 2.1, 3.0 and 4.0 LPeg lexer. + +local l = require('lexer') +local token, word_match = l.token, l.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local M = {_NAME = 'vcard'} + +-- Whitespace. +local ws = token(l.WHITESPACE, l.space^1) + +-- Required properties. +local required_property = token(l.KEYWORD, word_match({ + 'BEGIN', 'END', 'FN', 'N' --[[ Not required in v4.0. ]], 'VERSION' +}, nil, true)) * #P(':') + +-- Supported properties. +local supported_property = token(l.TYPE, word_match({ + 'ADR', 'AGENT' --[[ Not supported in v4.0. ]], + 'ANNIVERSARY' --[[ Supported in v4.0 only. ]], 'BDAY', + 'CALADRURI' --[[ Supported in v4.0 only. ]], + 'CALURI' --[[ Supported in v4.0 only. ]], 'CATEGORIES', + 'CLASS' --[[ Supported in v3.0 only. ]], + 'CLIENTPIDMAP' --[[ Supported in v4.0 only. ]], 'EMAIL', 'END', + 'FBURL' --[[ Supported in v4.0 only. ]], + 'GENDER' --[[ Supported in v4.0 only. ]], 'GEO', + 'IMPP' --[[ Not supported in v2.1. ]], 'KEY', + 'KIND' --[[ Supported in v4.0 only. ]], + 'LABEL' --[[ Not supported in v4.0. ]], + 'LANG' --[[ Supported in v4.0 only. ]], 'LOGO', + 'MAILER' --[[ Not supported in v4.0. ]], + 'MEMBER' --[[ Supported in v4.0 only. ]], + 'NAME' --[[ Supported in v3.0 only. ]], + 'NICKNAME' --[[ Not supported in v2.1. ]], 'NOTE', 'ORG', 'PHOTO', + 'PRODID' --[[ Not supported in v2.1. ]], + 'PROFILE' --[[ Not supported in v4.0. ]], + 'RELATED' --[[ Supported in v4.0 only. ]], 'REV', 'ROLE', + 'SORT-STRING' --[[ Not supported in v4.0. ]], 'SOUND', 'SOURCE', 'TEL', + 'TITLE', 'TZ', 'UID', 'URL', 'XML' --[[ Supported in v4.0 only. ]] +}, nil, true)) * #S(':;') + +local identifier = l.alpha^1 * l.digit^0 * (P('-') * l.alnum^1)^0 + +-- Extension. +local extension = token(l.TYPE, + l.starts_line(S('xX') * P('-') * identifier * #S(':;'))) + +-- Parameter. +local parameter = token(l.IDENTIFIER, l.starts_line(identifier * #S(':='))) + + token(l.STRING, identifier) * #S(':=') + +-- Operators. +local operator = token(l.OPERATOR, S('.:;=')) + +-- Group and property. +local group_sequence = token(l.CONSTANT, l.starts_line(identifier)) * + token(l.OPERATOR, P('.')) * + (required_property + supported_property + + l.token(l.TYPE, S('xX') * P('-') * identifier) * + #S(':;')) +-- Begin vCard, end vCard. +local begin_sequence = token(l.KEYWORD, P('BEGIN')) * + token(l.OPERATOR, P(':')) * token(l.COMMENT, P('VCARD')) +local end_sequence = token(l.KEYWORD, P('END')) * token(l.OPERATOR, P(':')) * + token(l.COMMENT, P('VCARD')) + +-- vCard version (in v3.0 and v4.0 must appear immediately after BEGIN:VCARD). +local version_sequence = token(l.KEYWORD, P('VERSION')) * + token(l.OPERATOR, P(':')) * + token(l.CONSTANT, l.digit^1 * (P('.') * l.digit^1)^-1) + +-- Data. +local data = token(l.IDENTIFIER, l.any) + +-- Rules. +M._rules = { + {'whitespace', ws}, + {'begin_sequence', begin_sequence}, + {'end_sequence', end_sequence}, + {'version_sequence', version_sequence}, + {'group_sequence', group_sequence}, + {'required_property', required_property}, + {'supported_property', supported_property}, + {'extension', extension}, + {'parameter', parameter}, + {'operator', operator}, + {'data', data}, +} + +-- Folding. +M._foldsymbols = { + _patterns = {'BEGIN', 'END'}, + [l.KEYWORD] = {['BEGIN'] = 1, ['END'] = -1} +} + +return M |
