private IToken TryGetLangSpec() { // Skip the first Character which must have been an @ SkipCharacter(); // Consume characters which can be in the keyword or Language Specifier char next = Peek(); while (Char.IsLetterOrDigit(next) || next == '-') { ConsumeCharacter(); next = Peek(); } // Check the output to see if it's valid String output = Value; if (RdfSpecsHelper.IsValidLangSpecifier(output)) { LastTokenType = Token.LANGSPEC; return(new LanguageSpecifierToken(output, CurrentLine, StartPosition, EndPosition)); } else { throw Error("Unexpected Content '" + output + "' encountered, expected a valid Language Specifier"); } }
private IToken TryGetLangSpec() { // Skip the first Character which must have been an @ SkipCharacter(); // Consume characters which can be in the keyword or Language Specifier char next = Peek(); while (Char.IsLetterOrDigit(next) || next == '-') { if (Syntax == NTriplesSyntax.Original && next > 127) { throw Error("Non-ASCII characters are not permitted in Original NTriples, please set the Syntax to Rdf11 to support characters beyond the ASCII range"); } ConsumeCharacter(); next = Peek(); } // Check the output to see if it's valid String output = Value; if (RdfSpecsHelper.IsValidLangSpecifier(output)) { LastTokenType = Token.LANGSPEC; return(new LanguageSpecifierToken(output, CurrentLine, StartPosition, EndPosition)); } throw Error("Unexpected Content '" + output + "' encountered, expected a valid Language Specifier"); }
public override void ParseLiteralLanguage(RdfACoreParserContext context, IRdfAEvent evt) { if (evt.HasAttribute("xml:lang")) { if (RdfSpecsHelper.IsValidLangSpecifier(evt["xml:lang"])) { context.Language = evt["xml:lang"]; } } }
private IToken TryGetKeywordOrLangSpec() { //Consume the first Character which must have been an @ this.ConsumeCharacter(); //Consume characters which can be in the keyword or Language Specifier char next = this.Peek(); while (Char.IsLetterOrDigit(next) || next == '-') { this.ConsumeCharacter(); next = this.Peek(); } //Check the output to see if it's valid String output = this.Value; if (output.Equals("@prefix")) { this._lasttokentype = Token.PREFIXDIRECTIVE; return(new PrefixDirectiveToken(this.CurrentLine, this.StartPosition)); } else if (output.Equals("@base")) { if (this._syntax == TriGSyntax.Original) { throw new RdfParseException("The @base directive is not permitted in this version of TriG, later versions of TriG support this feature and may be enabled by changing your syntax setting when you create a TriG Parser"); } this._lasttokentype = Token.BASEDIRECTIVE; return(new BaseDirectiveToken(this.CurrentLine, this.StartPosition)); } else if (RdfSpecsHelper.IsValidLangSpecifier(output)) { this._lasttokentype = Token.LANGSPEC; return(new LanguageSpecifierToken(output.Substring(1), this.CurrentLine, this.StartPosition, this.EndPosition)); } else { throw Error("Unexpected Content '" + output + "' encountered, expected an @prefix/@base keyword or a Language Specifier"); } }
private IToken TryGetKeywordOrLangSpec() { //Consume the first Character which must have been an @ this.ConsumeCharacter(); //Consume characters which can be in the keyword or Language Specifier char next = this.Peek(); while (Char.IsLetter(next) || next == '-') { this.ConsumeCharacter(); next = this.Peek(); } //Check the output to see if it's valid String output = this.Value; if (output.Equals("@prefix")) { this._lasttokentype = Token.PREFIXDIRECTIVE; return(new PrefixDirectiveToken(this.CurrentLine, this.StartPosition)); } else if (output.Equals("@base")) { this._lasttokentype = Token.BASEDIRECTIVE; return(new BaseDirectiveToken(this.CurrentLine, this.StartPosition)); } else if (RdfSpecsHelper.IsValidLangSpecifier(output)) { this._lasttokentype = Token.LANGSPEC; return(new LanguageSpecifierToken(output.Substring(1), this.CurrentLine, this.StartPosition, this.EndPosition)); } else { throw Error("Unexpected Content '" + output + "' encountered, expected an @prefix/@base keyword or a Language Specifier"); } }
private IToken TryGetKeywordOrLangSpec() { if (LastTokenType == Token.LITERAL || LastTokenType == Token.LONGLITERAL) { // Must be a Language Specifier // Discard the @ SkipCharacter(); // Get the Specifier char next = Peek(); while (Char.IsLetterOrDigit(next) || next == '-') { ConsumeCharacter(); next = Peek(); } // Return the Language Specifier if (RdfSpecsHelper.IsValidLangSpecifier(Value)) { LastTokenType = Token.LANGSPEC; return(new LanguageSpecifierToken(Value, CurrentLine, StartPosition, EndPosition)); } else { throw Error("Unexpected Content '" + Value + "' encountered, expected a valid Language Specifier"); } } else if (LastTokenType == Token.PLAINLITERAL) { // Can't specify Language on a Plain Literal throw Error("Unexpected Character (Code " + (int)'@' + " @\nThe @ sign cannot be used to specify a Language on a Plain Literal"); } else { // Must be some Keyword // Discard the @ SkipCharacter(); // Consume until we hit White Space char next = Peek(); while (!Char.IsWhiteSpace(next) && next != '.') { ConsumeCharacter(); next = Peek(); } // Now check we get something that's an actual Keyword/Directive String value = Value; if (value.Equals("keywords", StringComparison.OrdinalIgnoreCase)) { // Keywords Directive // Remember to enable Keywords Mode _keywordsmode = true; LastTokenType = Token.KEYWORDDIRECTIVE; return(new KeywordDirectiveToken(CurrentLine, StartPosition)); } else if (value.Equals("base", StringComparison.OrdinalIgnoreCase)) { // Base Directive LastTokenType = Token.BASEDIRECTIVE; return(new BaseDirectiveToken(CurrentLine, StartPosition)); } else if (value.Equals("prefix", StringComparison.OrdinalIgnoreCase)) { // Prefix Directive LastTokenType = Token.PREFIXDIRECTIVE; return(new PrefixDirectiveToken(CurrentLine, StartPosition)); } else if (value.Equals("forall", StringComparison.OrdinalIgnoreCase)) { // ForAll Quantifier LastTokenType = Token.FORALL; return(new ForAllQuantifierToken(CurrentLine, StartPosition)); } else if (value.Equals("forsome", StringComparison.OrdinalIgnoreCase)) { // ForSome Quantifier LastTokenType = Token.FORSOME; return(new ForSomeQuantifierToken(CurrentLine, StartPosition)); } else if (value.Equals("a")) { // 'a' Keyword LastTokenType = Token.KEYWORDA; return(new KeywordAToken(CurrentLine, StartPosition)); } else if (value.Equals("is")) { // 'is' Keyword LastTokenType = Token.KEYWORDIS; return(new KeywordIsToken(CurrentLine, StartPosition)); } else if (value.Equals("of")) { // 'of' Keyword LastTokenType = Token.KEYWORDOF; return(new KeywordOfToken(CurrentLine, StartPosition)); } else if (value.Equals("false") || value.Equals("true")) { // Plain Literal Boolean LastTokenType = Token.PLAINLITERAL; return(new PlainLiteralToken(value, CurrentLine, StartPosition, EndPosition)); } else if (_keywords.Contains(value)) { // A Custom Keyword which has been defined LastTokenType = Token.KEYWORDCUSTOM; return(new CustomKeywordToken(value, CurrentLine, StartPosition, EndPosition)); } else { // Some other unknown and undefined Keyword throw Error("The Keyword '" + value + "' has not been defined and is not a valid Notation 3 Keyword"); } } }